/* ==========================================================
   Shared tokens (mirrors landing page palette)
   ========================================================== */
:root {
  --ink:         #0d1f1b;
  --muted:       #627870;
  --muted-light: #94aca5;

  --bg:          #f5f8f6;
  --surface:     #ffffff;
  --surface-alt: #eef4f1;

  --border:      #dfe8e3;
  --border-mid:  #c4d5cc;

  --teal:        #0b8f7a;
  --teal-bright: #14b8a6;
  --teal-dim:    rgba(20, 184, 166, 0.15);
  --teal-dark:   #065f52;

  --red:         #dc2626;
  --red-dim:     rgba(220, 38, 38, 0.1);

  --sidebar-bg:  #070f0d;
  --sidebar-border: rgba(255,255,255,.07);

  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --mono: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;

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

  --shadow-sm: 0 1px 3px rgba(13,31,27,.07), 0 1px 2px rgba(13,31,27,.05);
  --shadow-md: 0 4px 16px rgba(13,31,27,.10), 0 2px 6px rgba(13,31,27,.06);
}

/* ==========================================================
   Reset
   ========================================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: var(--font); cursor: pointer; }

/* ==========================================================
   Buttons
   ========================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 40px;
  padding: 0 18px;
  font-size: 0.88rem;
  font-weight: 700;
  border: 1.5px solid transparent;
  border-radius: var(--r-md);
  white-space: nowrap;
  transition: background .14s, border-color .14s, color .14s, transform .12s, box-shadow .12s;
  cursor: pointer;
}

.btn-primary   { background: var(--ink);  color: #fff; }
.btn-primary:hover { background: var(--teal); }

.btn-teal      { background: var(--teal); color: #fff; }
.btn-teal:hover { background: var(--teal-dark); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(11,143,122,.35); }

.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--teal); color: var(--teal); }

.btn-danger    { background: var(--red-dim); color: var(--red); border-color: rgba(220,38,38,.25); }
.btn-danger:hover { background: var(--red); color: #fff; }

.btn-sm { height: 34px; padding: 0 14px; font-size: 0.82rem; }
.btn-full { width: 100%; }

/* ==========================================================
   Forms
   ========================================================== */
.field { margin-bottom: 18px; }

.field-label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.field-label-row .field-label { margin-bottom: 0; }
.field-label-link {
  font-size: 0.82rem;
  color: var(--teal);
  text-decoration: none;
}
.field-label-link:hover { text-decoration: underline; }

.form-success-card {
  padding: 16px;
  background: rgba(20,184,166,.08);
  border: 1px solid rgba(20,184,166,.2);
  border-radius: var(--r-md);
  font-size: 0.9rem;
  color: var(--fg-muted);
  line-height: 1.6;
  margin-bottom: 20px;
}

.field-label {
  display: block;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}

.field-input {
  width: 100%;
  height: 42px;
  padding: 0 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--surface);
  transition: border-color .12s, box-shadow .12s;
  appearance: none;
}

.field-input:focus {
  outline: none;
  border-color: var(--teal-bright);
  box-shadow: 0 0 0 3px var(--teal-dim);
}

.field-input.error { border-color: var(--red); }
.field-input.error:focus { box-shadow: 0 0 0 3px var(--red-dim); }

.field-hint {
  margin-top: 5px;
  font-size: 0.8rem;
  color: var(--muted);
}

.field-error {
  display: none;
  margin-top: 5px;
  font-size: 0.8rem;
  color: var(--red);
}
.field-error.visible { display: block; }

.form-error-banner {
  display: none;
  padding: 12px 14px;
  background: var(--red-dim);
  border: 1px solid rgba(220,38,38,.25);
  border-radius: var(--r-md);
  font-size: 0.88rem;
  color: var(--red);
  margin-bottom: 20px;
}
.form-error-banner.visible { display: block; }

.form-success-banner {
  display: none;
  padding: 12px 14px;
  background: rgba(20,184,166,.1);
  border: 1px solid rgba(20,184,166,.25);
  border-radius: var(--r-md);
  font-size: 0.88rem;
  color: var(--teal);
  margin-bottom: 20px;
}
.form-success-banner.visible { display: block; }

/* ==========================================================
   Auth pages
   ========================================================== */
.auth-page {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--ink);
  margin-bottom: 28px;
}

.logo-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  background: var(--ink);
  color: #fff;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: .02em;
  flex-shrink: 0;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 36px;
  box-shadow: var(--shadow-md);
}

.auth-card h1 {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -.025em;
  margin-bottom: 6px;
}

.auth-card .subtitle {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 28px;
}

.auth-footer {
  margin-top: 20px;
  text-align: center;
  font-size: 0.86rem;
  color: var(--muted);
}

.auth-footer a { color: var(--teal); font-weight: 600; }
.auth-footer a:hover { color: var(--teal-dark); }

/* ==========================================================
   App shell
   ========================================================== */
.app-shell {
  display: flex;
  min-height: 100svh;
}

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  border-right: 1px solid var(--sidebar-border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  font-size: 0.9rem;
  color: #fff;
  padding: 8px 10px 20px;
  border-bottom: 1px solid var(--sidebar-border);
  margin-bottom: 8px;
}

.sidebar-logo .logo-mark {
  background: rgba(255,255,255,.1);
}

.sidebar-nav {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  font-size: 0.88rem;
  font-weight: 500;
  color: #7fa89f;
  border-radius: var(--r-md);
  transition: background .12s, color .12s;
}

.nav-link:hover  { background: rgba(255,255,255,.06); color: #d0eae5; }
.nav-link.active { background: rgba(20,184,166,.12); color: var(--teal-bright); font-weight: 600; }

.nav-link svg { flex-shrink: 0; opacity: .8; }
.nav-link.active svg { opacity: 1; }

.sidebar-footer {
  border-top: 1px solid var(--sidebar-border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-md);
}

.user-avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  background: var(--teal);
  color: #fff;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  flex-shrink: 0;
}

.user-info { min-width: 0; }

.user-name {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: #d0eae5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-email {
  display: block;
  font-size: 0.74rem;
  color: #4a6e68;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logout-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  background: none;
  border: none;
  font-size: 0.86rem;
  color: #4a6e68;
  border-radius: var(--r-md);
  transition: background .12s, color .12s;
  text-align: left;
}
.logout-btn:hover { background: rgba(255,255,255,.05); color: #d0eae5; }

/* Main content */
.content {
  margin-left: 240px;
  flex: 1;
  background: var(--bg);
  min-height: 100svh;
}

.content-inner {
  max-width: 900px;
  padding: 40px 48px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
}

.page-title {
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -.025em;
}

/* ==========================================================
   Cards
   ========================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 28px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.card-header h2 {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -.01em;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.card-desc {
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 24px;
  line-height: 1.6;
}

.billing-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.billing-plan { padding-top: 4px; }
.plan-price   { display: flex; align-items: baseline; gap: 8px; }
.plan-amount  { font-size: 1.6rem; font-weight: 800; color: var(--ink); }
.plan-period  { font-size: 0.88rem; color: var(--muted); }

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
}

.badge-green  { background: rgba(20,184,166,.1);  color: var(--teal); border: 1px solid rgba(20,184,166,.2); }
.badge-gold   { background: rgba(245,158,11,.1);  color: #b45309;     border: 1px solid rgba(245,158,11,.2); }
.badge-red    { background: rgba(220,38,38,.1);   color: var(--red);  border: 1px solid rgba(220,38,38,.2); }
.badge-muted  { background: rgba(98,120,112,.1);  color: var(--muted); border: 1px solid rgba(98,120,112,.2); }

/* ==========================================================
   API Key
   ========================================================== */
.api-key-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  margin-bottom: 12px;
}

.api-key-value {
  flex: 1;
  font-family: var(--mono);
  font-size: 0.84rem;
  color: var(--ink);
  letter-spacing: .04em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.api-key-value.masked { letter-spacing: .12em; color: var(--muted-light); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--muted);
  transition: background .12s, color .12s, border-color .12s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg); color: var(--ink); border-color: var(--border-mid); }
.icon-btn.copied { color: var(--teal); border-color: var(--teal); }
.icon-btn-danger:hover { color: var(--red); border-color: var(--red); background: var(--red-dim); }

.api-key-hint {
  font-size: 0.82rem;
  color: var(--muted);
}

.api-key-hint code {
  font-family: var(--mono);
  font-size: .9em;
  background: var(--surface-alt, #eef4f1);
  padding: 1px 5px;
  border-radius: 3px;
}

/* ==========================================================
   Stats
   ========================================================== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 22px 24px;
}

.stat-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -.04em;
  line-height: 1;
}

/* ==========================================================
   Table
   ========================================================== */
.table-wrap {
  overflow-x: auto;
  margin: -4px;
  padding: 4px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 12px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--bg); }

.table-empty,
.table-loading {
  text-align: center;
  padding: 40px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ==========================================================
   Settings sections
   ========================================================== */
.settings-section {
  margin-bottom: 12px;
}

.settings-section h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.settings-section .section-desc {
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 24px;
}

.danger-zone {
  border-color: rgba(220,38,38,.25);
}

.danger-zone .card-header h2 { color: var(--red); }

/* ==========================================================
   Delete modal
   ========================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--surface);
  border-radius: var(--r-xl);
  padding: 36px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 24px 80px rgba(0,0,0,.22);
  transform: translateY(10px);
  transition: transform .18s;
}

.modal-overlay.open .modal { transform: translateY(0); }

.modal h3 {
  font-size: 1.15rem;
  font-weight: 800;
  margin-bottom: 10px;
}

.modal p {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 24px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

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

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

/* ==========================================================
   Responsive
   ========================================================== */
@media (max-width: 900px) {
  .content-inner { padding: 32px 24px; }
  .stats-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 680px) {
  .sidebar { width: 200px; }
  .content { margin-left: 200px; }
  .content-inner { padding: 24px 16px; }
  .stats-row { grid-template-columns: 1fr; }
}

/* ==========================================================
   Utilities
   ========================================================== */
.hidden { display: none; }
.mt-4 { margin-top: 1rem; }
.text-danger { color: var(--red); }
.billing-plan .pricing-list { margin-top: 18px; }
