:root {
  color-scheme: light;
  --bg: #ffffff;
  --paper: #ffffff;
  --card: #ffffff;
  --card-soft: #fafafa;
  --ink: #2f2c35;
  --ink-strong: #17151c;
  --muted: #6f6a75;
  --line: #e6e6e9;
  --soft-line: #f2f2f3;
  --accent: #e72787;
  --accent-dark: #bd1b6a;
  --accent-soft: #fdf2f8;
  --danger: #b91c1c;
  --danger-soft: #fff1f2;
  --shadow: 0 0 2px rgb(0 0 0 / 12%), 0 2px 4px rgb(0 0 0 / 14%);
  --shadow-soft: 0 0 2px rgb(0 0 0 / 10%), 0 1px 3px rgb(0 0 0 / 12%);
  --drawer-shadow: 0 4px 6px -1px rgb(0 0 0 / 10%), 0 2px 4px -2px rgb(0 0 0 / 10%);
  --sidebar-width: 240px;
  --radius: 8px;
  --control-radius: 4px;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 1rem; line-height: 1.5; text-rendering: optimizeLegibility; }
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent-dark); }
p { margin: 0 0 14px; }
h1, h2, h3 { color: var(--ink-strong); line-height: 1.2; text-wrap: balance; }
h1, h2 { margin: 0; }
h1 { font-size: 24px; font-weight: 600; }
h2 { font-size: 20px; font-weight: 700; }
code { padding: 2px 6px; border: 1px solid var(--line); border-radius: var(--control-radius); background: #f5f5f6; color: #3a3640; }

.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 80; padding: .65rem 1rem; background: var(--ink-strong); color: white; }
.skip-link:focus { top: 1rem; }
.app-shell { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100dvh; transition: grid-template-columns .18s ease; }
.sidebar { position: sticky; top: 0; z-index: 30; display: flex; height: 100dvh; flex-direction: column; overflow: auto; background: var(--paper); box-shadow: var(--drawer-shadow); transition: opacity .18s ease, transform .18s ease; }
.brand-block { display: flex; min-height: 64px; align-items: center; padding: 8px 16px; }
.brand-row { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 8px; }
.brand-lockup { display: flex; min-width: 0; align-items: center; gap: 10px; }
.brand-mark { display: grid; width: 36px; height: 36px; flex: 0 0 auto; place-items: center; border-radius: var(--control-radius); background: var(--accent); color: white; font-size: 13px; font-weight: 800; }
.brand { display: block; color: var(--ink-strong); font-size: 16px; font-weight: 700; line-height: 1.1; white-space: nowrap; }
.brand:hover { color: var(--ink-strong); }
.brand-sub { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; font-weight: 600; white-space: nowrap; }
.nav { display: flex; flex-direction: column; padding: 8px 0; }
.nav-section { margin: 14px 12px 6px; color: #8b8791; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.nav-link { display: flex; min-height: 36px; align-items: center; gap: 10px; padding: 6px 12px 6px 8px; border-radius: var(--control-radius); color: var(--ink); font-size: 14px; transition: background-color .14s ease, color .14s ease; }
.nav-link:hover { background: #f3f3f5; color: var(--ink-strong); }
.nav-link.active { background: #f3f3f5; color: var(--ink-strong); font-weight: 600; }
.nav-link.active .nav-icon { color: var(--accent); }
.nav-link.subtle { color: var(--muted); font-size: 13px; }
.nav-icon { display: inline-flex; width: 22px; opacity: .92; }
.nav-icon svg, .sidebar-hide svg, .sidebar-toggle svg, .icon-button svg { display: block; width: 20px; height: 20px; }
.nav form { margin: 0; }
.nav-button { width: 100%; justify-content: flex-start; border: 0; background: transparent; box-shadow: none; }
.nav-button:hover { border-color: transparent; background: #f3f3f5; color: var(--ink-strong); }
.sidebar-hide, .sidebar-toggle, .icon-button { display: grid; width: 40px; height: 40px; min-height: 40px; place-items: center; padding: 0; border: 0; border-radius: var(--control-radius); background: transparent; color: var(--ink); }
.sidebar-hide:hover, .sidebar-toggle:hover, .icon-button:hover { border-color: transparent; background: #f3f3f5; color: var(--ink-strong); }
html[data-sidebar="closed"] .app-shell { grid-template-columns: 0 minmax(0, 1fr); }
html[data-sidebar="closed"] .sidebar { opacity: 0; pointer-events: none; transform: translateX(-100%); }

.main { display: flex; min-width: 0; width: 100%; flex-direction: column; background: var(--paper); }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; min-height: 64px; align-items: center; justify-content: space-between; gap: 18px; padding: 8px 24px; border-bottom: 1px solid var(--soft-line); background: var(--paper); }
.topbar-title { display: flex; min-width: 0; align-items: center; gap: 12px; }
.topbar-title strong { color: var(--ink-strong); font-size: 16px; }
.user-card { display: flex; min-width: 0; align-items: center; gap: 10px; }
.user-meta { display: grid; min-width: 0; line-height: 1.2; text-align: right; }
.user-meta strong, .user-meta small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta strong { color: var(--ink-strong); font-size: 14px; }
.user-meta small { color: var(--muted); font-size: 12px; }
.user-avatar { display: grid; width: 34px; height: 34px; flex: 0 0 auto; place-items: center; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 800; text-transform: uppercase; }
.page-shell { min-width: 0; width: 100%; padding: 32px; }
.page-heading, .section-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; }
.lede { max-width: 72ch; margin-top: 5px; color: var(--muted); font-size: 14px; }

.panel { padding: 20px; border: 0; border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
.form-stack { display: grid; gap: 14px; }
.form-stack h2 { margin-bottom: 4px; }
label { color: var(--ink-strong); font-size: 14px; font-weight: 600; }
input, select, textarea { width: 100%; min-height: 40px; padding: 9px 12px; border: 1px solid #d1d1d1; border-radius: var(--control-radius); background: white; color: var(--ink); font: inherit; transition: border-color .16s ease, box-shadow .16s ease; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(231 39 135 / 16%); outline: 0; }
button, .button { display: inline-flex; width: fit-content; min-height: 40px; align-items: center; justify-content: center; gap: 8px; padding: 8px 14px; border: 1px solid var(--accent); border-radius: var(--control-radius); background: var(--accent); color: white; font: inherit; font-size: 14px; font-weight: 600; line-height: 1.4; text-decoration: none; cursor: pointer; transition: background-color .16s ease, border-color .16s ease, box-shadow .16s ease, color .16s ease, transform .16s ease; }
button:hover, .button:hover, .button.primary:hover { border-color: var(--accent-dark); background: var(--accent-dark); color: white; }
button:active, .button:active { transform: translateY(1px); }
button:focus-visible, .button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgb(231 39 135 / 22%); outline-offset: 2px; }
.button.primary { background: var(--accent); color: white; }
.button.secondary { border-color: #dedee2; background: #ededf0; color: var(--ink); }
.button.secondary:hover { border-color: #d7d7dc; background: #e1e1e6; color: var(--ink-strong); }
.button.danger { border-color: #9f1239; background: #9f1239; color: white; }
.button.danger:hover { border-color: #881337; background: #881337; }
.button.compact { min-height: 32px; padding: 6px 10px; font-size: 13px; }

.alert { margin: 0; padding: 14px 16px; border: 1px solid; border-left-width: 4px; border-radius: var(--control-radius); }
.alert.error { border-color: #fecdd3; border-left-color: var(--danger); background: #fef2f2; color: #991b1b; }
.alert.success { margin-top: 1rem; border-color: #bbf7d0; border-left-color: #15803d; background: #ecfdf5; color: #065f46; }
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin: 24px 0 32px; }
.metrics > * { display: grid; min-height: 120px; align-content: center; gap: 6px; padding: 16px; border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); color: var(--muted); text-decoration: none; transition: box-shadow .16s ease, transform .16s ease; }
.metrics > a:hover { box-shadow: 0 0 2px rgb(0 0 0 / 14%), 0 4px 10px rgb(0 0 0 / 16%); color: var(--muted); transform: translateY(-1px); }
.metrics strong { color: var(--ink-strong); font-size: 34px; font-variant-numeric: tabular-nums; font-weight: 600; line-height: 1; }
.section-block { margin-top: 28px; }
.table-wrap { max-width: 100%; margin-top: 14px; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: white; }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #fafafa; color: #4f4a55; font-size: 12px; font-weight: 700; text-transform: uppercase; }
tbody tr:hover td { background: #fafafa; }
tr:last-child td { border-bottom: 0; }
.empty-state { margin-top: 14px; padding: 28px; border: 1px dashed #d1d1d1; border-radius: var(--radius); background: var(--card-soft); color: var(--muted); text-align: center; }
.narrow { width: min(680px, 100%); }
.top-gap { margin-top: 20px; }
.field-help { margin: -6px 0 4px; color: var(--muted); font-size: 13px; }
.search-bar { max-width: 620px; margin-top: 20px; }
.search-bar > div { display: flex; gap: 8px; margin-top: 6px; }
.status { display: inline-flex; width: max-content; align-items: center; padding: 5px 8px; border-radius: var(--control-radius); font-size: 12px; font-weight: 700; }
.status.active { background: #ecfdf5; color: #166534; }
.status.inactive { background: #fef2f2; color: #991b1b; }
.status.role { background: var(--accent-soft); color: var(--accent-dark); }
.split-section { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; margin-top: 24px; align-items: start; }
.danger-zone { border: 1px solid #fecdd3; box-shadow: none; }
.inline-form { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.check-row { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check-row input { width: 16px; height: 16px; min-height: 16px; accent-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: minmax(130px, .35fr) 1fr; gap: 12px 16px; align-items: center; }
.form-grid fieldset { grid-column: 1 / -1; padding: 16px; border: 1px solid var(--line); border-radius: var(--control-radius); }
.form-grid > button { grid-column: 2; }
.filter-grid { display: grid; grid-template-columns: repeat(3, 1fr) auto; gap: 16px; align-items: end; }
.filter-grid label { display: block; margin-bottom: 6px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.technical-break { overflow-wrap: anywhere; }
.recovery-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 0; list-style: none; }

.login-main { min-height: 100dvh; background: var(--paper); }
.auth-page-shell { display: grid; min-height: 100dvh; padding: 32px; place-items: center; }
.auth-layout { display: grid; width: min(980px, 100%); grid-template-columns: minmax(280px, .9fr) minmax(300px, 420px); align-items: center; gap: 20px; }
.auth-layout > div:first-child { padding: 24px; }
.auth-layout > .panel { padding: 24px; }
.auth-layout h1 { font-size: clamp(28px, 4vw, 42px); font-weight: 650; letter-spacing: -.025em; }
.auth-layout .lede { font-size: 16px; }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; width: min(300px, calc(100vw - 48px)); }
  html[data-sidebar="closed"] .app-shell { grid-template-columns: 1fr; }
  .topbar { padding: 8px; }
  .user-card { display: none; }
  .page-shell { padding: 32px; }
  .auth-layout { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .split-section, .form-grid, .filter-grid { grid-template-columns: 1fr; }
  .form-grid > button { grid-column: 1; }
}

@media (max-width: 560px) {
  h1 { font-size: 22px; }
  .page-shell, .auth-page-shell { padding: 24px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .metrics { grid-template-columns: 1fr; }
  .search-bar > div, .inline-form { align-items: stretch; flex-direction: column; }
  .search-bar .button, .inline-form .button { width: 100%; }
  .recovery-list { grid-template-columns: 1fr; }
}

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