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

/* ── Design tokens ───────────────────────────────────────────────────────────── */
:root {
  --sidebar-w:     240px;
  --sidebar-bg:    #1e293b;
  --sidebar-text:  #94a3b8;
  --sidebar-hover: rgba(255,255,255,0.06);
  --sidebar-active-bg: rgba(59,130,246,0.15);
  --sidebar-active-border: #3b82f6;

  --accent:        #3b82f6;
  --accent-hover:  #2563eb;
  --bg:            #f1f5f9;
  --card:          #ffffff;
  --text:          #1e293b;
  --text-muted:    #64748b;
  --border:        #e2e8f0;
  --radius:        8px;
  --shadow:        0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:     0 4px 12px rgba(0,0,0,0.1);

  --green:  #22c55e;  --green-bg:  #dcfce7;  --green-text:  #15803d;
  --orange: #f59e0b;  --orange-bg: #fef3c7;  --orange-text: #b45309;
  --red:    #ef4444;  --red-bg:    #fee2e2;  --red-text:    #991b1b;
  --gray:             --gray-bg:   #f1f5f9;  --gray-text:   #475569;
}

/* ── Base ────────────────────────────────────────────────────────────────────── */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }

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

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 200;
  transition: transform .25s ease;
}

.sidebar-brand {
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.sidebar-brand h1 { font-size: 15px; font-weight: 700; color: #fff; }
.sidebar-brand p  { font-size: 11px; color: var(--sidebar-text); margin-top: 2px; }

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }

.nav-section-label {
  padding: 14px 20px 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: rgba(148,163,184,0.5);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  border-left: 3px solid transparent;
  transition: all .15s;
  cursor: pointer;
}
.nav-item svg { flex-shrink: 0; opacity: 0.7; }
.nav-item:hover { color: #fff; background: var(--sidebar-hover); }
.nav-item.active {
  color: #fff;
  background: var(--sidebar-active-bg);
  border-left-color: var(--sidebar-active-border);
}
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,0.07);
}

/* ── Overlay (mobile) ────────────────────────────────────────────────────────── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 199;
}

/* ── Main area ───────────────────────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Topbar ──────────────────────────────────────────────────────────────────── */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 13px 28px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-title { font-size: 17px; font-weight: 600; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.menu-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--text-muted);
  border-radius: 6px;
}
.menu-btn:hover { background: var(--bg); }

/* ── Content ─────────────────────────────────────────────────────────────────── */
.content { padding: 24px 28px; flex: 1; }

/* ── Cards ───────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-header h2 { font-size: 15px; font-weight: 600; }
.card-body { padding: 22px; }

/* ── Stats row ───────────────────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.stat-value { font-size: 26px; font-weight: 700; margin-bottom: 3px; }
.stat-label { font-size: 11px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card.green .stat-value { color: var(--green-text); }
.stat-card.orange .stat-value { color: var(--orange-text); }
.stat-card.red .stat-value { color: var(--red-text); }

/* ── Table ───────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

thead th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
tbody td { padding: 11px 16px; vertical-align: middle; }

.key-cell {
  font-family: 'Courier New', Courier, monospace;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.5px;
}

/* ── Badges ──────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.badge-active   { background: var(--green-bg);  color: var(--green-text); }
.badge-expiring { background: var(--orange-bg); color: var(--orange-text); }
.badge-grace    { background: #ffedd5;          color: #c2410c; }
.badge-expired  { background: var(--red-bg);    color: var(--red-text); }
.badge-revoked  { background: #f1f5f9;          color: #475569; }
.badge-standard { background: #eff6ff;          color: #1d4ed8; }
.badge-premium  { background: #faf5ff;          color: #7e22ce; }
.badge-billmate_desktop { background: #f1f5f9;  color: #334155; }
.badge-billmate_mobile  { background: #ecfdf5;  color: #047857; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all .15s;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

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

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

.btn-danger    { background: var(--red-bg); color: var(--red-text); }
.btn-danger:hover { background: var(--red); color: #fff; }

.btn-warning   { background: var(--orange-bg); color: var(--orange-text); }
.btn-warning:hover { background: var(--orange); color: #fff; }

.btn-success   { background: var(--green-bg); color: var(--green-text); }
.btn-success:hover { background: var(--green); color: #fff; }

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

.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-lg { padding: 10px 22px; font-size: 15px; }
.btn-icon { padding: 7px; }

/* ── Forms ───────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}
.form-required { color: var(--red); margin-left: 2px; }

.form-input, .form-select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
}
.form-input:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 5px; }

/* ── Alerts ──────────────────────────────────────────────────────────────────── */
.alert {
  padding: 11px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
  margin-bottom: 16px;
  border: 1px solid transparent;
  display: none;
}
.alert.show { display: block; }
.alert-error   { background: var(--red-bg);    color: var(--red-text);    border-color: #fca5a5; }
.alert-success { background: var(--green-bg);  color: var(--green-text);  border-color: #86efac; }
.alert-info    { background: #eff6ff;          color: #1e40af;            border-color: #bfdbfe; }

/* ── Login page ──────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sidebar-bg);
  padding: 20px;
}
.login-card {
  background: var(--card);
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.login-logo { text-align: center; margin-bottom: 30px; }
.login-logo h1 { font-size: 22px; font-weight: 700; }
.login-logo p  { font-size: 13px; color: var(--text-muted); margin-top: 3px; }
.login-logo .logo-icon {
  width: 52px;
  height: 52px;
  background: var(--accent);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
  color: #fff;
}

/* ── Key display (create success) ────────────────────────────────────────────── */
.key-display {
  background: #f8fafc;
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius);
  padding: 22px;
  text-align: center;
  margin: 20px 0;
}
.key-display .key-value {
  font-family: 'Courier New', Courier, monospace;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 1.5px;
  margin-bottom: 14px;
  word-break: break-all;
}

/* ── Info grid (detail page) ─────────────────────────────────────────────────── */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px 28px;
}
.info-item {}
.info-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 5px;
}
.info-value { font-size: 14.5px; font-weight: 500; }
.info-value.mono {
  font-family: 'Courier New', Courier, monospace;
  font-size: 13.5px;
  color: var(--accent);
  letter-spacing: 0.5px;
}
.info-value.muted { color: var(--text-muted); font-style: italic; font-weight: 400; }

/* ── Actions section ─────────────────────────────────────────────────────────── */
.actions-row { display: flex; flex-wrap: wrap; gap: 10px; }

.danger-zone {
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: 20px 22px;
  background: #fff5f5;
  margin-top: 8px;
}
.danger-zone h3 { font-size: 13px; font-weight: 600; color: var(--red-text); margin-bottom: 10px; }
.danger-zone p  { font-size: 13px; color: #6b2f2f; margin-bottom: 14px; }

/* ── Utility ─────────────────────────────────────────────────────────────────── */
.section-gap { margin-bottom: 20px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.text-muted  { color: var(--text-muted); }
.text-small  { font-size: 12px; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }

.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { text-align: center; padding: 56px 20px; color: var(--text-muted); }
.empty-state svg { opacity: 0.3; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

.days-ok      { color: var(--green-text); font-weight: 600; }
.days-warning { color: var(--orange-text); font-weight: 600; }
.days-danger  { color: var(--red-text); font-weight: 600; }

/* ── Help Center ─────────────────────────────────────────────────────────────── */
.help-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}
.help-toc a {
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 20px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  transition: all .15s;
}
.help-toc a:hover { background: var(--bg); color: var(--text); border-color: var(--accent); }

.help-section { margin-bottom: 20px; }
.help-section h2 {
  font-size: 16.5px;
  font-weight: 700;
  margin-bottom: 4px;
  padding-top: 6px;
  scroll-margin-top: 16px;
}
.help-section .help-kicker {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 4px;
}
.help-section p { font-size: 13.5px; color: var(--text); margin-bottom: 10px; }
.help-section ol, .help-section ul { margin: 0 0 12px 20px; font-size: 13.5px; }
.help-section li { margin-bottom: 6px; }
.help-section h3 { font-size: 13.5px; font-weight: 600; margin: 14px 0 6px; }

.callout {
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  margin: 12px 0;
  border: 1px solid transparent;
}
.callout strong { display: block; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 3px; }
.callout-tip     { background: var(--green-bg);  color: var(--green-text);  border-color: #86efac; }
.callout-warning { background: var(--orange-bg); color: var(--orange-text); border-color: #fcd34d; }
.callout-mistake { background: var(--red-bg);    color: var(--red-text);    border-color: #fca5a5; }

.faq-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
}
.faq-item summary {
  padding: 12px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fafc;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: '+'; font-size: 16px; color: var(--text-muted); }
.faq-item[open] summary::after { content: '−'; }
.faq-item .faq-answer { padding: 12px 16px; font-size: 13.5px; color: var(--text-muted); border-top: 1px solid var(--border); }

.help-step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  margin-right: 6px;
  flex-shrink: 0;
}

/* ── Mobile ──────────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .overlay.show { display: block; }
  .main { margin-left: 0; }
  .menu-btn { display: flex; }
  .content { padding: 16px; }
  .topbar { padding: 11px 16px; }
  .stats-row { grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: 1fr; gap: 14px; }
  .actions-row { gap: 8px; }
  .card-header { flex-wrap: wrap; }
  thead th:nth-child(3),
  tbody td:nth-child(3) { display: none; }
}

@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 22px; }
  .login-card { padding: 28px 22px; }
}
