/* ============================================================================
   KR CONSULTING PORTAL — SHELL
   App frame, top bar, nav, user menu, buttons, inputs, modals, toasts,
   skeletons, empty/error states, context menus, login + 2FA.
   Consumes ONLY tokens from tokens.css.
   ========================================================================= */

/* ============================ APP FRAME ================================== */
/* Stacking order, one place:
   topbar 40 · botnav 60 · drawer-scrim 70 · sidebar 80 · menu 110
   · login 200 · modal scrim 250 · toasts 300
   Modals and toasts must outrank the login overlay — both are used there. */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "topbar topbar"
    "side   view";
  min-height: 100dvh;
  min-height: 100vh;
}
@supports (min-height: 100dvh) { .app { min-height: 100dvh; } }

.app[hidden] { display: none; }

/* ---------------------------- TOP BAR ------------------------------------ */
.topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(var(--sp-4), env(safe-area-inset-right))
           0 max(var(--sp-4), env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  border-bottom: 1px solid var(--border);
}
@supports (backdrop-filter: blur(1px)) {
  .topbar { backdrop-filter: blur(16px) saturate(1.1); }
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-1);
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
  flex: 0 0 auto;
}
.brand .logo { width: 48px; height: 26px; }
.brand-word { display: flex; align-items: baseline; gap: 6px; line-height: 1; }
.brand-kr { font-size: 15px; font-weight: 650; letter-spacing: .01em; color: var(--text); }
.brand-sub { font-size: 11px; font-weight: 600; letter-spacing: .08em;
             text-transform: uppercase; color: var(--text-mute); }

/* nav pills (desktop, in top bar) */
.nav {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  margin-left: var(--sp-4);
}
.nav-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  height: 36px;
  padding: 0 var(--sp-3);
  border-radius: var(--radius-pill);
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: .01em;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease);
}
.nav-link:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); color: var(--text); }
.nav-link[aria-current="page"] {
  background: var(--accent-dim);
  color: var(--accent-hi);
}
.nav-link[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 6px; top: 50%;
  width: 3px; height: 16px;
  margin-top: -8px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  transform-origin: center;
  animation: pill-bar var(--dur-fast) var(--ease) both;
}
@keyframes pill-bar { from { transform: scaleY(.3); opacity: 0; } to { transform: none; opacity: 1; } }
.nav-link[aria-current="page"] { padding-left: var(--sp-4); }

/* user menu trigger */
.user-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  height: 36px;
  padding: 0 var(--sp-2) 0 var(--sp-1);
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.user-btn:hover { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.user-btn[aria-expanded="true"] { background: var(--surface-2); border-color: var(--border-hi); }
.avatar {
  display: grid;
  place-items: center;
  width: 28px; height: 28px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--on-accent);
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: .02em;
}
.user-name { font-size: 13.5px; font-weight: 500; max-width: 140px;
             overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------- SIDEBAR ------------------------------------ */
.sidebar {
  grid-area: side;
  position: sticky;
  top: calc(var(--topbar-h) + env(safe-area-inset-top));
  align-self: start;
  height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-top));
  overflow-y: auto;
  padding: var(--sp-5) var(--sp-3)
           calc(var(--sp-8) + env(safe-area-inset-bottom));
  border-right: 1px solid var(--border);
  background: var(--bg);
}
.sidebar .t-over { padding: 0 var(--sp-3) var(--sp-2); display: block; }
.side-section + .side-section { margin-top: var(--sp-6); }

/* ---------------------------- VIEW --------------------------------------- */
.view {
  grid-area: view;
  min-width: 0;
  position: relative;
  padding-bottom: calc(var(--sp-8) + env(safe-area-inset-bottom));
}
.view-inner {
  padding: var(--sp-6) max(var(--gutter), env(safe-area-inset-right))
           0 max(var(--gutter), env(safe-area-inset-left));
}

.view-swap { animation: view-in var(--dur) var(--ease) both; }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* mobile bottom nav — hidden on desktop */
.botnav { display: none; }

/* ============================ BUTTONS ==================================== */
.btn {
  --btn-bg: transparent;
  --btn-fg: var(--text);
  --btn-bd: var(--border-hi);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 36px;
  padding: 0 var(--sp-4);
  border: 1px solid var(--btn-bd);
  border-radius: var(--radius);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: .01em;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease),
              transform var(--dur-press) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
}
.btn:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.btn:active { transform: scale(.972); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn:disabled:hover { background: var(--btn-bg); }

.btn-primary {
  --btn-bg: var(--accent);
  --btn-fg: var(--on-accent);
  --btn-bd: var(--accent);
}
.btn-primary:hover { background: var(--accent-hi); border-color: var(--accent-hi); }
.btn-primary:active { transform: scale(.972) translateY(.5px); }

.btn-danger {
  --btn-bg: var(--danger);
  --btn-fg: #FFFFFF;
  --btn-bd: var(--danger);
}
:root[data-theme="dark"] .btn-danger { --btn-fg: #180D04; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-danger { --btn-fg: #180D04; } }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 86%, #000); border-color: transparent; }

.btn-ghost {
  --btn-bd: transparent;
  --btn-fg: var(--text-dim);
}
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }

.btn-quiet {
  --btn-bd: var(--border);
  --btn-fg: var(--text-dim);
  background: var(--surface);
}
.btn-quiet:hover { border-color: var(--border-hi); color: var(--text);
                   background: color-mix(in srgb, var(--accent) 5%, var(--surface)); }

.btn-sm { height: 30px; padding: 0 var(--sp-3); font-size: 12.5px; }
.btn-lg { height: 44px; padding: 0 var(--sp-5); font-size: 14.5px; }
.btn-block { width: 100%; }

/* icon-only: visual box stays small, hit area grows via ::after expander */
.btn-icon {
  position: relative;
  width: 36px;
  height: 36px;
  padding: 0;
  border-color: transparent;
  color: var(--text-dim);
  border-radius: var(--radius);
}
.btn-icon:hover { color: var(--text); background: var(--surface-2); }
.btn-icon::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 36px; height: 36px;
  transform: translate(-50%, -50%);
}
@media (max-width: 768px) {
  .btn-icon::after { width: 44px; height: 44px; }
}

/* text-only link button */
.btn-link {
  display: inline-flex; align-items: center; gap: var(--sp-1-5);
  padding: 0; height: auto; border: 0; background: none;
  color: var(--accent-text); font-size: 13px; font-weight: 600; cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color var(--dur-fast) var(--ease);
}
.btn-link:hover { color: var(--accent-hi); text-decoration: underline; }

/* segmented control */
.seg {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  border: 1px solid var(--border-hi);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.seg > button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-1-5);
  height: 28px; padding: 0 var(--sp-2-5, 10px);
  border-radius: calc(var(--radius) - 3px);
  color: var(--text-mute); font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.seg > button:hover { color: var(--text); }
.seg > button[aria-pressed="true"] { background: var(--surface); color: var(--accent-hi); box-shadow: var(--shadow-1); }

/* ============================ INPUTS ===================================== */
.field { display: flex; flex-direction: column; gap: var(--sp-1-5); }
.field > label { display: block; }

.input, input[type="text"], input[type="password"], input[type="search"],
input[type="email"], input[type="date"], textarea, select {
  width: 100%;
  min-height: 40px;
  padding: 9px var(--sp-3);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 14.5px;
  font-weight: 400;
  line-height: 1.4;
  transition: border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease),
              background var(--dur-fast) var(--ease);
  -webkit-appearance: none;
  appearance: none;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
select {
  padding-right: var(--sp-8);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.input:focus, input:focus, textarea:focus, select:focus { outline: none; }
.input:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 4px var(--accent-soft);
}
/* keyboard-less focus (e.g. programmatic) still shows the accent edge */
.input:focus, input:focus, textarea:focus { border-color: var(--accent); }

.input::placeholder, input::placeholder, textarea::placeholder { color: var(--text-mute); opacity: 1; }

.input[aria-invalid="true"], input[aria-invalid="true"], textarea[aria-invalid="true"] {
  border-color: var(--danger);
}
.input[aria-invalid="true"]:focus-visible { box-shadow: 0 0 0 4px var(--danger-soft); }

/* iOS: 16px prevents focus zoom. Mandatory. */
@media (max-width: 640px) {
  .input, input[type="text"], input[type="password"], input[type="search"],
  input[type="email"], input[type="date"], textarea, select { font-size: 16px; }
}

/* input with trailing affix (eye toggle) */
.input-wrap { position: relative; display: block; }
.input-wrap > .input,
.input-wrap > input { padding-right: 44px; }
.input-affix {
  position: absolute;
  top: 50%; right: 4px;
  transform: translateY(-50%);
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  color: var(--text-mute);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.input-affix:hover { color: var(--text); background: var(--surface-2); }
.input-affix::after {
  content: ""; position: absolute; inset: 50% auto auto 50%;
  width: 44px; height: 44px; transform: translate(-50%, -50%);
}

.field-err {
  display: flex; align-items: center; gap: var(--sp-1);
  font-size: 12.5px; font-weight: 500; color: var(--danger);
  animation: err-in var(--dur-fast) var(--ease) both;
}
@keyframes err-in { from { opacity: 0; transform: translateY(-2px); } to { opacity: 1; transform: none; } }

/* checkbox */
.check { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; }
.check input[type="checkbox"] {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; margin: 0;
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-sm);
  background: var(--surface);
  display: grid; place-items: center;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.check input[type="checkbox"]::after {
  content: "";
  width: 10px; height: 10px;
  clip-path: polygon(14% 46%, 0 60%, 40% 100%, 100% 22%, 86% 8%, 38% 70%);
  background: var(--on-accent);
  transform: scale(0);
  transition: transform var(--dur-fast) var(--ease-spring);
}
.check input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.check input[type="checkbox"]:checked::after { transform: scale(1); }

/* ============================ STRIPS / ALERTS ============================ */
.strip {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: 10px var(--sp-3);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  animation: strip-in var(--dur) var(--ease) both;
}
@keyframes strip-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.strip .ico { margin-top: 1px; }
.strip-err  { background: var(--danger-soft); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }
.strip-warn { background: color-mix(in srgb, var(--warn) 10%, transparent);
              border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); color: var(--warn); }
.strip-ok   { background: var(--ok-soft); border: 1px solid color-mix(in srgb, var(--ok) 40%, transparent); color: var(--ok); }
.strip-info { background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim); }

/* reduced-motion substitute for the shake: a single tint flash */
@keyframes strip-flash {
  0%   { background: var(--danger-soft); }
  50%  { background: transparent; }
  100% { background: var(--danger-soft); }
}

/* ============================ THEME SWAP ================================= */
/* Colour transitions ONLY for the 300ms after the toggle. A permanent global
   colour transition makes every hover state feel laggy. app.js adds/removes
   .theming on <html>. */
:root.theming, :root.theming body, :root.theming *:not(.ico):not(.ico *) {
  transition: background-color var(--dur) var(--ease),
              color var(--dur) var(--ease),
              border-color var(--dur) var(--ease) !important;
}
#theme-toggle .ico, #login-theme .ico { animation: theme-swap var(--dur) var(--ease) both; }
@keyframes theme-swap {
  from { opacity: 0; transform: rotate(-90deg) scale(.82); }
  to   { opacity: 1; transform: none; }
}

/* ============================ CARDS ====================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1), inset 0 1px 0 var(--hairline);
}

/* ============================ MODALS ===================================== */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: grid;
  place-items: center;
  padding: max(var(--sp-4), env(safe-area-inset-top)) max(var(--sp-4), env(safe-area-inset-right))
           max(var(--sp-4), env(safe-area-inset-bottom)) max(var(--sp-4), env(safe-area-inset-left));
  background: var(--scrim);
  animation: fade var(--dur-fast) var(--ease) both;
}
@supports (backdrop-filter: blur(1px)) { .scrim { backdrop-filter: blur(3px); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.scrim.is-closing { animation: fade var(--dur-fast) var(--ease-in) reverse both; }

.modal {
  width: min(440px, 100%);
  max-height: calc(100dvh - 2 * var(--sp-8));
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2), inset 0 1px 0 var(--hairline);
  animation: modal-in var(--dur) var(--ease-spring) both;
  overflow: hidden;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
.scrim.is-closing .modal {
  animation: modal-out var(--dur-fast) var(--ease-in) both;
}
@keyframes modal-out {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateY(6px) scale(.985); }
}

.modal-head {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-5) var(--sp-3);
}
.modal-head .ico-badge {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  flex: 0 0 auto;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-dim);
}
.modal-head .ico-badge.tone-danger { background: var(--danger-soft); color: var(--danger); }
.modal-head .ico-badge.tone-accent { background: var(--accent-dim); color: var(--accent-hi); }
.modal-title { font-size: 17px; font-weight: 600; line-height: 1.3; letter-spacing: -.01em; }
.modal-body {
  padding: 0 var(--sp-5) var(--sp-5);
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-dim);
}
.modal-body .field { margin-top: var(--sp-4); }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5) var(--sp-5);
  border-top: 1px solid var(--border);
  padding-top: var(--sp-4);
  background: var(--bg-elev);
}
@media (max-width: 480px) {
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; height: 44px; }
}

/* ============================ TOASTS ===================================== */
.toasts {
  position: fixed;
  z-index: 300;
  right: max(var(--sp-5), env(safe-area-inset-right));
  bottom: max(var(--sp-5), env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  width: min(360px, calc(100vw - 2 * var(--sp-4)));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2-5, 10px);
  padding: 11px var(--sp-3);
  border-radius: var(--radius);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-2), inset 0 1px 0 var(--hairline);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.4;
  animation: toast-in 220ms var(--ease-spring) both;
  overflow: hidden;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px) scale(.96); }
  to   { opacity: 1; transform: none; }
}
.toast.is-closing { animation: toast-out 140ms var(--ease-in) both; }
@keyframes toast-out {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateY(6px); }
}
.toast::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--tone, var(--accent));
}
.toast { position: relative; padding-left: calc(var(--sp-3) + 3px); }
.toast .ico { color: var(--tone, var(--accent)); margin-top: 1px; }
.toast-ok   { --tone: var(--ok); }
.toast-err  { --tone: var(--danger); }
.toast-info { --tone: var(--accent); }
.toast-msg { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.toast-x {
  flex: 0 0 auto; width: 22px; height: 22px; display: grid; place-items: center;
  border-radius: var(--radius-sm); color: var(--text-mute); cursor: pointer;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.toast-x:hover { color: var(--text); background: var(--surface-2); }

@media (max-width: 640px) {
  .toasts {
    left: max(var(--sp-4), env(safe-area-inset-left));
    right: max(var(--sp-4), env(safe-area-inset-right));
    bottom: calc(var(--botnav-h, 0px) + max(var(--sp-4), env(safe-area-inset-bottom)));
    width: auto;
  }
}

/* ============================ CONTEXT MENU =============================== */
.menu {
  position: fixed;
  z-index: 110;
  min-width: 208px;
  max-width: 300px;
  padding: var(--sp-1);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1), inset 0 1px 0 var(--hairline);
  animation: menu-in var(--dur-fast) var(--ease) both;
  transform-origin: var(--mo-x, 0) var(--mo-y, 0);
}
@keyframes menu-in {
  from { opacity: 0; transform: translateY(-4px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
.menu.is-closing { animation: menu-in var(--dur-fast) var(--ease-in) reverse both; }
.menu-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2-5, 10px);
  width: 100%;
  min-height: 34px;
  padding: 0 var(--sp-3);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.menu-item .ico { color: var(--text-mute); }
.menu-item:hover, .menu-item:focus-visible {
  background: color-mix(in srgb, var(--accent) 9%, transparent);
  color: var(--accent-hi);
}
.menu-item:hover .ico, .menu-item:focus-visible .ico { color: var(--accent-hi); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-soft); color: var(--danger); }
.menu-item.danger .ico { color: currentColor; }
.menu-item:disabled { opacity: .45; cursor: not-allowed; }
.menu-item:disabled:hover { background: none; color: var(--text); }
.menu-kbd { margin-left: auto; font-family: var(--font-mono); font-size: 11.5px; color: var(--text-mute); }
.menu-sep { height: 1px; margin: var(--sp-1) var(--sp-2); background: var(--border); }
.menu-label { padding: var(--sp-2) var(--sp-3) var(--sp-1); }

@media (max-width: 768px) {
  .menu-item { min-height: 44px; font-size: 15px; }
}

/* ============================ SKELETON =================================== */
.skeleton {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  background-image: linear-gradient(90deg,
      transparent 0%,
      color-mix(in srgb, var(--text) 6%, transparent) 50%,
      transparent 100%);
  background-size: 240% 100%;
  background-repeat: no-repeat;
  animation: skel 1350ms linear infinite;
}
@keyframes skel {
  from { background-position: -140% 0; }
  to   { background-position: 240% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton { background-image: none; animation: none; }
}
.skel-list { display: flex; flex-direction: column; gap: var(--sp-1); }
.skel-row { display: flex; align-items: center; gap: var(--sp-3); height: var(--row-h); padding: 0 var(--sp-3); }
.skel-row .sk-ico { width: 20px; height: 20px; border-radius: var(--radius-sm); flex: 0 0 auto; }
.skel-row .sk-name { height: 11px; border-radius: var(--radius-pill); }
.skel-row .sk-meta { width: 68px; height: 10px; border-radius: var(--radius-pill); flex: 0 0 auto; margin-left: auto; }

/* ============================ EMPTY / ERROR STATES ======================= */
.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--sp-3);
  padding: var(--sp-16) var(--sp-5);
  animation: view-in var(--dur) var(--ease) both;
}
.state-ico {
  display: grid; place-items: center;
  width: 56px; height: 56px;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  color: var(--text-mute);
  border: 1px solid var(--border);
}
.state.tone-err .state-ico { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.state-title { font-size: 17px; font-weight: 600; letter-spacing: -.01em; color: var(--text); }
.state-text { font-size: 13.5px; color: var(--text-mute); max-width: 42ch; line-height: 1.55; }
.state-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-2); flex-wrap: wrap; justify-content: center; }

/* ============================ SPINNER ==================================== */
.spinner { display: inline-block; }
.spinner .ico { animation: spin 700ms linear infinite; transform-origin: 50% 50%; }

/* progress bar (shared base; files.js may extend) */
.bar {
  position: relative;
  height: 3px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  overflow: hidden;
}
.bar-fill {
  position: absolute; inset: 0;
  transform-origin: left;
  transform: scaleX(0);
  background: var(--accent);
  border-radius: inherit;
  transition: transform var(--dur-fast) linear;
}
.bar-fill.is-ok { background: var(--ok); }
.bar-fill.is-err { background: var(--danger); }
.bar.is-indeterminate .bar-fill { display: none; }
.bar.is-indeterminate::after {
  content: "";
  position: absolute; top: 0; bottom: 0; left: 0;
  width: 28%;
  border-radius: inherit;
  background: var(--accent);
  animation: bar-slide 1100ms linear infinite;
}
@keyframes bar-slide { from { transform: translateX(0); } to { transform: translateX(360%); } }
@media (prefers-reduced-motion: reduce) {
  .bar.is-indeterminate::after { animation: none; width: 40%; }
}

/* ============================ CSP-SAFE UTILITIES ========================= */
/* The server sends `style-src 'self'` with NO 'unsafe-inline', so literal
   style="…" attributes in markup are dropped by the browser. Everything that
   would have been an inline style is a class here instead. (Assignments made
   through the CSSOM — element.style.x = … — are NOT restricted by CSP, so
   genuinely dynamic values such as menu coordinates still use JS.) */
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.boot-splash {
  position: fixed;
  inset: 0;
  z-index: 320;
  display: grid;
  place-items: center;
  background: var(--bg);
  color: var(--text-mute);
}

.noscript-note { padding: var(--sp-8); text-align: center; color: var(--text); }

.text-center { text-align: center; }
.mt-1 { margin-top: var(--sp-1); }
.mt-1-5 { margin-top: var(--sp-1-5); }
.mt-2 { margin-top: var(--sp-2); }
.mt-5 { margin-top: var(--sp-5); }
.mt-8 { margin-top: var(--sp-8); }
.mt-hair { margin-top: 2px; }

/* stagger indices for the login panel children (§5.1) */
.s0 { --s: 0; } .s1 { --s: 1; } .s2 { --s: 2; }
.s3 { --s: 3; } .s4 { --s: 4; } .s5 { --s: 5; }

/* sidebar */
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav .nav-link { justify-content: flex-start; }
.side-kbd {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--sp-1-5) var(--sp-3);
  margin-top: var(--sp-2);
  padding: 0 var(--sp-3);
}
.side-kbd dt { color: var(--text-mute); }
.side-kbd dd { margin: 0; }

/* skeleton row widths, varied without inline styles */
.skel-row:nth-child(6n+1) .sk-name { width: 46%; }
.skel-row:nth-child(6n+2) .sk-name { width: 68%; }
.skel-row:nth-child(6n+3) .sk-name { width: 34%; }
.skel-row:nth-child(6n+4) .sk-name { width: 58%; }
.skel-row:nth-child(6n+5) .sk-name { width: 41%; }
.skel-row:nth-child(6n+6) .sk-name { width: 62%; }

/* login: secret well + hint spacing */
.enroll-manual .secret-well { margin-top: var(--sp-1-5); }
.strip .hint { display: block; margin-top: var(--sp-1); }

/* ============================ DIVIDER / MISC ============================= */
.hr { height: 1px; background: var(--border); border: 0; margin: var(--sp-4) 0; }
.chip {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  height: 22px; padding: 0 var(--sp-2);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 11.5px; font-weight: 600; letter-spacing: .02em;
}

/* ========================================================================= */
/*                         LOGIN + 2FA SCREEN                                */
/* ========================================================================= */
.login {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: max(var(--sp-6), env(safe-area-inset-top)) max(var(--sp-6), env(safe-area-inset-right))
           max(var(--sp-6), env(safe-area-inset-bottom)) max(var(--sp-6), env(safe-area-inset-left));

  background-color: var(--bg);
  background-image:
    /* 3. moving specular sheen */
    radial-gradient(120% 80% at var(--gx, 30%) var(--gy, 18%),
        color-mix(in srgb, var(--accent) 14%, transparent) 0%, transparent 60%),
    /* 2. technical-drawing grid lives in ::before — a single element cannot
          mask one background layer independently of the others */
    /* 1. brushed-metal micro-striation, 3px pitch */
    repeating-linear-gradient(103deg, rgba(127,140,148,.055) 0 1px, transparent 1px 3px),
    /* 0. vertical plate falloff */
    linear-gradient(178deg,
        color-mix(in srgb, var(--bg-elev) 70%, var(--bg)) 0%,
        var(--bg) 46%,
        color-mix(in srgb, var(--surface-2) 60%, var(--bg)) 100%);
  animation: sheen-drift 24s var(--ease) infinite alternate;
}
@keyframes sheen-drift {
  from { --gx: 22%; --gy: 12%; }
  to   { --gx: 64%; --gy: 30%; }
}
/* edge-fade the grid layers only */
.login::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(0deg,  var(--grid) 0 1px, transparent 1px 32px),
    repeating-linear-gradient(90deg, var(--grid) 0 1px, transparent 1px 32px);
  -webkit-mask-image: radial-gradient(110% 90% at 50% 40%, #000 40%, transparent 100%);
  mask-image: radial-gradient(110% 90% at 50% 40%, #000 40%, transparent 100%);
}

/* registration mark — drawing-sheet fiducial */
.login-mark {
  position: absolute;
  top: var(--sp-8);
  left: var(--sp-8);
  width: 88px; height: 88px;
  color: var(--border);
  opacity: .5;
  pointer-events: none;
}
@media (max-width: 900px) { .login-mark { display: none; } }

.login-stack {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-5);
  width: min(400px, 100%);
}

.login-panel {
  width: 100%;
  padding: var(--sp-8) var(--sp-8) var(--sp-6);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2), inset 0 1px 0 var(--hairline);
  animation: panel-in 280ms var(--ease-spring) both;
}
@supports (backdrop-filter: blur(1px)) {
  .login-panel {
    background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
    backdrop-filter: blur(18px) saturate(1.15);
  }
}
@keyframes panel-in {
  from { opacity: 0; transform: translateY(12px) scale(.985); }
  to   { opacity: 1; transform: none; }
}
.login-panel.is-shaking { animation: shake 220ms var(--ease) both; }
@keyframes shake {
  0%   { transform: translateX(0); }
  15%  { transform: translateX(-6px); }
  30%  { transform: translateX(5px); }
  45%  { transform: translateX(-4px); }
  60%  { transform: translateX(3px); }
  80%  { transform: translateX(-2px); }
  100% { transform: translateX(0); }
}
@media (prefers-reduced-motion: reduce) {
  .login-panel.is-shaking { animation: none; }
  .login-panel.is-shaking .strip-err { animation: strip-flash 300ms linear 1 both; }
}

/* staggered children on first paint */
.login-panel .stg { animation: stg-in 160ms var(--ease) both; animation-delay: calc(var(--s, 0) * 40ms); }
@keyframes stg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.login-head { display: flex; flex-direction: column; gap: var(--sp-1); margin-bottom: var(--sp-5); }
.login-head .logo { width: 74px; height: 40px; margin-bottom: var(--sp-3); }
.login-title { font-size: 26px; font-weight: 650; line-height: 1.2; letter-spacing: -.02em; color: var(--text); }
.login-sub { font-size: 12.5px; color: var(--text-mute); }

.login-rule { height: 1px; background: var(--border); border: 0; margin: var(--sp-5) 0; }

.login-form { display: flex; flex-direction: column; gap: var(--sp-4); }
.login-form .input,
.login-form input[type="text"],
.login-form input[type="password"] { min-height: 44px; }
.login-form .btn-primary { height: 46px; font-size: 14.5px; }

.login-foot {
  display: flex; align-items: center; gap: var(--sp-2);
  margin-top: var(--sp-5);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border);
  color: var(--text-mute);
  font-size: 12.5px;
}

.login-below {
  display: flex; align-items: center; gap: var(--sp-3);
  color: var(--text-mute); font-size: 12.5px;
  animation: stg-in 200ms var(--ease) 240ms both;
}

/* --- step morph: old slides out left, new slides in from right ----------- */
.login-steps { display: grid; grid-template-rows: 1fr; transition: none; }
.step-exit  { animation: step-out 120ms var(--ease-in) both; }
.step-enter { animation: step-in 200ms var(--ease) 90ms both; }
@keyframes step-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateX(-14px); } }
@keyframes step-in  { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }

/* --- OTP group ----------------------------------------------------------- */
.otp {
  display: flex;
  gap: var(--sp-2);
  justify-content: center;
  scroll-margin-block: 96px;
}
/* 12px between box 3 and box 4 (visual grouping, like a serial number).
   Two 8px flex gaps straddle the spacer, so it pulls 4px back: 8-2+0-2+8 = 12. */
.otp .otp-gap { width: 0; margin: 0 -2px; flex: 0 0 auto; }
.otp input {
  width: 48px;
  height: 58px;
  padding: 0;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius);
  caret-color: var(--accent);
  transition: border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease);
}
.otp input:focus, .otp input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
  transform: translateY(-1px);
}
.otp .otp-cell { position: relative; display: flex; flex: 0 0 auto; }
/* empty-state baseline tick */
.otp .otp-cell::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 10px; height: 2px;
  margin: -1px 0 0 -5px;
  border-radius: 1px;
  background: var(--border-hi);
  opacity: 1;
  transition: opacity var(--dur-fast) var(--ease);
  pointer-events: none;
}
.otp .otp-cell.is-filled::after { opacity: 0; }
.otp input.just-filled { animation: digit-in 90ms var(--ease-spring) both; }
@keyframes digit-in { from { opacity: 0; transform: scale(.82); } to { opacity: 1; transform: none; } }

.otp.is-error input { border-color: var(--danger); color: var(--danger); }
.otp.is-shaking { animation: shake 220ms var(--ease) both; }
.otp.is-busy { opacity: .7; }

@media (max-width: 400px) {
  .otp { gap: 6px; }
  .otp input { width: 44px; height: 54px; font-size: 23px; }
  .otp .otp-gap { margin: 0; }   /* 6 + 0 + 6 = 12 */
}

.countdown { font-variant-numeric: tabular-nums; }
.countdown.is-warn { color: var(--warn); }
.countdown.is-danger { color: var(--danger); }

/* --- enrolment (QR) ------------------------------------------------------ */
.enroll { display: flex; flex-direction: column; gap: var(--sp-4); }
.enroll-cols { display: flex; flex-direction: column; gap: var(--sp-4); }
@media (min-width: 560px) {
  .enroll-cols { flex-direction: row; align-items: flex-start; gap: var(--sp-5); }
  .enroll-qr { flex: 0 0 auto; }
  .enroll-manual { flex: 1 1 auto; min-width: 0; }
}
/* HARDCODED #FFFFFF IN BOTH THEMES ON PURPOSE:
   a QR rendered on a dark ground fails to scan on a large number of phone
   cameras. This is the one sanctioned literal colour in the application. */
.enroll-qr {
  padding: 12px;
  background: #FFFFFF;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  line-height: 0;
}
.enroll-qr img { width: 176px; height: 176px; image-rendering: pixelated; }

.secret-well {
  padding: var(--sp-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 450;
  letter-spacing: .04em;
  color: var(--text);
  word-break: break-all;
  user-select: all;
  -webkit-user-select: all;
}
.enroll-steps { margin: 0; padding-left: 1.25em; display: flex; flex-direction: column; gap: var(--sp-1); }
.enroll-steps li { font-size: 12.5px; color: var(--text-mute); line-height: 1.45; }
.enroll-steps li::marker { color: var(--accent-text); font-weight: 600; }

/* ≤480px: keep the panel above the mobile keyboard */
@media (max-width: 480px) {
  .login { align-items: start; padding-top: 8vh; }
  .login-panel { padding: var(--sp-6) var(--sp-5); }
  .login-stack { width: 100%; }
}

/* ========================================================================= */
/*                    RESPONSIVE: TABLET / PHONE SHELL                       */
/* ========================================================================= */

/* sidebar collapses into an overlay drawer below 900px */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "view";
  }
  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 80;
    width: min(var(--sidebar-w), 84vw);
    height: 100dvh;
    padding-top: calc(var(--sp-5) + env(safe-area-inset-top));
    background: var(--bg-elev);
    box-shadow: var(--shadow-2);
    transform: translateX(-100%);
    transition: transform var(--dur) var(--ease-out);
    visibility: hidden;
  }
  .app.drawer-open .sidebar { transform: none; visibility: visible; }
  .drawer-scrim {
    position: fixed; inset: 0; z-index: 70;
    background: var(--scrim);
    animation: fade var(--dur-fast) var(--ease) both;
  }
  .nav { display: none; }                 /* moves to the bottom bar */
  .menu-toggle { display: inline-flex; }
}
@media (min-width: 901px) {
  .menu-toggle { display: none; }
  .drawer-scrim { display: none; }
}

/* phone: bottom nav bar with safe-area padding and 44px+ targets */
@media (max-width: 640px) {
  :root { --topbar-h: 52px; --gutter: var(--sp-4); --row-h: 48px; --botnav-h: 58px; }

  .view { padding-bottom: calc(var(--botnav-h) + env(safe-area-inset-bottom) + var(--sp-4)); }
  .view-inner { padding-top: var(--sp-4); }

  .brand-word { display: none; }

  .botnav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 60;
    display: flex;
    align-items: stretch;
    height: calc(var(--botnav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
    border-top: 1px solid var(--border);
  }
  @supports (backdrop-filter: blur(1px)) {
    .botnav { backdrop-filter: blur(16px) saturate(1.1); }
  }
  .botnav a, .botnav button {
    flex: 1 1 0;
    min-height: 44px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--text-mute);
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .02em;
    text-decoration: none;
    cursor: pointer;
    transition: color var(--dur-fast) var(--ease);
  }
  .botnav a:active { transform: scale(.97); }
  .botnav a[aria-current="page"] { color: var(--accent-text); }
  .botnav a[aria-current="page"] .ico { transform: translateY(-1px); }

  .user-name { display: none; }

  /* touch targets */
  .btn { height: 40px; }
  .btn-lg { height: 46px; }
}

/* honour reduced motion for the login sheen + drawer */
@media (prefers-reduced-motion: reduce) {
  .login { animation: none; --gx: 30%; --gy: 18%; }
  .sidebar { transition: none; }
}
