:root {
  --ink: #171b1f;
  --muted: #687178;
  --paper: #f4f2ed;
  --surface: #fffefa;
  --surface-strong: #ffffff;
  --line: #dedbd2;
  --line-strong: #c8c4ba;
  --accent: #125e59;
  --accent-strong: #0a4743;
  --accent-soft: #dcece7;
  --warm: #d98d4f;
  --danger: #a64239;
  --danger-soft: #f6e4e0;
  --success: #2d7556;
  --shadow: 0 24px 70px rgb(25 35 38 / 10%);
  --radius: 18px;
  --radius-small: 11px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--paper); }

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background:
    radial-gradient(circle at 9% 2%, rgb(18 94 89 / 9%), transparent 29rem),
    radial-gradient(circle at 98% 92%, rgb(217 141 79 / 9%), transparent 25rem),
    var(--paper);
}

button, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid rgb(18 94 89 / 22%);
  outline-offset: 2px;
}

.boot {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  color: var(--muted);
}
.boot-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.brand-mark {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 13px 13px 13px 4px;
  color: white;
  background: var(--accent);
  font-family: Georgia, serif;
  font-size: 25px;
}

.login-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}

.brand-lockup { position: relative; z-index: 1; display: flex; align-items: center; gap: 12px; font-weight: 700; letter-spacing: -.02em; }
.brand-lockup .brand-mark { color: var(--accent-strong); background: #d7eee7; }

.login-panel { display: grid; width: 100%; place-items: center; }
.login-card { width: min(100%, 360px); }
.eyebrow { margin: 0 0 9px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.login-card h2, .dialog h2 { margin: 0; font: 500 34px/1.1 Georgia, serif; letter-spacing: -.025em; }
.login-card > p { margin: 14px 0 30px; color: var(--muted); line-height: 1.55; }
.field-stack { display: grid; gap: 18px; }
label > span { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 700; }
input, select {
  width: 100%;
  height: 47px;
  padding: 0 13px;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-small);
  background: var(--surface-strong);
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:hover, select:hover { border-color: #9e9a90; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgb(18 94 89 / 8%); outline: 0; }
label small, .muted { color: var(--muted); font-size: 12px; line-height: 1.45; }
label small { display: block; margin-top: 6px; }

.button {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 750;
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { cursor: progress; opacity: .58; }
.button.primary { color: white; background: var(--accent); }
.button.primary:hover:not(:disabled) { background: var(--accent-strong); }
.button.secondary { color: var(--accent-strong); border-color: #acc9c2; background: var(--accent-soft); }
.button.ghost { border-color: var(--line); background: transparent; }
.button.danger { color: var(--danger); border-color: #e6bbb4; background: var(--danger-soft); }
.button.full { width: 100%; margin-top: 25px; }
.button.text { min-height: 32px; padding: 0 8px; color: var(--accent); border: 0; background: none; }
.login-actions { display: grid; gap: 10px; }
.login-error { min-height: 22px; margin: 12px 0 0; color: var(--danger); font-size: 13px; }
.debug-login { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.debug-login .button { width: 100%; }

.app-shell { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: 242px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(24px, env(safe-area-inset-top)) 19px max(20px, env(safe-area-inset-bottom));
  border-right: 1px solid var(--line);
  background: rgb(250 249 245 / 80%);
  backdrop-filter: blur(22px);
}
.sidebar .brand-lockup { padding: 0 8px 24px; }
.nav { display: grid; gap: 5px; margin-top: 17px; }
.nav-button { display: flex; width: 100%; align-items: center; gap: 11px; min-height: 42px; padding: 0 12px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; cursor: pointer; font-weight: 700; text-align: left; }
.nav-button:hover { color: var(--ink); background: #eceae3; }
.nav-button.active { color: var(--accent-strong); background: var(--accent-soft); }
.nav-icon { width: 23px; color: currentColor; text-align: center; }
.sidebar-spacer { flex: 1; }
.sidebar-account { padding: 14px 10px 0; border-top: 1px solid var(--line); }
.sidebar-account strong, .sidebar-account span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-account strong { font-size: 13px; }
.sidebar-account span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.sidebar-account button { margin-top: 10px; }

.workspace { min-width: 0; padding: max(31px, env(safe-area-inset-top)) clamp(26px, 4.7vw, 72px) max(54px, env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 36px; }
.topbar h1 { margin: 3px 0 0; font: 500 clamp(30px, 4vw, 45px)/1 Georgia, serif; letter-spacing: -.035em; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.live-pill { display: inline-flex; align-items: center; gap: 8px; min-height: 34px; padding: 0 11px; border: 1px solid #bdd7ca; border-radius: 999px; color: var(--success); background: #edf7f1; font-size: 12px; font-weight: 750; }
.live-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 4px rgb(45 117 86 / 10%); }
.live-pill.warning { color: #8c531e; border-color: #e0c49e; background: #f8eddf; }
.live-pill.danger { color: var(--danger); border-color: #e3b8b1; background: var(--danger-soft); }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metric-card, .panel { border: 1px solid var(--line); border-radius: var(--radius); background: rgb(255 254 250 / 88%); box-shadow: 0 10px 35px rgb(30 39 39 / 4%); }
.metric-card { min-height: 139px; padding: 20px; }
.metric-label { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 700; }
.metric-icon { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 9px; color: var(--accent-strong); background: var(--accent-soft); }
.metric-value { display: block; margin-top: 22px; font: 500 clamp(25px, 3vw, 34px)/1 Georgia, serif; letter-spacing: -.025em; }
.metric-detail { display: block; margin-top: 8px; color: var(--muted); font-size: 11px; }

.content-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(280px, .75fr); gap: 16px; margin-top: 16px; }
.panel { min-width: 0; padding: 22px; }
.panel.flush { padding: 0; overflow: hidden; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.panel-header.flush-header { padding: 22px 22px 0; }
.panel-title { margin: 0; font: 500 21px/1.2 Georgia, serif; }
.panel-subtitle { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.progress-track { overflow: hidden; height: 10px; border-radius: 999px; background: #e8e5dd; }
.progress-bar { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), #3c8f7d); transition: width .35s ease; }
.progress-bar.warning { background: linear-gradient(90deg, var(--warm), #c96843); }
.quota-figures { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 17px 0 13px; }
.quota-figures strong { font: 500 31px/1 Georgia, serif; }
.quota-figures span { color: var(--muted); font-size: 12px; }
.session-dots { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 19px; }
.session-dot { width: 35px; height: 35px; border-radius: 11px; border: 1px dashed var(--line-strong); background: transparent; }
.session-dot.online { border-style: solid; border-color: #a5cdbd; background: var(--accent-soft); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 20px; border-top: 1px solid #ebe8e0; font-size: 12px; text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
tbody tr:hover { background: #fbfaf6; }
.identity { display: flex; align-items: center; gap: 10px; }
.avatar { display: grid; flex: 0 0 auto; width: 34px; height: 34px; place-items: center; border-radius: 11px; color: var(--accent-strong); background: var(--accent-soft); font-weight: 850; }
.identity strong, .identity small { display: block; }
.identity small { max-width: 210px; margin-top: 2px; overflow: hidden; color: var(--muted); text-overflow: ellipsis; }
.badge { display: inline-flex; min-height: 24px; align-items: center; padding: 0 8px; border-radius: 999px; font-size: 10px; font-weight: 800; }
.badge.active { color: var(--success); background: #e3f2e9; }
.badge.paused { color: var(--danger); background: var(--danger-soft); }
.badge.warning { color: #8c531e; background: #f6eadb; }
.row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.icon-button { display: grid; width: 34px; height: 34px; place-items: center; padding: 0; border: 1px solid transparent; border-radius: 9px; background: transparent; cursor: pointer; font-size: 20px; }
.icon-button:hover { border-color: var(--line); background: #f4f2ec; }
.empty-state { padding: 55px 20px; color: var(--muted); text-align: center; }

.account-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(280px, .7fr); gap: 16px; }
.stack { display: grid; gap: 16px; }
.device-list, .session-list, .audit-list { display: grid; gap: 0; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 66px; padding: 12px 0; border-top: 1px solid #ebe8e0; }
.list-row:first-child { border-top: 0; }
.list-row-main { min-width: 0; }
.list-row-main strong, .list-row-main span { display: block; }
.list-row-main strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.list-row-main span { margin-top: 4px; color: var(--muted); font-size: 11px; }
.policy-list { display: grid; gap: 14px; margin: 0; }
.policy-list div { display: flex; justify-content: space-between; gap: 24px; }
.policy-list dt { color: var(--muted); font-size: 12px; }
.policy-list dd { margin: 0; font-size: 12px; font-weight: 800; text-align: right; }

.dialog { width: min(660px, calc(100vw - 32px)); max-height: min(860px, calc(100dvh - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 22px; color: var(--ink); background: var(--surface); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgb(19 28 30 / 46%); backdrop-filter: blur(4px); }
.dialog form, .dialog section { padding: 25px; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 17px; }
.input-with-suffix { position: relative; }
.input-with-suffix input { padding-right: 52px; }
.input-with-suffix span { position: absolute; right: 13px; top: 15px; color: var(--muted); font-size: 12px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 25px; margin-top: 22px; padding: 15px; border: 1px solid var(--line); border-radius: 13px; }
.switch-row.secondary-switch { margin-top: 10px; }
.switch-row strong, .switch-row small { display: block; }
.switch-row strong { font-size: 13px; }
.switch-row small { margin-top: 4px; }
.switch-row input { width: 42px; height: 23px; accent-color: var(--accent); }
.admin-actions { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 18px; padding: 15px; border: 1px dashed var(--line-strong); border-radius: 13px; }
.admin-actions strong, .admin-actions small { display: block; }
.admin-actions strong { font-size: 13px; }
.admin-actions small { margin-top: 4px; color: var(--muted); font-size: 11px; }
.admin-action-buttons { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 25px; }
.secret-box { display: flex; align-items: center; gap: 10px; margin: 18px 0; padding: 12px; border: 1px solid #acd0c5; border-radius: 12px; background: var(--accent-soft); }
.secret-box code { min-width: 0; flex: 1; overflow-wrap: anywhere; font-size: 12px; }
details { margin-top: 16px; }
summary { cursor: pointer; color: var(--accent); font-size: 12px; font-weight: 750; }
pre { max-height: 270px; overflow: auto; padding: 14px; border-radius: 10px; color: #e9f2ef; background: #17312f; font-size: 11px; line-height: 1.5; white-space: pre-wrap; }

.toast-region { position: fixed; z-index: 30; right: max(20px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); display: grid; gap: 8px; width: min(370px, calc(100vw - 40px)); pointer-events: none; }
.toast { padding: 13px 15px; border: 1px solid #cad6d0; border-radius: 11px; color: #f8fbfa; background: #1c3734; box-shadow: 0 13px 35px rgb(20 31 33 / 22%); font-size: 12px; animation: toast-in .18s ease-out; }
.toast.error { border-color: #8e4a43; background: #763a34; }
@keyframes toast-in { from { opacity: 0; transform: translateY(7px); } }
.hidden, [hidden] { display: none !important; }
.mobile-menu { display: none; }

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .content-grid, .account-grid { grid-template-columns: 1fr; }
}

@media (max-width: 780px) {
  .login-shell { padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left)); }
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 20; left: 0; width: min(280px, 86vw); transform: translateX(-105%); box-shadow: var(--shadow); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .workspace { padding: max(21px, env(safe-area-inset-top)) 18px max(42px, env(safe-area-inset-bottom)); }
  .mobile-menu { display: grid; }
  .topbar { align-items: flex-start; margin-bottom: 26px; }
  .topbar-actions .live-pill { display: none; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric-card { min-height: 126px; padding: 16px; }
  .panel { padding: 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .admin-actions { align-items: stretch; flex-direction: column; }
  .admin-action-buttons { justify-content: flex-start; }
}

@media (max-width: 470px) {
  .metric-grid { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 32px; }
  .topbar-actions > .button { min-width: 0; padding: 0 11px; }
  .dialog form, .dialog section { padding: 20px; }
  .secret-box { align-items: stretch; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
