/* Admin portal visual layer. Shared brand tokens are loaded after this file. */
:root {
  color-scheme: light;
  --bg: var(--ui-bg, #F4F6F6);
  --surface: var(--ui-surface, #fff);
  --surface-soft: var(--ui-surface-soft, #EFF3F3);
  --surface-strong: var(--ui-surface-strong, #E6ECEC);
  --border: var(--ui-border, #D9E1E1);
  --border-strong: var(--ui-border-strong, #BBC8C8);
  --text: var(--ui-text, #142125);
  --muted: var(--ui-muted, #526267);
  --subtle: var(--ui-subtle, #64767B);
  --accent: var(--ui-accent, #0B6D7E);
  --accent-soft: var(--ui-accent-soft, #DCEFF1);
  --primary: var(--ui-primary, #151B1E);
  --on-primary: var(--ui-on-primary, #fff);
  --danger: var(--ui-danger, #B42318);
  --positive: var(--ui-positive, #216E4E);
  --card-radius: var(--ui-radius-card, 8px);
  --control-radius: var(--ui-radius-control, 6px);
  --focus: var(--ui-focus, #0B6D7E);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --transition: 120ms ease;
}

html[data-theme="dark"] { color-scheme: dark; }
*, *::before, *::after { box-sizing: border-box; }
html, body { min-height: 100%; background: var(--bg); color: var(--text); }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
button, a, input, select { touch-action: manipulation; }
button { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
::selection { background: var(--accent-soft); color: var(--text); }

.portal-header {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px max(20px, calc((100vw - 1240px) / 2));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.portal-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.25px;
}
.portal-brand img, .login-brand img {
  display: block;
  width: 32px;
  height: 32px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: var(--control-radius);
}
.portal-header-actions { display: flex; align-items: center; gap: 8px; }
.portal-label {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--control-radius);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.theme-toggle {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--control-radius);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition), color var(--transition);
}
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.theme-toggle:hover, .portal-home-link:hover { background: var(--surface-soft); border-color: var(--border-strong); color: var(--text); }
.portal-home-link {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--control-radius);
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color var(--transition), border-color var(--transition), color var(--transition);
}

#loginScreen {
  min-height: calc(100svh - 64px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 28px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-brand img { width: 40px; height: 40px; }
.eyebrow { margin-bottom: 2px; color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: 0; text-transform: none; }
.login-card h1 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -.45px; line-height: 1.25; }
.login-card p { margin-bottom: 20px; color: var(--muted); font-size: 14px; }
.field-label { display: block; margin: 0 0 6px; color: var(--text); font-size: 13px; font-weight: 550; }
.field-label span { color: var(--subtle); font-weight: 400; }
.finput {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--control-radius);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition), background-color var(--transition);
}
.finput::placeholder { color: var(--subtle); opacity: 1; }
.finput:focus { border-color: var(--focus); }
select.finput { color-scheme: inherit; }
#pwInput { margin-bottom: 12px; }
.btn-primary, .btn-sm, .btn-tiny {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--control-radius);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition), color var(--transition);
}
.btn-primary { width: 100%; border-color: var(--primary); background: var(--primary); color: var(--on-primary); font-size: 14px; }
.btn-primary:hover { filter: brightness(.92); transform: none; }
.btn-sm:hover, .btn-tiny:hover { background: var(--surface-soft); border-color: var(--border-strong); }
.btn-sm.accent { border-color: var(--primary); background: var(--primary); color: var(--on-primary); }
.btn-sm.accent:hover { filter: brightness(.92); }
.err { display: none; margin-top: 12px; color: var(--danger); font-size: 13px; overflow-wrap: anywhere; }
.err.show { display: block; }

#dashScreen { display: none; max-width: 1280px; margin: 0 auto; padding: 28px 24px 64px; }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.top-row h1 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -.55px; line-height: 1.25; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.stats-row { display: flex; gap: 12px; margin-bottom: 16px; }
.stat-card {
  min-width: 140px;
  flex: 1;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  background: var(--surface);
}
.stat-num { color: var(--text); font-size: 22px; font-weight: 650; letter-spacing: -.4px; font-variant-numeric: tabular-nums; }
.stat-lbl { margin-top: 2px; color: var(--muted); font-size: 13px; }
.create-key-panel { width: 100%; margin-bottom: 16px; }
.create-key-heading { margin: 0 0 12px; font-size: 15px; font-weight: 600; letter-spacing: -.15px; }
.create-key-row { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 12px; }
.create-label-field { min-width: 200px; flex: 1 1 240px; }
.create-label-field .finput { display: block; }
.unlimited-label { min-height: 44px; display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; white-space: nowrap; }
#newUnlimited { width: 16px; height: 16px; accent-color: var(--accent); }
.key-result {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--control-radius);
  background: var(--surface-soft);
}
.key-result-label { margin-bottom: 6px; color: var(--muted); font-size: 12px; }
.key-result-row { display: flex; align-items: center; gap: 10px; }
#newKeyValue { min-width: 0; flex: 1; color: var(--positive); font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }
.storage-banner { margin-bottom: 14px; padding: 12px 14px; text-align: left; border: 1px solid var(--border-strong); border-radius: var(--card-radius); background: var(--surface); color: var(--muted); }

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  background: var(--surface);
  scrollbar-color: var(--border-strong) transparent;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.table-wrap:focus-visible { outline-offset: 2px; }
table { width: 100%; min-width: 960px; border-collapse: collapse; background: var(--surface); }
thead { background: var(--surface-soft); }
th { padding: 10px 12px; color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; white-space: nowrap; }
td { min-height: 44px; padding: 10px 12px; border-top: 1px solid var(--border); color: var(--text); font-size: 13px; vertical-align: middle; }
tbody tr { height: 44px; }
tbody tr:hover td { background: var(--surface-soft); }
.key-cell { color: var(--muted); font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums slashed-zero; }
#keysTable td:nth-child(6) { font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 2px 8px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-soft); color: var(--muted); font-size: 12px; font-weight: 550; }
.badge.active { border-color: color-mix(in srgb, var(--positive) 28%, var(--border)); color: var(--positive); }
.badge.deleted, .badge.suspended { border-color: color-mix(in srgb, var(--danger) 28%, var(--border)); color: var(--danger); }
.row-actions { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
.btn-tiny { min-height: 44px; padding: 0 10px; font-size: 12px; white-space: nowrap; }
.btn-tiny.danger { color: var(--danger); }
.btn-tiny.danger:hover { border-color: var(--danger); color: var(--danger); }
.btn-primary:disabled, .btn-sm:disabled, .btn-tiny:disabled { opacity: .6; cursor: wait; }
.empty-state { padding: 28px 16px; color: var(--muted); font-size: 13px; text-align: center; }
.toast {
  display: none;
  position: fixed;
  z-index: 50;
  right: 16px;
  bottom: 16px;
  left: auto;
  max-width: min(440px, calc(100vw - 32px));
  padding: 12px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--control-radius);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  overflow-wrap: anywhere;
  box-shadow: none;
  transform: none;
}
.toast.show { display: block; animation: fade-in 120ms ease-out; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.plan-panel { margin-top: 24px; padding: 16px; border: 1px solid var(--border); border-radius: var(--card-radius); background: var(--surface); }
.plan-heading-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.plan-heading-row h2 { margin: 0; font-size: 17px; font-weight: 620; letter-spacing: -.25px; }
.plan-heading-row p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.plan-form { display: flex; align-items: flex-end; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: var(--control-radius); background: var(--surface-soft); }
.plan-field { min-width: 0; }
.plan-email-field { flex: 1 1 300px; }
.plan-tier-field { flex: 0 1 180px; }
.plan-field label { display: block; margin: 0 0 6px; color: var(--text); font-size: 13px; font-weight: 550; }
.plan-field .finput { display: block; margin: 0; }
.plan-submit { white-space: nowrap; }
.plan-submit:disabled, .row-actions button:disabled { opacity: .6; cursor: wait; }
.plan-notice { min-height: 44px; padding: 12px 2px 8px; color: var(--muted); font-size: 13px; }
.plan-table-wrap { margin-top: 2px; }
.plan-table { min-width: 620px; }
.plan-table td:first-child { overflow-wrap: anywhere; }
.plan-tier { color: var(--text); }
.plan-empty { padding: 24px 16px; }

@media (max-width: 760px) {
  .portal-header { min-height: 60px; padding: 8px 16px; }
  .portal-header-actions { gap: 6px; }
  .portal-home-link { padding: 0 9px; font-size: 12px; }
  #loginScreen { min-height: calc(100svh - 60px); padding: 24px 16px; }
  #dashScreen { padding: 24px 16px 48px; }
  .top-row { align-items: flex-start; }
  .stats-row { gap: 8px; }
  .stat-card { min-width: calc(50% - 4px); padding: 12px; }
  .create-key-row { align-items: stretch; }
  .create-label-field { flex-basis: 100%; }
  .unlimited-label { flex: 1 1 auto; }
  #newKeyBtn { min-width: 140px; }
  .plan-heading-row { align-items: flex-start; flex-direction: column; gap: 10px; }
  .plan-form { align-items: stretch; flex-direction: column; gap: 10px; }
  .plan-email-field, .plan-tier-field { flex: 1 1 auto; }
  .plan-submit { width: 100%; }
  .table-wrap { border-radius: var(--control-radius); }
  .table-wrap::after { content: "Scroll horizontally to see all columns"; display: block; padding: 7px 12px; border-top: 1px solid var(--border); background: var(--surface-soft); color: var(--subtle); font-size: 11px; }
}
@media (max-width: 430px) {
  .portal-label { display: none; }
  .portal-brand { gap: 7px; font-size: 14px; }
  .portal-brand img { width: 28px; height: 28px; }
  .portal-home-link { font-size: 11px; }
  .login-card { padding: 22px 18px; }
  .top-row { flex-direction: column; }
  .top-row .actions, .top-row .btn-sm { width: 100%; }
  .stats-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-row .stat-card:last-child { grid-column: 1 / -1; }
  .create-key-row { display: grid; grid-template-columns: 1fr; }
  #newKeyBtn { width: 100%; }
  .plan-panel { padding: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
