:root {
  --brand: #6366f1;
  --brand-strong: #4f46e5;
  --brand-soft: rgba(99, 102, 241, .12);
  --bg-main: #f7f7f8;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f7f7f7;
  --text-main: #222222;
  --text-secondary: #717171;
  --border: #e8e8eb;
  --danger: #c9364f;
  --success: #147a3e;
  --shadow: 0 10px 30px rgba(17, 24, 39, .05);
  --sidebar-width: 214px;
  --radius: 14px;
  color-scheme: light;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
:root[data-theme="dark"] {
  --brand-soft: rgba(129, 140, 248, .16);
  --bg-main: #111318;
  --bg-sidebar: #17191f;
  --bg-card: #1b1e25;
  --bg-input: #242730;
  --text-main: #f0f1f5;
  --text-secondary: #a4a8b3;
  --border: #30343e;
  --danger: #ff7189;
  --success: #54c985;
  --shadow: 0 12px 36px rgba(0, 0, 0, .24);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg-main); color: var(--text-main); }
body { font-size: 14px; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
.app-shell { min-height: 100vh; display: flex; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; width: var(--sidebar-width); display: flex; flex-direction: column; padding: 14px 12px; background: var(--bg-sidebar); border-right: 1px solid var(--border); transition: width .24s ease, transform .24s ease; }
.sidebar__collapse { position: absolute; top: 62px; right: -12px; width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--border); background: var(--bg-card); color: var(--text-secondary); box-shadow: var(--shadow); cursor: pointer; }
.brand { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 3px 4px; margin-bottom: 16px; overflow: hidden; }
.brand__mark, .profile__avatar { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; color: #fff; background: linear-gradient(145deg, var(--brand), var(--brand-strong)); font-weight: 750; }
.brand__mark { width: 34px; height: 34px; border-radius: 10px; }
.brand__name { white-space: nowrap; font-weight: 700; letter-spacing: -.01em; }
.nav { display: flex; flex: 1; flex-direction: column; gap: 4px; min-height: 0; }
.nav__item { display: flex; align-items: center; gap: 11px; min-height: 40px; padding: 0 12px; border-radius: 10px; color: var(--text-secondary); white-space: nowrap; transition: color .16s ease, background .16s ease; overflow: hidden; }
.nav__item:hover { color: var(--text-main); background: var(--bg-input); }
.nav__item--active { color: var(--brand); background: var(--brand-soft); font-weight: 650; }
.nav__icon { width: 20px; flex: 0 0 20px; text-align: center; font-size: 19px; line-height: 1; }
.nav__label { overflow: hidden; }
.sidebar__footer { padding-top: 12px; border-top: 1px solid var(--border); }
.profile { display: flex; align-items: center; gap: 9px; min-height: 42px; padding: 3px 4px 10px; overflow: hidden; }
.profile__avatar { width: 30px; height: 30px; border-radius: 9px; }
.profile__text { display: flex; flex: 1; min-width: 0; flex-direction: column; }
.profile__text strong, .profile__text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile__text strong { font-size: 12px; }
.profile__text small { color: var(--text-secondary); font-size: 11px; text-transform: capitalize; }
.icon-button { flex: 0 0 auto; width: 30px; height: 30px; border: 0; border-radius: 8px; color: var(--text-secondary); background: transparent; cursor: pointer; }
.icon-button:hover { background: var(--bg-input); color: var(--text-main); }
.workspace { width: calc(100% - var(--sidebar-width)); min-width: 0; margin-left: var(--sidebar-width); transition: width .24s ease, margin-left .24s ease; }
.page-header { min-height: 82px; display: flex; align-items: center; gap: 14px; padding: 16px 28px; background: var(--bg-main); border-bottom: 1px solid var(--border); }
.page-header__eyebrow { margin: 0 0 2px; color: var(--text-secondary); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.page-header h1 { margin: 0; font-size: 24px; line-height: 1.15; letter-spacing: -.02em; }
.mobile-menu { display: none; width: 38px; height: 38px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-card); color: var(--text-main); }
.badge { margin-left: auto; max-width: 55%; padding: 7px 10px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-size: 12px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-content { padding: 24px 28px 40px; }
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.controls { display: flex; align-items: flex-end; gap: 18px; padding: 18px 20px; margin-bottom: 18px; }
.controls .field { min-width: 180px; }
.controls__count { margin-left: auto; padding-bottom: 10px; color: var(--text-secondary); font-size: 13px; }
.field { display: block; margin-bottom: 18px; }
.field--inline { margin-bottom: 0; }
.field__label { display: block; margin-bottom: 7px; color: var(--text-secondary); font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.input { width: 100%; min-height: 40px; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg-input); color: var(--text-main); outline: none; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.btn-primary { display: inline-flex; min-height: 40px; align-items: center; justify-content: center; padding: 0 16px; border: 0; border-radius: 9px; background: var(--brand); color: #fff; font-weight: 650; cursor: pointer; }
.btn-primary:hover { background: var(--brand-strong); }
.table-card { overflow: hidden; }
.tablewrap { width: 100%; overflow: auto; scrollbar-gutter: stable; }
.tablewrap--scrolling { border-bottom: 1px solid var(--border); }
.table { width: 100%; min-width: 1680px; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.table th { position: sticky; top: 0; z-index: 3; padding: 12px 14px; border-bottom: 1px solid var(--border); color: var(--text-secondary); background: color-mix(in srgb, var(--bg-card), var(--bg-input) 45%); font-size: 10px; font-weight: 750; letter-spacing: .05em; text-align: left; text-transform: uppercase; white-space: nowrap; }
.table th[data-sort] { cursor: pointer; }
.table th.sorted { color: var(--brand); }
.table td { padding: 13px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--brand-soft); }
.table .num { text-align: right; white-space: nowrap; }
.cell-main { font-weight: 650; white-space: nowrap; }
.cell-sub { margin-top: 4px; color: var(--text-secondary); font-size: 11px; }
.cell-sub.up { color: var(--danger); }
.cell-sub.down { color: var(--success); }
.cell-sub.off { color: var(--danger); }
.cell-complex { min-width: 190px; }
.cell-comment { width: 520px; min-width: 520px; color: var(--text-secondary); line-height: 1.35; }
.factor-row { display: flex; align-items: baseline; gap: 4px; padding: 3px 0; white-space: nowrap; }
.factor-row + .factor-row { border-top: 1px solid color-mix(in srgb, var(--border), transparent 35%); }
.factor-label { color: var(--text-main); font-weight: 600; }
.factor-value { flex: 1; min-width: 150px; color: var(--text-secondary); }
.factor-effect { margin-left: auto; padding-left: 8px; font-weight: 750; white-space: nowrap; }
.factor-effect--up { color: var(--success); }
.factor-effect--down { color: var(--danger); }
.factor-effect--neutral { color: var(--text-secondary); }
.tablefoot { padding: 12px; border-top: 1px solid var(--border); text-align: center; color: var(--text-secondary); }
.tablefoot button { padding: 7px 14px; border: 1px solid var(--border); border-radius: 8px; background: transparent; color: var(--text-main); cursor: pointer; }
.admin-grid { display: grid; grid-template-columns: minmax(300px, 420px) minmax(360px, 1fr); gap: 20px; align-items: start; }
.admin-card, .settings-card { padding: 22px; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.section-heading h2 { margin: 0; font-size: 18px; }
.section-heading p { margin: 5px 0 0; color: var(--text-secondary); font-size: 13px; }
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: radial-gradient(circle at top, var(--brand-soft), transparent 45%), var(--bg-main); }
.login__card { width: 100%; max-width: 390px; padding: 30px; }
.login__title { margin: 0; font-size: 28px; }
.login__sub { margin: 7px 0 24px; color: var(--text-secondary); line-height: 1.45; }
.login__error, .form__success { margin: 0 0 15px; font-size: 13px; }
.login__error { color: var(--danger); }
.form__success { color: var(--success); }
.login .btn-primary { width: 100%; }
.settings-page { display: grid; gap: 20px; }
.theme-grid { display: grid; grid-template-columns: repeat(3, minmax(160px, 1fr)); gap: 14px; }
.theme-choice { display: flex; flex-direction: column; gap: 5px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-card); color: var(--text-main); text-align: left; cursor: pointer; }
.theme-choice:hover, .theme-choice--active { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.theme-choice strong { margin-top: 5px; }
.theme-choice small { color: var(--text-secondary); }
.theme-preview { height: 90px; display: grid; grid-template-columns: 34% 1fr; gap: 7px; padding: 8px; border-radius: 9px; overflow: hidden; }
.theme-preview i { display: block; border-radius: 5px; }
.theme-preview--light { background: #f3f4f6; }
.theme-preview--light i { background: #fff; border: 1px solid #e5e7eb; }
.theme-preview--dark { background: #111318; }
.theme-preview--dark i { background: #1b1e25; border: 1px solid #30343e; }
.theme-preview--system { background: linear-gradient(110deg, #f3f4f6 50%, #111318 50%); }
.theme-preview--system i:first-child { background: #fff; }
.theme-preview--system i:last-child { background: #1b1e25; }
.save-state { opacity: 0; color: var(--success); font-size: 12px; transition: opacity .2s; }
.save-state--visible { opacity: 1; }
.access-list { display: grid; gap: 12px; }
.access-list > div { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; }
.access-list p { margin: 0; color: var(--text-secondary); }
.role-badge { min-width: 64px; padding: 5px 8px; border-radius: 7px; background: var(--brand-soft); color: var(--brand); font-weight: 700; text-align: center; }
.role-badge--muted { background: var(--bg-input); color: var(--text-secondary); }
.sidebar-overlay { display: none; }
body.sidebar-collapsed { --sidebar-width: 68px; }
body.sidebar-collapsed .brand__name, body.sidebar-collapsed .nav__label, body.sidebar-collapsed .profile__text, body.sidebar-collapsed .icon-button { width: 0; opacity: 0; pointer-events: none; }
body.sidebar-collapsed .nav__item { justify-content: center; padding-inline: 0; }
body.sidebar-collapsed .profile { justify-content: center; padding-inline: 0; }
body.sidebar-collapsed .sidebar__collapse { transform: rotate(180deg); }
@media (max-width: 900px) {
  :root { --sidebar-width: 0px; }
  .sidebar { width: 230px; transform: translateX(-105%); box-shadow: 18px 0 40px rgba(0,0,0,.18); }
  body.sidebar-mobile-open .sidebar { transform: translateX(0); }
  .sidebar__collapse { display: none; }
  .sidebar-overlay { position: fixed; inset: 0; z-index: 20; border: 0; background: rgba(9, 11, 16, .45); }
  body.sidebar-mobile-open .sidebar-overlay { display: block; }
  .workspace { width: 100%; margin-left: 0; }
  .mobile-menu { display: inline-flex; align-items: center; justify-content: center; }
  .page-header { padding: 14px 18px; }
  .page-content { padding: 18px; }
  .controls { flex-wrap: wrap; }
  .controls .field { min-width: calc(50% - 10px); flex: 1; }
  .controls__count { width: 100%; margin-left: 0; }
  .admin-grid { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .badge { display: none; }
  .page-header h1 { font-size: 21px; }
  .controls .field { min-width: 100%; }
  .theme-grid { grid-template-columns: 1fr; }
  .login__card { padding: 24px; }
}
