:root {
  --bg-main: #09090b;
  --bg-surface: #121215;
  --bg-card: #18181b;
  --bg-card-hover: #222227;
  --bg-code: #000000;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(255, 255, 255, 0.25);
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  
  --accent-emerald: #10b981;
  --accent-emerald-dim: rgba(16, 185, 129, 0.15);
  --accent-primary: #f4f4f5;
  --accent-primary-hover: #ffffff;
  --accent-primary-text: #09090b;
  
  --color-danger: #f43f5e;
  --color-danger-dim: rgba(244, 63, 94, 0.15);
  --color-warning: #f59e0b;
  --color-info: #38bdf8;
  
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }

/* Header & Navigation */
.navbar {
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(9, 9, 11, 0.85);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.nav-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.brand-badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 9999px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}
.nav-link {
  font-size: 0.9rem;
  color: var(--text-secondary);
  transition: color 0.15s ease;
}
.nav-link:hover { color: var(--text-primary); }
.github-link {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.6rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  transition: all 0.15s ease;
}
.github-link:hover {
  color: var(--text-primary);
  background: var(--bg-card-hover);
  border-color: var(--border-focus);
}
.github-link svg { flex-shrink: 0; }
.github-stars {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.github-stars svg { color: var(--color-warning); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
}
.btn-primary {
  background-color: var(--accent-primary);
  color: var(--accent-primary-text);
}
.btn-primary:hover {
  background-color: var(--accent-primary-hover);
  box-shadow: 0 0 20px rgba(255,255,255,0.25);
}
.btn-secondary {
  background-color: var(--bg-card);
  border-color: var(--border-subtle);
  color: var(--text-primary);
}
.btn-secondary:hover {
  background-color: var(--bg-card-hover);
  border-color: var(--border-focus);
}
.btn-github {
  background-color: #24292f;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.12);
  width: 100%;
}
.btn-github:hover {
  background-color: #2f363d;
}
.btn-danger {
  background-color: transparent;
  color: var(--color-danger);
  border-color: rgba(244, 63, 94, 0.2);
}
.btn-danger:hover {
  background-color: var(--color-danger-dim);
  border-color: var(--color-danger);
}
.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

/* Layout */
/* width: 100% matters: as a flex item of body, auto margins would otherwise
   shrink-wrap the container to its content (and let wide content overflow). */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem;
  flex: 1;
}
/* Flash message rows sit above the page content and must not grow like it. */
.container.container-flash {
  flex: none;
  padding-top: 1.5rem;
  padding-bottom: 0;
}
.container-flash + .container {
  padding-top: 0;
}

/* Hero Section */
.hero {
  text-align: center;
  padding: 4rem 1rem 3rem;
  max-width: 800px;
  margin: 0 auto;
}
.hero h1 {
  font-size: 3.25rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.15;
  margin-bottom: 1.25rem;
  background: linear-gradient(180deg, #ffffff 0%, #a1a1aa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero p {
  font-size: 1.15rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
  line-height: 1.6;
}
.hero-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Terminal Component */
.terminal {
  background: var(--bg-code);
  border: 1px solid var(--border-subtle);
  border-radius: 0.75rem;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0,0,0,0.6);
  max-width: 760px;
  margin: 2.5rem auto 4rem;
  text-align: left;
  font-family: var(--font-mono);
}
.terminal-header {
  background: var(--bg-surface);
  padding: 0.65rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
}
.terminal-btn {
  width: 11px;
  height: 11px;
  border-radius: 50%;
}
.tb-red { background: #ff5f56; }
.tb-yellow { background: #ffbd2e; }
.tb-green { background: #27c93f; }
.terminal-title {
  margin-left: auto;
  margin-right: auto;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.terminal-body {
  padding: 1.25rem;
  font-size: 0.85rem;
  line-height: 1.6;
}
.t-line { margin-bottom: 0.35rem; }
.t-prompt { color: #818cf8; font-weight: 600; }
.t-cmd { color: #f4f4f5; font-weight: 500; }
.t-success { color: var(--accent-emerald); }
.t-info { color: #38bdf8; }
.t-muted { color: var(--text-muted); }
.t-url {
  color: #fafafa;
  text-decoration: underline;
  text-decoration-color: rgba(255,255,255,0.4);
}

/* Feature Grid */
.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin: 3rem 0;
}
.feature-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 0.75rem;
  padding: 1.75rem;
  transition: all 0.2s ease;
}
.feature-card:hover {
  border-color: var(--border-focus);
  transform: translateY(-2px);
}
.feature-icon {
  width: 40px;
  height: 40px;
  border-radius: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  display: grid;
  place-items: center;
  margin-bottom: 1.25rem;
  color: var(--text-primary);
}
.feature-card h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.feature-card p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.5;
}

/* Auth Cards */
.auth-wrapper {
  max-width: 400px;
  margin: 4rem auto;
}
.auth-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 0.85rem;
  padding: 2.25rem;
  box-shadow: 0 15px 35px rgba(0,0,0,0.4);
}
.auth-header {
  text-align: center;
  margin-bottom: 1.75rem;
}
.auth-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}
.auth-header p {
  font-size: 0.875rem;
  color: var(--text-secondary);
}
.form-group {
  margin-bottom: 1.2rem;
}
.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.4rem;
  color: var(--text-secondary);
}
.form-input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 0.5rem;
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s ease;
}
.form-input:focus {
  border-color: var(--accent-primary);
}
.divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 1.5rem 0;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border-subtle);
}
.divider span { padding: 0 0.75rem; }

/* Dashboard Header */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
  gap: 1rem;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.user-badge {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  max-width: 100%;
}
.user-meta {
  min-width: 0;
}
.user-name {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  font-weight: 600;
  font-size: 1.05rem;
}
.user-email {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-id {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.user-id code {
  word-break: break-all;
}
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-subtle);
  object-fit: cover;
  flex-shrink: 0;
}
.avatar-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 0.85rem;
  flex-shrink: 0;
}

/* One-time token banner */
.alert.token-banner {
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}
.token-banner-title {
  font-weight: 600;
  font-size: 0.95rem;
}
.token-banner-text {
  font-size: 0.85rem;
  color: #a7f3d0;
}
.token-banner .code-box {
  width: 100%;
}
.code-box-success span { color: #6ee7b7; }

/* Dashboard Tabs */
.tabs-nav {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 1.75rem;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs-nav::-webkit-scrollbar {
  display: none;
}
.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.65rem 1rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.15s ease;
  flex-shrink: 0;
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active {
  color: var(--text-primary);
  border-bottom-color: var(--text-primary);
}
.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  height: 1.25rem;
  padding: 0 0.4rem;
  border-radius: 9999px;
  background: rgba(255,255,255,0.06);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
}
.tab-btn.active .tab-count {
  background: rgba(255,255,255,0.14);
  color: var(--text-primary);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Data Tables */
.data-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 0.75rem;
  overflow: hidden;
  margin-bottom: 1.75rem;
}
.card-header {
  padding: 1.25rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
  gap: 0.5rem;
}
.card-header h2 {
  font-size: 1.05rem;
  font-weight: 600;
}
.card-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.table-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}
.table th {
  padding: 0.85rem 1.5rem;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(255,255,255,0.01);
}
.table td {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: rgba(255,255,255,0.015); }
.table .cell-actions { text-align: right; }
.table .table-empty {
  text-align: center;
  padding: 2.5rem;
  color: var(--text-muted);
}
.cell-title {
  font-weight: 600;
  color: var(--text-primary);
}
.cell-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.text-muted-sm {
  color: var(--text-muted);
  font-size: 0.8rem;
}
.text-live { color: var(--accent-emerald); }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}
.badge-active {
  background: var(--accent-emerald-dim);
  color: var(--accent-emerald);
}
.badge-ended {
  background: rgba(255,255,255,0.05);
  color: var(--text-muted);
}
.badge-muted {
  background: rgba(255,255,255,0.08);
}
.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* Client Setup */
.setup-steps {
  display: grid;
  gap: 1.5rem;
  padding: 1.5rem;
}
.setup-step h3 {
  font-size: 1rem;
  margin-bottom: 0.5rem;
}
.setup-note {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}
.setup-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}
.setup-hint code {
  white-space: nowrap;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(4px);
  display: none;
  place-items: center;
  padding: 1rem;
  z-index: 100;
}
.modal-backdrop.open { display: grid; }
.modal-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-focus);
  border-radius: 0.85rem;
  max-width: 500px;
  width: 100%;
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  padding: 2rem;
  box-shadow: 0 25px 50px rgba(0,0,0,0.7);
}
.modal-title {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}
.modal-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
}
.input-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.input-suffix {
  color: var(--text-muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

/* Snippets / Code blocks */
.code-box {
  background: var(--bg-code);
  border: 1px solid var(--border-subtle);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  margin-top: 0.5rem;
  overflow-x: auto;
  gap: 0.75rem;
}
.code-box span {
  min-width: 0;
  word-break: break-all;
}
.copy-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 0.25rem;
  transition: color 0.15s ease;
  flex-shrink: 0;
}
.copy-btn:hover { color: var(--text-primary); }

/* Alerts */
.alert {
  padding: 0.85rem 1.25rem;
  border-radius: 0.5rem;
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.alert-error {
  background: var(--color-danger-dim);
  border: 1px solid var(--color-danger);
  color: #ff859b;
}
.alert-success {
  background: var(--accent-emerald-dim);
  border: 1px solid var(--accent-emerald);
  color: #6ee7b7;
}

/* Footer */
footer {
  border-top: 1px solid var(--border-subtle);
  padding: 2rem 1.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: auto;
}

/* Responsive / Mobile Breakpoints */
@media (max-width: 768px) {
  .hero h1 {
    font-size: 2.5rem;
  }
  .nav-container {
    padding: 0.75rem 1rem;
  }
  .container {
    padding: 1.75rem 1rem;
  }
  .table th, .table td {
    padding: 0.85rem 1rem;
  }
}

@media (max-width: 640px) {
  .hero h1 {
    font-size: 2rem;
  }
  .hero p {
    font-size: 1rem;
    margin-bottom: 1.5rem;
  }
  .nav-links {
    gap: 0.75rem;
  }
  .container {
    padding: 1.5rem 1rem;
  }
  .container.container-flash {
    padding-top: 1rem;
  }

  /* Dashboard header: identity on top, actions as full-width buttons below */
  .dashboard-header {
    flex-direction: column;
    align-items: stretch;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
  }
  .user-name {
    font-size: 1rem;
  }
  .header-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    width: 100%;
    gap: 0.5rem;
  }
  .header-actions .btn {
    width: 100%;
    min-height: 2.5rem;
    padding: 0.55rem 0.5rem;
    white-space: nowrap;
  }

  /* Tabs: a 2x2 grid so every tab is visible without sideways scrolling */
  .tabs-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    border-bottom: none;
    overflow: visible;
    white-space: normal;
  }
  .tab-btn {
    justify-content: center;
    min-height: 2.75rem;
    padding: 0.55rem 0.5rem;
    font-size: 0.85rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 0.5rem;
  }
  .tab-btn.active {
    background: var(--bg-card-hover);
    border-color: var(--border-focus);
  }

  .card-header {
    padding: 1rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }

  /* Tables: each row becomes a card, with the primary cell and its aside
     (status badge or action button) on top and labelled fields below. */
  .table-stack thead {
    display: none;
  }
  .table-stack,
  .table-stack tbody {
    display: block;
  }
  .table-stack tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 0.75rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border-subtle);
  }
  .table-stack tr:last-child {
    border-bottom: none;
  }
  .table-stack tr:hover td {
    background: none;
  }
  .table-stack td {
    grid-column: 1 / -1;
    min-width: 0;
    padding: 0;
    border-bottom: none;
  }
  .table-stack td.cell-primary {
    grid-column: 1;
    grid-row: 1;
    align-self: center;
    overflow-wrap: anywhere;
  }
  .table-stack td.cell-aside {
    grid-column: 2;
    grid-row: 1;
    align-self: start;
  }
  .table-stack td[data-label] {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: 0.3rem 0;
    text-align: right;
    overflow-wrap: anywhere;
  }
  .table-stack td[data-label]::before {
    content: attr(data-label);
    flex-shrink: 0;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-align: left;
  }
  /* Long values (URLs) read better stacked under their label */
  .table-stack td.cell-block {
    display: block;
    text-align: left;
  }
  .table-stack td.cell-block::before {
    display: block;
    margin-bottom: 0.15rem;
  }
  .table-stack .cell-primary + td[data-label] {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-subtle);
  }
  .table-stack .btn-sm {
    min-height: 2.25rem;
    padding: 0.4rem 0.85rem;
  }
  .table-stack td.table-empty {
    padding: 1.5rem 0.5rem;
  }

  /* Code snippets & copy buttons */
  .code-box {
    padding: 0.65rem 0.75rem;
    font-size: 0.8rem;
  }
  .copy-btn {
    min-width: 2rem;
    min-height: 2rem;
  }
  .setup-steps {
    padding: 1rem;
    gap: 1.25rem;
  }

  /* Modals */
  .modal-backdrop {
    padding: 0.75rem;
  }
  .modal-box {
    padding: 1.5rem 1.25rem;
  }
  .form-input {
    font-size: 1rem; /* 16px or larger stops iOS Safari zooming on focus */
  }
  .input-group {
    flex-wrap: wrap;
  }
  .input-suffix {
    white-space: normal;
    overflow-wrap: anywhere;
    font-size: 0.85rem;
  }
  .modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .modal-actions .btn {
    min-height: 2.75rem;
    padding: 0.55rem 0.5rem;
    white-space: nowrap;
  }

  footer {
    padding: 1.5rem 1rem;
    font-size: 0.8rem;
  }
  .terminal-body {
    padding: 1rem;
    font-size: 0.8rem;
  }
  .feature-card {
    padding: 1.25rem;
  }
  .auth-card {
    padding: 1.5rem;
  }
}

@media (max-width: 400px) {
  .brand-badge {
    display: none;
  }
  .github-stars {
    display: none;
  }
  .github-link {
    padding: 0.35rem;
  }
}
