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

:root {
  --bg:          #0f1117;
  --surface:     #1a1d27;
  --surface-alt: #252830;
  --border:      #2d3142;
  --accent:      #6366f1;
  --accent-hover:#818cf8;
  --text:        #e2e8f0;
  --text-muted:  #94a3b8;
  --green:       #22c55e;
  --red:         #ef4444;
  --radius:      8px;
  --radius-sm:   6px;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Login Screen ── */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-card h1 {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.login-card p {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 24px;
}

.login-error {
  color: var(--red);
  font-size: 0.8125rem;
  margin-top: 12px;
  min-height: 20px;
}

.otp-sent-msg {
  color: var(--green);
  font-size: 0.8125rem;
  margin-bottom: 16px;
}

.topbar-email {
  color: var(--text-muted);
  font-size: 0.8125rem;
}

/* ── Form Elements ── */
input, select, textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

label {
  display: block;
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-group {
  margin-bottom: 16px;
  text-align: left;
}

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

.btn:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary   { background: var(--accent); color: #fff; }
.btn-danger    { background: var(--red); color: #fff; }
.btn-secondary { background: var(--surface-alt); color: var(--text); border: 1px solid var(--border); }
.btn-sm        { padding: 6px 12px; font-size: 0.8125rem; }
.btn-full      { width: 100%; justify-content: center; }

/* ── Dashboard Layout ── */
.dashboard { display: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar h1 { font-size: 1.125rem; }

.container { padding: 24px; max-width: 1200px; margin: 0 auto; }

/* ── Stats Cards ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.stat-card .label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 700;
}

/* ── Action Bar ── */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.action-bar h2 { font-size: 1.125rem; }

/* ── Table ── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }

th {
  text-align: left;
  padding: 12px 16px;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-alt); }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-active  { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-revoked { background: rgba(239,68,68,0.15); color: var(--red); }

.key-mono {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

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

.empty-row td {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 16px;
}

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 480px;
}

.modal h2 { margin-bottom: 20px; font-size: 1.125rem; }

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

/* ── Key Reveal ── */
.key-reveal {
  display: none;
  margin-top: 20px;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
}

.key-reveal.show { display: block; }

.key-reveal .warning {
  color: var(--red);
  font-size: 0.8125rem;
  margin-bottom: 10px;
  font-weight: 600;
}

.key-reveal code {
  display: block;
  word-break: break-all;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.875rem;
  background: var(--surface-alt);
  padding: 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
}

.copy-success {
  color: var(--green);
  font-size: 0.8125rem;
  margin-left: 10px;
  opacity: 0;
  transition: opacity 0.3s;
}

.copy-success.show { opacity: 1; }

/* ── Usage Panel ── */
.usage-panel {
  display: none;
  margin-top: 24px;
}

.usage-panel.open { display: block; }

.usage-panel h3 {
  margin-bottom: 12px;
  font-size: 1rem;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}

.pagination span { font-size: 0.8125rem; color: var(--text-muted); }

/* ── Responsive ── */
@media (max-width: 768px) {
  .container { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .action-bar { flex-direction: column; gap: 12px; align-items: flex-start; }
  .modal { padding: 24px; }
  th, td { padding: 10px 12px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}

/* ── Utilities ── */
.hidden { display: none !important; }
