/* ── Design Tokens ─────────────────────────────────────────────────────── */
:root {
  --bg-base:       #0a0e1a;
  --bg-surface:    #111827;
  --bg-elevated:   #1a2235;
  --bg-hover:      #1e2a3d;
  --border:        #1e2d45;
  --border-light:  #2a3f5f;

  --accent-cyan:   #22d3ee;
  --accent-cyan-dim: rgba(34, 211, 238, 0.15);
  --accent-purple: #a855f7;
  --accent-purple-dim: rgba(168, 85, 247, 0.15);
  --accent-blue:   #3b82f6;

  --status-green:  #10b981;
  --status-green-dim: rgba(16, 185, 129, 0.15);
  --status-yellow: #f59e0b;
  --status-yellow-dim: rgba(245, 158, 11, 0.15);
  --status-grey:   #6b7280;
  --status-grey-dim: rgba(107, 114, 128, 0.15);

  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #475569;

  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.6);
  --shadow-glow-cyan: 0 0 20px rgba(34,211,238,0.2);
  --shadow-glow-purple: 0 0 20px rgba(168,85,247,0.2);

  --nav-width: 240px;
  --header-height: 60px;
}

/* ── Reset & Base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background-color: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--accent-cyan); text-decoration: none; transition: color 0.2s; }
a:hover { color: #67e8f9; }

code, pre, .mono { font-family: var(--font-mono); }

img, svg { display: block; }

/* ── Typography ────────────────────────────────────────────────────────── */
h1 { font-size: clamp(2rem, 5vw, 3.5rem); font-weight: 800; line-height: 1.1; letter-spacing: -0.02em; }
h2 { font-size: clamp(1.4rem, 3vw, 2rem); font-weight: 700; line-height: 1.2; }
h3 { font-size: clamp(1.1rem, 2vw, 1.4rem); font-weight: 600; }
h4 { font-size: 1rem; font-weight: 600; }

p { color: var(--text-secondary); }

.gradient-text {
  background: linear-gradient(135deg, var(--accent-cyan) 0%, var(--accent-purple) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Layout ────────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--nav-width);
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s ease;
}

.main-content {
  margin-left: var(--nav-width);
  flex: 1;
  min-width: 0;
}

.page-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2.5rem 2rem;
}

/* ── Sidebar ───────────────────────────────────────────────────────────── */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 1.2rem 1.2rem 1rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
}

.sidebar-logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-logo-text {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.sidebar-logo-sub {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0.75rem;
  overflow-y: auto;
}

.sidebar-section-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 0.75rem 0.5rem 0.3rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s;
  text-decoration: none;
}

.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-link.active {
  background: var(--accent-cyan-dim);
  color: var(--accent-cyan);
}

.nav-link svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-link.active svg { opacity: 1; }

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
}

.sidebar-footer a {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.sidebar-footer a:hover { color: var(--text-secondary); }

/* Mobile header */
.mobile-header {
  display: none;
  position: sticky;
  top: 0;
  z-index: 99;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  align-items: center;
  justify-content: space-between;
}

.mobile-header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
}

.hamburger {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
}

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: rgba(17, 24, 39, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
}

.card-hover {
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.card-hover:hover {
  transform: translateY(-2px);
  border-color: var(--border-light);
  box-shadow: var(--shadow-lg);
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.card-body { color: var(--text-secondary); font-size: 0.875rem; }

/* ── Section heading ───────────────────────────────────────────────────── */
.section-heading {
  margin-bottom: 1.5rem;
}

.section-heading h2 {
  margin-bottom: 0.4rem;
}

.section-heading p {
  font-size: 0.95rem;
}

/* ── Grid helpers ──────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }

/* ── Input / Control ───────────────────────────────────────────────────── */
input[type="text"],
input[type="search"],
select,
textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  padding: 0.5rem 0.75rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}

input[type="text"]:focus,
input[type="search"]:focus,
select:focus,
textarea:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px var(--accent-cyan-dim);
}

select option { background: var(--bg-surface); }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--accent-cyan);
  color: #000;
}

.btn-primary:hover { background: #67e8f9; color: #000; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-light);
}

/* ── Code blocks ───────────────────────────────────────────────────────── */
pre {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.6;
}

:not(pre) > code {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.15em 0.4em;
  font-size: 0.85em;
  color: var(--accent-cyan);
}

/* ── Tables ────────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table thead th {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.6rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.data-table tbody tr:hover { background: var(--bg-hover); }

.data-table tbody td {
  padding: 0.6rem 1rem;
  vertical-align: middle;
  color: var(--text-secondary);
}

.data-table tbody td:first-child {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-primary);
  font-weight: 500;
}

/* ── Badges ────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-implemented {
  background: var(--status-green-dim);
  color: var(--status-green);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-stub {
  background: var(--status-yellow-dim);
  color: var(--status-yellow);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-not_started {
  background: var(--status-grey-dim);
  color: var(--status-grey);
  border: 1px solid rgba(107, 114, 128, 0.3);
}

.badge-cyan {
  background: var(--accent-cyan-dim);
  color: var(--accent-cyan);
  border: 1px solid rgba(34,211,238,0.3);
}

.badge-purple {
  background: var(--accent-purple-dim);
  color: var(--accent-purple);
  border: 1px solid rgba(168,85,247,0.3);
}

/* ── Progress bar ──────────────────────────────────────────────────────── */
.progress-bar {
  height: 6px;
  background: var(--bg-elevated);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent-purple));
  transition: width 0.6s ease;
}

/* ── Tooltips ──────────────────────────────────────────────────────────── */
[data-tooltip] { position: relative; cursor: default; }

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.75rem;
  padding: 4px 8px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 50;
}

[data-tooltip]:hover::after { opacity: 1; }

/* ── Divider ───────────────────────────────────────────────────────────── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

/* ── Scroll hint ───────────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

/* ── Animations ────────────────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

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

.fade-in { animation: fadeIn 0.3s ease forwards; }

.skeleton {
  background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-hover) 50%, var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

/* ── Bottom Navigation ─────────────────────────────────────────────────── */
.bottom-nav {
  display: none; /* enabled in @media (max-width: 768px) */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: rgba(17, 24, 39, 0.97);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  /* padding drives the height — no fixed height so safe-area-inset works cleanly */
  padding: 8px 0.5rem;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  justify-content: space-around;
  align-items: center;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: color 0.15s;
  min-width: 56px;
  text-align: center;
}

.bottom-nav-item svg {
  width: 22px;
  height: 22px;
  transition: transform 0.15s;
  flex-shrink: 0;
}

.bottom-nav-item:hover { color: var(--text-secondary); }

.bottom-nav-item.active {
  color: var(--accent-cyan);
}

.bottom-nav-item.active svg {
  transform: scale(1.1);
  filter: drop-shadow(0 0 6px rgba(34,211,238,0.4));
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none !important; }
  .sidebar-overlay { display: none !important; }
  .hamburger { display: none !important; }

  .mobile-header { display: none !important; }

  .main-content {
    margin-left: 0;
    /* bottom nav height ≈ 8+22+3+10+8 = ~51px items + padding; add extra room */
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }

  .page-inner { padding: 1.25rem 1rem 1.5rem; }

  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }

  .bottom-nav { display: flex; }

  h1 { font-size: clamp(1.6rem, 6vw, 2.4rem); }
}

@media (max-width: 480px) {
  .page-inner { padding: 1rem 0.75rem 1.5rem; }
  .card { padding: 1rem; }
}

@media (max-width: 1024px) and (min-width: 769px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1400px) {
  :root { --nav-width: 260px; }
  .page-inner { max-width: 1200px; }
}

/* ── iOS / Capacitor native app ─────────────────────────────────────────── */

/* Momentum scrolling on scrollable containers */
.main-content,
.table-wrapper,
.builder-results {
  -webkit-overflow-scrolling: touch;
}

/* Remove tap flash on all interactive elements */
a, button, [role="button"], input, select, textarea, label {
  -webkit-tap-highlight-color: transparent;
}

/* Prevent callout (copy menu) on long-press for UI elements */
.bottom-nav, .sidebar, .card, .btn, .badge, .bit-cell {
  -webkit-touch-callout: none;
}

/* Native app: push content below status bar */
.native-app .app-layout {
  padding-top: env(safe-area-inset-top, 0px);
}

/* Prevent rubber-band overscroll on the page root in native */
.native-app body {
  overscroll-behavior: none;
}

/* Hide the force-update button in native (Railway env vars don't apply) */
.native-app #force-update-btn,
.native-app #force-update-status {
  display: none !important;
}
