/* ============================================
   Sublink — Network Operations Terminal
   A cyberpunk command-center aesthetic
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=Outfit:wght@300;400;500;600;700;800&display=swap');

/* --- Tokens --- */
:root {
  --bg-void: #06080d;
  --bg-surface: #0c1018;
  --bg-elevated: #111822;
  --bg-panel: #151d2b;
  --bg-input: #0d1520;
  --neon: #00e5a0;
  --neon-dim: rgba(0, 229, 160, 0.12);
  --neon-glow: rgba(0, 229, 160, 0.3);
  --neon-bright: #33ffbe;
  --accent-2: #00b4d8;
  --accent-2-dim: rgba(0, 180, 216, 0.12);
  --warn: #ff6b6b;
  --text-h: #e8ecf1;
  --text-b: #8b95a5;
  --text-m: #4d5a6e;
  --border: rgba(255, 255, 255, 0.05);
  --border-active: rgba(0, 229, 160, 0.25);
  --grid-line: rgba(0, 229, 160, 0.03);
  --shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
  --shadow-neon: 0 0 20px rgba(0, 229, 160, 0.08);
  --r: 10px;
  --r-lg: 14px;
  --font-display: 'Outfit', sans-serif;
  --font-mono: 'Space Mono', monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="light"] {
  --bg-void: #f0f2f5;
  --bg-surface: #ffffff;
  --bg-elevated: #f7f8fa;
  --bg-panel: #eef0f4;
  --bg-input: #f5f6f8;
  --neon: #00996b;
  --neon-dim: rgba(0, 153, 107, 0.08);
  --neon-glow: rgba(0, 153, 107, 0.15);
  --neon-bright: #00b37e;
  --accent-2: #0077b6;
  --accent-2-dim: rgba(0, 119, 182, 0.08);
  --text-h: #111827;
  --text-b: #4b5563;
  --text-m: #9ca3af;
  --border: rgba(0, 0, 0, 0.06);
  --border-active: rgba(0, 153, 107, 0.3);
  --grid-line: rgba(0, 153, 107, 0.04);
  --shadow: 0 4px 30px rgba(0, 0, 0, 0.06);
  --shadow-neon: 0 0 20px rgba(0, 153, 107, 0.06);
}

/* --- Reset --- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* --- Grid Background Texture --- */
body {
  font-family: var(--font-display);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-b);
  background: var(--bg-void);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background 0.4s var(--ease), color 0.4s var(--ease);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 48px 48px;
  background-position: center center;
}

/* Scan-line overlay */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.015) 2px,
    rgba(0, 0, 0, 0.015) 4px
  );
}

/* --- Navbar --- */
.navbar {
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.navbar-brand {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-h);
  text-decoration: none;
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 3px;
}

.navbar-brand span {
  color: var(--neon);
  text-shadow: 0 0 12px var(--neon-glow);
}

.navbar-brand .blink {
  animation: blink 1.2s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.navbar-links {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-link {
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-m);
  text-decoration: none;
  border-radius: 7px;
  transition: all 0.2s var(--ease);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.nav-link:hover, .nav-link.active {
  color: var(--neon);
  background: var(--neon-dim);
}

.theme-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  color: var(--text-m);
  transition: all 0.2s var(--ease);
}

.theme-btn:hover {
  border-color: var(--neon);
  color: var(--neon);
  box-shadow: var(--shadow-neon);
}

/* --- Page Header --- */
.page-header {
  text-align: center;
  padding: 20px 24px 4px;
}

.page-header h1 {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-h);
  letter-spacing: -1px;
}

.page-header h1 .hl {
  color: var(--neon);
  text-shadow: 0 0 24px var(--neon-glow);
}

.page-header .subtitle {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-m);
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

/* --- Card --- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 26px;
  transition: all 0.3s var(--ease);
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--neon-dim), transparent);
}

.card:hover {
  border-color: var(--border-active);
  box-shadow: var(--shadow-neon);
}

.card + .card {
  margin-top: 14px;
}

/* --- Card Label (top-left tag) --- */
.card-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--neon);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-tag::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--neon);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--neon-glow);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* --- Forms --- */
label {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-m);
  margin-bottom: 6px;
}

input[type="text"],
textarea,
select,
input[type="file"] {
  width: 100%;
  padding: 11px 14px;
  font-size: 14px;
  font-family: var(--font-display);
  background: var(--bg-input);
  color: var(--text-h);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: all 0.2s var(--ease);
}

input[type="text"]:focus,
textarea:focus,
select:focus {
  border-color: var(--neon);
  box-shadow: 0 0 0 3px var(--neon-dim), var(--shadow-neon);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-m);
  font-size: 13px;
}

textarea {
  resize: vertical;
  min-height: 88px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%234d5a6e' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

input[type="file"] {
  cursor: pointer;
  font-size: 13px;
}

input[type="file"]::file-selector-button {
  background: var(--neon);
  color: #06080d;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-mono);
  cursor: pointer;
  margin-right: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: all 0.2s var(--ease);
}

input[type="file"]::file-selector-button:hover {
  box-shadow: 0 0 12px var(--neon-glow);
}

.form-group {
  margin-bottom: 18px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 28px;
  font-size: 13px;
  font-weight: 700;
  font-family: var(--font-mono);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  transition: all 0.25s var(--ease);
  position: relative;
  overflow: hidden;
}

.btn-primary {
  background: var(--neon);
  color: #06080d;
  box-shadow: 0 2px 16px var(--neon-glow);
}

.btn-primary:hover {
  box-shadow: 0 4px 28px var(--neon-glow), 0 0 60px rgba(0, 229, 160, 0.15);
  transform: translateY(-2px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-outline {
  background: transparent;
  color: var(--text-b);
  border: 1px solid var(--border);
}

.btn-outline:hover {
  color: var(--neon);
  border-color: var(--neon);
  background: var(--neon-dim);
}

.btn-sm {
  padding: 7px 16px;
  font-size: 11px;
}

.btn-block {
  width: 100%;
  margin-top: 6px;
}

/* Shimmer effect on primary button */
.btn-primary::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 60%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
  transition: left 0.5s var(--ease);
}

.btn-primary:hover::after {
  left: 120%;
}

/* --- Layout --- */
.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 28px 48px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1.3fr 0.7fr;
  gap: 18px;
  align-items: start;
}

.method-bar {
  display: flex;
  align-items: center;
  gap: 14px;
}

.method-bar label {
  margin: 0;
  white-space: nowrap;
}

.method-bar select {
  max-width: 220px;
}

/* --- Info Panels --- */
.info-section {
  margin-bottom: 14px;
}

.info-section:last-child {
  margin-bottom: 0;
}

.info-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent-2);
  margin-bottom: 5px;
}

.info-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent-2);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--text-b);
  word-break: break-all;
}

/* --- File Upload --- */
.file-upload-container {
  display: none;
}

/* --- Show Page --- */
.show-container {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 28px 48px;
}

.show-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.show-stats {
  display: flex;
  gap: 32px;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.stat-item {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  color: var(--neon);
  line-height: 1;
  text-shadow: 0 0 20px var(--neon-glow);
}

.stat-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-m);
  margin-top: 4px;
}

.page-list {
  list-style: none;
}

.page-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  transition: all 0.2s var(--ease);
  border-radius: 6px;
}

.page-item:last-child {
  border-bottom: none;
}

.page-item:hover {
  background: var(--neon-dim);
  border-color: transparent;
}

.page-link {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  color: var(--neon);
  text-decoration: none;
  letter-spacing: 0.3px;
}

.page-link:hover {
  text-shadow: 0 0 8px var(--neon-glow);
}

.copy-btn {
  padding: 6px 14px;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-mono);
  background: var(--bg-panel);
  color: var(--text-m);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: all 0.2s var(--ease);
}

.copy-btn:hover {
  border-color: var(--neon);
  color: var(--neon);
  box-shadow: 0 0 12px var(--neon-dim);
}

.copy-btn.copied {
  border-color: var(--neon);
  color: #06080d;
  background: var(--neon);
}

/* --- About Page --- */
.about-container {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 28px 48px;
}

.about-container h2 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-h);
  margin: 30px 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.about-container h2::before {
  content: '>';
  font-family: var(--font-mono);
  color: var(--neon);
  font-size: 14px;
}

.about-container p {
  margin-bottom: 12px;
  line-height: 1.8;
}

.about-container ol,
.about-container ul {
  margin: 8px 0 16px 20px;
}

.about-container li {
  margin-bottom: 8px;
  line-height: 1.7;
}

.about-container li strong {
  color: var(--text-h);
}

.about-container code {
  background: var(--bg-elevated);
  padding: 2px 7px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--neon);
  border: 1px solid var(--border);
}

.protocol-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 20px;
}

.protocol-table th,
.protocol-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.protocol-table th {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-m);
}

.protocol-table td {
  color: var(--text-b);
}

.protocol-table tr:hover td {
  background: var(--neon-dim);
}

/* --- Error Pages --- */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  padding: 40px;
}

.error-code {
  font-family: var(--font-mono);
  font-size: 6rem;
  font-weight: 700;
  color: var(--neon);
  line-height: 1;
  text-shadow: 0 0 40px var(--neon-glow);
  letter-spacing: -4px;
}

.error-message {
  font-family: var(--font-mono);
  color: var(--text-m);
  font-size: 13px;
  margin: 14px 0 28px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: #06080d;
  z-index: 10000;
  opacity: 0;
  transform: translateY(10px) scale(0.97);
  transition: all 0.25s var(--ease);
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast.success { background: var(--neon); box-shadow: 0 4px 20px var(--neon-glow); }
.toast.error { background: var(--warn); }

/* --- Tooltip --- */
.tooltip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--neon-dim);
  border: 1px solid var(--border-active);
  color: var(--neon);
  font-size: 9px;
  font-family: var(--font-mono);
  cursor: help;
  margin-left: 6px;
  vertical-align: middle;
  flex-shrink: 0;
}
.tooltip .tooltip-text {
  visibility: hidden;
  opacity: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border-active);
  color: var(--text-b);
  font-size: 12px;
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.5;
  padding: 8px 12px;
  border-radius: var(--r);
  position: absolute;
  z-index: 200;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: 220px;
  text-align: left;
  pointer-events: none;
  transition: opacity 0.18s var(--ease);
  box-shadow: var(--shadow);
  white-space: normal;
}
.tooltip:hover .tooltip-text,
.tooltip:focus .tooltip-text {
  visibility: visible;
  opacity: 1;
}
.tooltip .tooltip-text::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--border-active);
}

/* --- Error Banner --- */
.error-banner {
  margin-top: 14px;
  padding: 10px 16px;
  border-radius: var(--r);
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.35);
  color: var(--warn);
  font-size: 13px;
  font-family: var(--font-mono);
}

/* --- HTMX Loading Spinner --- */
.htmx-indicator {
  opacity: 0;
  transition: opacity 200ms ease-in;
}
.htmx-request .htmx-indicator,
.htmx-indicator.htmx-request {
  opacity: 1;
}
.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--neon-dim);
  border-top-color: var(--neon);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  margin: 14px auto 0;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Hide "Generating..." text by default; show during HTMX request */
.btn-loading { display: none; }
.btn-text { display: inline; }
.htmx-request .btn-loading { display: inline; }
.htmx-request .btn-text { display: none; }

/* --- Staggered Load Animation --- */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  animation: fadeUp 0.5s var(--ease) both;
}

.grid-2 > :nth-child(1) .card { animation-delay: 0.05s; }
.grid-2 > :nth-child(2) .card { animation-delay: 0.15s; }

.page-item {
  animation: fadeUp 0.4s var(--ease) both;
}

.page-item:nth-child(1) { animation-delay: 0.05s; }
.page-item:nth-child(2) { animation-delay: 0.1s; }
.page-item:nth-child(3) { animation-delay: 0.15s; }
.page-item:nth-child(4) { animation-delay: 0.2s; }
.page-item:nth-child(5) { animation-delay: 0.25s; }

/* --- Responsive --- */
@media (max-width: 768px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .navbar {
    padding: 14px 18px;
  }

  .navbar-links { gap: 4px; }

  .nav-link {
    padding: 6px 10px;
    font-size: 10px;
  }

  .page-header h1 {
    font-size: 1.5rem;
  }

  .card {
    padding: 20px;
  }

  .container, .show-container, .about-container {
    padding: 0 18px 36px;
  }

  .method-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .method-bar select {
    max-width: 100%;
  }

  .show-stats {
    gap: 20px;
  }

  .stat-value {
    font-size: 1.5rem;
  }
}
