/* ============================================================
   MProxy — design tokens
   Two complete palettes. Light is designed on its own terms:
   layered neutral greys with white cards, not an inverted dark.
   ============================================================ */

html[data-theme="light"] {
  --bg:            #f4f5f7;
  --bg-glow:       rgba(11,127,96,.07);
  --surface:       #ffffff;
  --surface-2:     #fafbfc;
  --surface-hover: #f3f4f6;
  --border:        #e4e6ea;
  --border-strong: #d3d6db;
  --text:          #1b1d21;
  --text-2:        #6b7280;
  --text-3:        #9ba1a9;
  --accent:        #0b7f60;   /* 4.98:1 on white — AA for button text */
  --accent-hover:  #096b51;
  --accent-ink:    #ffffff;
  --accent-soft:   rgba(11,127,96,.10);
  --ok:            #2f9e68;
  --ok-soft:       rgba(47,158,104,.12);
  --danger:        #c4453c;
  --danger-hover:  #a83a32;
  --danger-soft:   rgba(196,69,60,.10);
  --shadow-sm:     0 1px 2px rgba(16,20,28,.05);
  --shadow-md:     0 2px 8px rgba(16,20,28,.07), 0 1px 2px rgba(16,20,28,.04);
  --shadow-lg:     0 12px 32px rgba(16,20,28,.10), 0 2px 6px rgba(16,20,28,.05);
}

html[data-theme="dark"] {
  --bg:            #0f1114;
  --bg-glow:       rgba(45,189,138,.06);
  --surface:       #16191e;
  --surface-2:     #1b1f25;
  --surface-hover: #1f242a;
  --border:        #262b32;
  --border-strong: #333941;
  --text:          #f0f2f4;
  --text-2:        #98a0aa;
  --text-3:        #6d757f;
  --accent:        #2dbd8a;
  --accent-hover:  #46cd9c;
  --accent-ink:    #07130f;
  --accent-soft:   rgba(45,189,138,.13);
  --ok:            #3fb883;
  --ok-soft:       rgba(63,184,131,.14);
  --danger:        #e0665c;
  --danger-hover:  #ea7a71;
  --danger-soft:   rgba(224,102,92,.12);
  --shadow-sm:     0 1px 2px rgba(0,0,0,.30);
  --shadow-md:     0 2px 10px rgba(0,0,0,.35);
  --shadow-lg:     0 14px 40px rgba(0,0,0,.45);
}

:root {
  --r-card:   16px;
  --r-input:  13px;
  --r-btn:    12px;
  --r-pill:   999px;
  --sidebar:  260px;
  --content:  1180px;
  --tap:      44px;
  --ease:     cubic-bezier(.32,.72,0,1);
}

/* ============================================================
   Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

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

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.018em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.0625rem; letter-spacing: -.012em; }
h3 { font-size: .9375rem; }

.muted { color: var(--text-2); }
.mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: .8125rem;
  font-variant-ligatures: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}
::selection { background: var(--accent-soft); }

svg { flex: none; }

/* ============================================================
   Shell: sidebar + content
   ============================================================ */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  display: none;
  width: var(--sidebar);
  flex: none;
  flex-direction: column;
  padding: 22px 14px 18px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px 22px;
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -.02em;
}
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid; place-items: center;
  flex: none;
}

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--text-2);
  font-weight: 500;
  transition: background .16s var(--ease), color .16s var(--ease);
}
.nav a:hover { background: var(--surface-hover); color: var(--text); }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.nav a.on svg { color: var(--accent); }

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.who { padding: 0 10px; font-size: .8125rem; color: var(--text-3); overflow-wrap: anywhere; }

.content { flex: 1; min-width: 0; }
.page { max-width: var(--content); margin: 0 auto; padding: 24px 18px 72px; }
.page.narrow { max-width: 620px; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-head p { margin: 4px 0 0; color: var(--text-2); font-size: .875rem; }

/* ============================================================
   Mobile top bar
   ============================================================ */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar .brand { padding: 0; font-size: 1rem; }
.topbar nav {
  display: flex;
  gap: 2px;
  flex: 1;
  justify-content: center;
}
.topbar nav a {
  display: grid; place-items: center;
  min-width: var(--tap); min-height: var(--tap);
  padding: 0 12px;
  border-radius: 10px;
  color: var(--text-2);
  font-size: .875rem; font-weight: 500;
}
.topbar nav a.on { background: var(--accent-soft); color: var(--accent); }

/* ============================================================
   Theme switch — segmented control
   ============================================================ */
.theme-switch {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
}
.theme-switch button {
  display: grid; place-items: center;
  width: 32px; height: 30px;
  border: 0; border-radius: var(--r-pill);
  background: none; color: var(--text-3);
  cursor: pointer;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.theme-switch button:hover { color: var(--text); }
.theme-switch button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
html[data-theme="dark"] .theme-switch button[aria-pressed="true"] {
  background: var(--surface-hover);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: var(--tap);
  padding: 0 16px;
  border-radius: var(--r-btn);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .16s var(--ease), border-color .16s var(--ease),
              transform .1s var(--ease), opacity .16s var(--ease);
}
.btn:hover { background: var(--surface-hover); }
.btn:active { transform: scale(.985); }
.btn[disabled], .btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost { background: none; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }

.btn-danger { color: var(--danger); border-color: var(--border-strong); background: none; }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn-block { width: 100%; }
.btn-lg { min-height: 50px; font-size: .96875rem; }

/* ============================================================
   Cards, stats, tables
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 18px 20px; }
.card + .card { margin-top: 14px; }

.card-title {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 14px;
  color: var(--text-2);
  font-size: .8125rem;
  font-weight: 600;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}
.stat { padding: 16px 18px; }
.stat .n {
  display: block;
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -.03em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat .l { display: block; margin-top: 3px; color: var(--text-2); font-size: .8125rem; }
.stat.is-ok .n { color: var(--ok); }
.stat.is-fail .n { color: var(--danger); }

.kv { display: grid; gap: 12px; margin: 0; }
.kv > div { display: flex; justify-content: space-between; gap: 18px; align-items: baseline; }
.kv dt { color: var(--text-2); font-size: .875rem; flex: none; }
.kv dd { margin: 0; text-align: right; overflow-wrap: anywhere; }

.status-line { display: inline-flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.dot.is-ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.is-fail { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  font-size: .75rem; font-weight: 500;
  white-space: nowrap;
}
.badge.active { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.badge.failed { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.badge.disabled { color: var(--text-2); background: var(--surface-2); border-color: transparent; }

/* mobile card list (default) */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.row-card { display: block; padding: 15px 17px; transition: border-color .16s var(--ease); }
.row-card:hover { border-color: var(--border-strong); }
.row-card .rc-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.row-card .rc-name { font-weight: 600; }
.row-card .rc-meta {
  display: grid; gap: 3px;
  margin-top: 9px;
  color: var(--text-2); font-size: .8125rem;
  overflow-wrap: anywhere;
}
.row-card .rc-date { margin-top: 9px; color: var(--text-3); font-size: .75rem; }

/* desktop table */
.table-wrap { display: none; }
table.keys { width: 100%; border-collapse: collapse; }
table.keys th {
  text-align: left;
  padding: 0 16px 11px;
  color: var(--text-2);
  font-size: .78125rem;
  font-weight: 600;
}
table.keys td { padding: 14px 16px; border-top: 1px solid var(--border); vertical-align: middle; }
table.keys tbody tr { transition: background .14s var(--ease); }
table.keys tbody tr:hover { background: var(--surface-hover); }
table.keys .t-name { font-weight: 500; }
table.keys .t-hint { color: var(--text-2); overflow-wrap: anywhere; max-width: 230px; }
table.keys .t-date { color: var(--text-2); white-space: nowrap; font-size: .875rem; }
table.keys .t-act { text-align: right; white-space: nowrap; }

/* ============================================================
   Forms
   ============================================================ */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  margin-bottom: 7px;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-2);
}
.input {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-input);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  transition: border-color .16s var(--ease), box-shadow .16s var(--ease), background .16s var(--ease);
}
html[data-theme="light"] .input { background: var(--surface); }
.input::placeholder { color: var(--text-3); }
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px var(--accent-soft);
}
.help { margin: 7px 0 0; color: var(--text-3); font-size: .8125rem; }

/* ============================================================
   Notices
   ============================================================ */
.notice {
  display: flex; gap: 11px;
  padding: 13px 15px;
  border-radius: var(--r-input);
  font-size: .875rem;
  margin-bottom: 16px;
}
.notice svg { margin-top: 1px; }
.notice.is-ok   { background: var(--ok-soft); color: var(--ok); }
.notice.is-fail { background: var(--danger-soft); color: var(--danger); }
.notice.is-info {
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
}

/* ============================================================
   Protected key — the one loud element in the product
   ============================================================ */
.keybox { padding: 18px 20px; border-color: var(--border-strong); }
.key {
  display: block;
  padding: 14px 15px;
  margin: 12px 0;
  border-radius: var(--r-input);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: .78125rem;
  line-height: 1.65;
  overflow-wrap: anywhere;
  word-break: break-all;
  user-select: all;
  max-height: 8.5rem;
  overflow-y: auto;
  transition: filter .2s var(--ease);
}
.key.hidden {
  filter: blur(7px);
  user-select: none;
  pointer-events: none;
}

.actions { display: flex; gap: 9px; flex-wrap: wrap; }
.actions > * { flex: 1 1 auto; }
@media (min-width: 480px) { .actions > * { flex: 0 0 auto; } }

.danger-zone {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
  margin-top: 14px; padding-top: 14px;
  border-top: 1px solid var(--border);
}
.danger-zone p { margin: 0; font-size: .8125rem; color: var(--text-2); }

/* ============================================================
   Login
   ============================================================ */
.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 18px;
  position: relative;
  overflow: hidden;
}
.gate::before {
  content: "";
  position: absolute;
  top: -30vh; left: 50%;
  width: min(760px, 130vw); height: min(760px, 130vw);
  transform: translateX(-50%);
  background: radial-gradient(circle, var(--bg-glow) 0%, transparent 68%);
  pointer-events: none;
}
.gate-inner { width: 100%; max-width: 400px; position: relative; }
.gate-head { text-align: center; margin-bottom: 22px; }
.gate-head .brand { justify-content: center; padding: 0 0 12px; font-size: 1.25rem; }
.gate-head p { margin: 0; color: var(--text-2); font-size: .875rem; }
.gate .card { padding: 24px 22px; box-shadow: var(--shadow-lg); }
.gate-foot { display: flex; justify-content: center; margin-top: 20px; }

.empty { text-align: center; padding: 56px 20px; }
.empty h3 { margin-bottom: 6px; }
.empty p { margin: 0 0 18px; color: var(--text-2); font-size: .875rem; }

.back {
  display: inline-flex; align-items: center; gap: 6px;
  margin-bottom: 14px;
  color: var(--text-2); font-size: .875rem;
}
.back:hover { color: var(--text); }

.toast-ok { color: var(--ok); }

/* Utility classes replacing former inline style attributes.
   CSP is style-src 'self' with no 'unsafe-inline', so style="..." on an
   element is subject to blocking — every rule must live here. */
.help-flush     { margin: 0; }
.error-text     { color: var(--danger); }
.notice-spaced  { margin: 16px 0 0; }
.mobile-logout  { padding: 0 10px; }

/* ============================================================
   Tablet 768–1023: rail sidebar, roomier grid
   ============================================================ */
@media (min-width: 768px) {
  body { font-size: 15px; }
  .page { padding: 28px 26px 80px; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  h1 { font-size: 1.625rem; }

  .topbar { padding-left: 20px; padding-right: 20px; }
  .topbar nav { justify-content: flex-start; margin-left: 14px; }
}

/* ============================================================
   Desktop >=1024: real sidebar layout, table instead of cards
   ============================================================ */
@media (min-width: 1024px) {
  .topbar { display: none; }
  .sidebar { display: flex; }
  .page { padding: 34px 36px 90px; }
  h1 { font-size: 1.75rem; }

  .list { display: none; }
  .table-wrap { display: block; }

  .stats { gap: 14px; margin-bottom: 16px; }
  .stat { padding: 20px 22px; }
  .stat .n { font-size: 2.25rem; }

  .card-pad { padding: 22px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
