/**
 * IPv4 Subnet Calculator - Custom Styles
 * Dark mode only
 */

/* Tailwind Directives */
@tailwind base;
@tailwind components;
@tailwind utilities;

/* Dark Theme Variables */
:root {
  --bg: #0b1220;
  --fg: #e2e8f0;
  --surface: #0f172a;
  --muted: #94a3b8;
  --soft: #111827;
  --border: #1f2937;
  color-scheme: dark;
}

/* Base Styles */
html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
}

/* Component Styles */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.card:hover {
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

.soft {
  background: var(--soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: all 0.2s ease;
}

.pill {
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: .125rem .5rem;
  font-size: .75rem;
  transition: all 0.2s ease;
}

.muted {
  color: var(--muted);
  transition: color 0.2s ease;
}

/* Fade-in animation for panels */
section[role="tabpanel"]:not(.hidden) {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
}

.btn {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .5rem .75rem;
  font-size: .875rem;
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.btn:active {
  transform: translateY(0);
  box-shadow: none;
}

.tab-active {
  background: #111827;
  color: #fff;
  transition: all 0.2s ease;
}

nav[role="tablist"] button {
  transition: all 0.2s ease;
}

nav[role="tablist"] button:hover:not(.tab-active) {
  background: rgba(255, 255, 255, 0.05);
}

/* Form Elements */
textarea, input, select {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .5rem;
  transition: all 0.2s ease;
}

input::placeholder, textarea::placeholder {
  color: var(--muted);
  opacity: 1;
  transition: opacity 0.2s ease;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

input:hover:not(:focus), select:hover:not(:focus), textarea:hover:not(:focus) {
  border-color: rgba(59, 130, 246, 0.5);
}

/* Validation States */
input.invalid, textarea.invalid, select.invalid {
  border-color: #ef4444;
  outline-color: #ef4444;
  padding-right: 2.5rem;
}

input.valid, textarea.valid, select.valid {
  border-color: #10b981;
  padding-right: 2.5rem;
}

/* Validation Icons */
.input-wrapper {
  position: relative;
  display: inline-block;
  width: 100%;
}

.validation-icon {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.25rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.validation-icon.show {
  opacity: 1;
}

.validation-icon.valid {
  color: #10b981;
}

.validation-icon.invalid {
  color: #ef4444;
}

.error-message {
  color: #ef4444;
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

/* Table Styles */
table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  border-bottom: 1px solid var(--border);
  padding: .5rem;
  text-align: left;
}

th {
  font-size: .75rem;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

th:hover {
  color: var(--fg);
}

td {
  font-size: .875rem;
}

/* VLSM Container Visualization */
.vlsm-bar {
  position: relative;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--soft);
  overflow: hidden;
}

.vlsm-seg {
  position: absolute;
  top: 0;
  bottom: 0;
  border-right: 1px solid rgba(0, 0, 0, .06);
  display: flex;
  align-items: center;
  padding-left: 6px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.vlsm-legend {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
  margin-top: .5rem;
}

.vlsm-chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .2rem .5rem;
  border: 1px solid var(--border);
  border-radius: 9999px;
  font-size: .75rem;
  background: var(--surface);
}

.vlsm-dot {
  width: .7rem;
  height: .7rem;
  border-radius: 9999px;
  display: inline-block;
}

/* Color Segments */
.seg-0 { background: rgba(59, 130, 246, .35); } /* blue */
.seg-1 { background: rgba(34, 197, 94, .35); } /* green */
.seg-2 { background: rgba(234, 179, 8, .35); } /* amber */
.seg-3 { background: rgba(236, 72, 153, .35); } /* pink */
.seg-4 { background: rgba(168, 85, 247, .35); } /* purple */
.seg-5 { background: rgba(248, 113, 113, .35); } /* red */
.seg-6 { background: rgba(20, 184, 166, .35); } /* teal */
.seg-7 { background: rgba(99, 102, 241, .35); } /* indigo */

/* Enhanced Subnet Map Visualization */
.subnet-map {
  position: relative;
  width: 100%;
  margin: 1rem 0;
}

.subnet-map-bar {
  position: relative;
  height: 48px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--soft);
  overflow: visible;
  transition: all 0.2s ease;
}

.subnet-map-bar:hover {
  border-color: #3b82f6;
}

.subnet-block {
  position: absolute;
  top: 0;
  bottom: 0;
  border-right: 1px solid rgba(0, 0, 0, .15);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.subnet-block:hover {
  filter: brightness(1.2);
  transform: scaleY(1.1);
  z-index: 10;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

.subnet-block:last-child {
  border-right: none;
}

/* Subnet tooltip */
.subnet-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 1000;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.subnet-block:hover .subnet-tooltip {
  opacity: 1;
}

.subnet-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--border);
}

.subnet-tooltip-line {
  margin: 0.25rem 0;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.subnet-tooltip-label {
  color: var(--muted);
}

.subnet-tooltip-value {
  color: var(--fg);
  font-family: ui-monospace, monospace;
}

/* IP Space Overview */
.ip-space-overview {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.ip-space-label {
  font-weight: 600;
}

.ip-space-range {
  font-family: ui-monospace, monospace;
}

/* Size-based coloring */
.subnet-size-small { background: rgba(34, 197, 94, .7); } /* /28-/32 - green */
.subnet-size-medium { background: rgba(59, 130, 246, .7); } /* /24-/27 - blue */
.subnet-size-large { background: rgba(234, 179, 8, .7); } /* /16-/23 - amber */
.subnet-size-xlarge { background: rgba(236, 72, 153, .7); } /* /8-/15 - pink */
.subnet-size-huge { background: rgba(168, 85, 247, .7); } /* /0-/7 - purple */

/* Utility Classes */
.hidden {
  display: none;
}

.spill {
  background: rgba(239, 68, 68, .25);
}

/* Footer */
footer {
  margin-top: 1rem;
  color: var(--muted);
  font-size: .85rem;
}

/* Copy Success Notification */
.copy-notification {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: #10b981;
  color: white;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  font-size: 0.875rem;
  font-weight: 500;
  animation: slideIn 0.3s ease-out, slideOut 0.3s ease-in 2.7s;
  z-index: 1000;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

/* Print Styles */
@media print {
  /* Hide interactive elements */
  .btn, button, nav, #historyBtn, #historyDropdown,
  .copy-notification, .validation-icon,
  .loading-spinner, .loading-overlay {
    display: none !important;
  }

  /* Reset colors for print */
  * {
    color: black !important;
    background: white !important;
  }

  body {
    padding: 0;
    margin: 0;
    font-size: 11pt;
  }

  /* Page breaks */
  h1, h2, h3 {
    page-break-after: avoid;
    page-break-inside: avoid;
  }

  table, .card {
    page-break-inside: avoid;
  }

  /* Borders and spacing */
  .card, .soft {
    border: 1px solid #333;
    padding: 12pt;
    margin: 8pt 0;
  }

  /* Tables */
  table {
    border-collapse: collapse;
    width: 100%;
    margin: 8pt 0;
  }

  th, td {
    border: 1px solid #333;
    padding: 6pt;
    text-align: left;
  }

  th {
    font-weight: bold;
    background: #f0f0f0 !important;
  }

  /* Header formatting */
  header {
    border-bottom: 2px solid #000;
    margin-bottom: 16pt;
    padding-bottom: 8pt;
  }

  h1 {
    font-size: 18pt;
    margin: 0;
  }

  /* Footer */
  footer {
    border-top: 1px solid #000;
    margin-top: 16pt;
    padding-top: 8pt;
    font-size: 9pt;
  }

  /* Monospace styling */
  .mono {
    font-family: 'Courier New', Courier, monospace;
  }

  /* Hide empty results */
  .hidden {
    display: none !important;
  }

  /* Print URLs after links */
  a[href]:after {
    content: " (" attr(href) ")";
    font-size: 9pt;
    color: #666 !important;
  }
}

/* Tooltips */
[data-tooltip] {
  position: relative;
  cursor: help;
  border-bottom: 1px dotted var(--muted);
}

button[data-tooltip] {
  border-bottom: none;
  cursor: pointer;
}

[data-tooltip]:hover::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 1000;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

[data-tooltip]:hover::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 0.25rem;
  border: 0.25rem solid transparent;
  border-top-color: var(--border);
  z-index: 1000;
  pointer-events: none;
}

/* Accessibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Focus visible for keyboard navigation */
*:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* Loading States */
.loading-spinner {
  display: inline-block;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--border);
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 2rem;
  color: var(--muted);
  font-size: 0.875rem;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Skeleton Loading */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--soft) 0%,
    var(--surface) 50%,
    var(--soft) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Mobile Optimizations */
@media (max-width: 768px) {
  /* Increase touch targets to 44x44px minimum */
  .btn {
    min-height: 44px;
    padding: .75rem 1rem;
    font-size: .9375rem;
  }

  input, select, textarea {
    min-height: 44px;
    padding: .75rem;
    font-size: 1rem;
  }

  /* Tab buttons */
  nav[role="tablist"] button {
    min-height: 44px;
    padding: .75rem 1rem;
  }

  /* Pill badges */
  .pill {
    padding: .375rem .75rem;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
  }

  /* Table improvements */
  table {
    font-size: .8125rem;
  }

  th, td {
    padding: .75rem .5rem;
    min-height: 44px;
  }

  /* History button */
  #historyBtn {
    min-width: 44px;
    min-height: 44px;
  }

  /* Better spacing for mobile */
  .space-y-4 > * + * {
    margin-top: 1.25rem;
  }

  /* Prevent zoom on input focus iOS */
  input[type="text"],
  input[type="number"],
  textarea {
    font-size: 16px;
  }

  /* Card-based table layout for mobile */
  @media (max-width: 640px) {
    table, thead, tbody, tr {
      display: block;
    }

    thead {
      position: absolute;
      top: -9999px;
      left: -9999px;
    }

    tr {
      margin-bottom: 1rem;
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: .75rem;
      background: var(--soft);
    }

    td {
      display: block;
      text-align: right;
      padding: .5rem 0;
      border-bottom: 1px solid var(--border);
      min-height: auto;
    }

    td:last-child {
      border-bottom: none;
    }

    td::before {
      content: attr(data-label);
      float: left;
      font-weight: 600;
      color: var(--muted);
    }
  }
}
