:root {
  --bg: #f2f5f8;
  --surface: #ffffff;
  --surface-2: #edf2f7;
  --text: #17212b;
  --muted: #687687;
  --line: #d9e2ea;
  --brand: #1267e5;
  --brand-dark: #0d4da8;
  --nav: #10243e;
  --danger: #ba3434;
  --warning: #a86200;
  --success: #148259;
  --shadow: 0 14px 40px rgba(20, 36, 55, .09);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, "Segoe UI", Arial, sans-serif; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 10%, #dbeafe, transparent 38%), var(--bg); }
.login-card { width: min(450px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 34px; box-shadow: var(--shadow); }
.logo { font-size: 25px; font-weight: 900; letter-spacing: .02em; }
.logo span { color: var(--brand); }
.subtitle { color: var(--muted); margin: 8px 0 28px; }
.field { display: grid; gap: 7px; margin-bottom: 15px; }
.field label { font-size: 13px; font-weight: 700; color: #425466; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; background: var(--input-bg); color: var(--text); outline: none; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(18, 103, 229, .12); }
input[disabled] { background: var(--input-disabled); color: var(--muted); }
.btn { border: 0; border-radius: 10px; padding: 10px 15px; font-weight: 750; background: var(--brand); color: white; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover { background: var(--brand-dark); }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.danger { background: #fde7e7; color: var(--danger); }
.btn.warning { background: #fff1d6; color: var(--warning); }
.btn.small { padding: 7px 10px; font-size: 13px; }
.btn.full { width: 100%; }
.shell { min-height: 100vh; display: grid; grid-template-columns: 270px 1fr; }
.sidebar { background: var(--nav); color: white; padding: 24px 17px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .logo { margin: 0 9px 6px; }
.sidebar-version { margin: 0 9px 24px; color: #8fa6c2; font-size: 12px; }
.nav { display: grid; gap: 6px; padding-bottom: 180px; }
.nav button { text-align: left; border: 0; border-radius: 10px; padding: 11px 12px; background: transparent; color: #d7e3f3; font-weight: 650; }
.nav button:hover, .nav button.active { background: rgba(255,255,255,.12); color: white; }
.nav-separator { height: 1px; background: rgba(255,255,255,.12); margin: 8px 10px; }
.sidebar-footer { position: absolute; left: 17px; right: 17px; bottom: 18px; color: #b0c0d3; font-size: 13px; background: var(--nav); }
.role-pill { display: inline-flex; margin: 7px 0 12px; padding: 4px 8px; border-radius: 999px; background: rgba(255,255,255,.12); color: white; font-weight: 700; font-size: 12px; }
.content { padding: 30px; min-width: 0; }
.topbar { display: flex; gap: 16px; align-items: center; justify-content: space-between; margin-bottom: 24px; }
h1 { font-size: 27px; margin: 0; }
h2 { margin: 0 0 16px; }
h3 { margin: 0; }
.muted { color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 5px 20px rgba(20,36,55,.04); padding: 20px; }
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.metric { min-height: 130px; }
.metric-value { font-size: 32px; font-weight: 900; margin-top: 14px; color: var(--brand-dark); }
.module-card { display: grid; gap: 10px; align-content: start; }
.module-card .btn { justify-self: start; }
.project-card { cursor: pointer; transition: .18s; }
.project-card:hover { transform: translateY(-2px); border-color: #b9cff1; box-shadow: var(--shadow); }
.project-card h3 { margin: 0 0 8px; }
.badge { display: inline-flex; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #e8f1ff; color: #1559aa; }
.badge.success { background: #e3f6ee; color: var(--success); }
.badge.off { background: #f1f1f1; color: #707070; }
.badge.system { background: #eee8ff; color: #5e3aa8; }
.actions { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }
.form-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.form-row.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; min-width: 900px; }
th, td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; background: #edf3f9; color: #405164; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; z-index: 1; }
td.num, th.num { text-align: right; white-space: nowrap; }
.summary { margin-left: auto; width: min(430px, 100%); display: grid; gap: 8px; }
.summary-row { display: flex; justify-content: space-between; gap: 20px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.summary-row.total { font-size: 20px; font-weight: 900; border: 0; color: var(--brand-dark); }
.modal-backdrop { position: fixed; inset: 0; background: rgba(8,20,35,.55); display: grid; place-items: center; padding: 20px; z-index: 10; }
.modal { background: var(--surface); border-radius: 18px; width: min(760px, 100%); max-height: 92vh; overflow: auto; padding: 24px; box-shadow: var(--shadow); }
.modal h2 { margin-top: 0; }
.toast { position: fixed; right: 22px; top: 22px; background: #17212b; color: white; padding: 12px 16px; border-radius: 10px; opacity: 0; transform: translateY(-10px); pointer-events: none; transition: .2s; z-index: 20; max-width: 440px; }
.toast.show { opacity: 1; transform: translateY(0); }
.empty { text-align: center; color: var(--muted); padding: 42px 20px; }
.legal-links { display:flex; flex-wrap:wrap; justify-content:center; gap:10px; margin-top:18px; font-size:12px; }
.legal-links a { color: var(--brand); }
.legal-gate { width:min(620px,100%); }
.check-row { display:flex; align-items:flex-start; gap:10px; padding:14px; margin:10px 0; border:1px solid var(--line); border-radius:12px; line-height:1.45; }
.check-row input { margin-top:4px; width: auto; }
.notice { border-left: 4px solid var(--brand); background: #eaf2ff; padding: 16px; border-radius: 10px; }
.notice.warning { border-left-color: #d68a1c; background: #fff6e7; }
.section-gap { margin-top: 18px; }
.filter-row { display: grid; grid-template-columns: minmax(240px, 1fr) 220px auto; gap: 10px; margin-bottom: 14px; }
.permission-list { display: flex; flex-wrap: wrap; gap: 6px; }
.permission-list span { font-size: 11px; padding: 4px 7px; border-radius: 999px; background: var(--surface-2); color: #526172; }
@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar-footer { position: static; margin-top: 20px; }
  .nav { padding-bottom: 0; }
  .content { padding: 18px; }
  .grid.cols-4, .grid.cols-3, .grid.cols-2, .form-row, .form-row.cols-2, .filter-row { grid-template-columns: 1fr; }
}

/* ===== SFERA brand assets and light/dark themes ===== */
:root {
  color-scheme: light;
  --nav: #ffffff;
  --nav-text: #344456;
  --nav-muted: #758498;
  --nav-hover: #eaf2ff;
  --nav-line: #dfe7ef;
  --input-bg: #ffffff;
  --input-disabled: #f3f5f7;
  --field-label: #425466;
  --table-head: #edf3f9;
  --login-glow: #dbeafe;
  --role-bg: #e8f1ff;
  --role-text: #1559aa;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e141b;
  --surface: #151d27;
  --surface-2: #1e2936;
  --text: #eef4fb;
  --muted: #9cafc1;
  --line: #2b3948;
  --brand: #6da8ff;
  --brand-dark: #4b8de9;
  --nav: #101821;
  --nav-text: #dce8f5;
  --nav-muted: #91a7bd;
  --nav-hover: #233246;
  --nav-line: #273545;
  --danger: #ff9494;
  --warning: #f4bc67;
  --success: #64d7aa;
  --shadow: 0 14px 40px rgba(0, 0, 0, .35);
  --input-bg: #101821;
  --input-disabled: #202a35;
  --field-label: #bac8d7;
  --table-head: #1d2936;
  --login-glow: #172f50;
  --role-bg: #243953;
  --role-text: #b8d6ff;
}

body { transition: background-color .2s ease, color .2s ease; }
.login-shell { background: radial-gradient(circle at 20% 10%, var(--login-glow), transparent 38%), var(--bg); }
.field label { color: var(--field-label); }
input, select, textarea { background: var(--input-bg); }
input[disabled] { background: var(--input-disabled); color: var(--muted); }
.sidebar { background: var(--nav); color: var(--text); border-right: 1px solid var(--nav-line); }
.sidebar-version { color: var(--nav-muted); }
.nav button { color: var(--nav-text); }
.nav button:hover, .nav button.active { background: var(--nav-hover); color: var(--text); }
.nav-separator { background: var(--nav-line); }
.sidebar-footer { color: var(--nav-muted); background: var(--nav); }
.role-pill { background: var(--role-bg); color: var(--role-text); }
th { background: var(--table-head); color: var(--muted); }
.modal { background: var(--surface); color: var(--text); }
.permission-list span { color: var(--muted); }

.brand-logo-wrap { display: block; line-height: 0; }
.brand-logo { display: block; width: 100%; height: auto; object-fit: contain; }
.brand-logo-dark { display: none; }
html[data-theme="dark"] .brand-logo-light { display: none; }
html[data-theme="dark"] .brand-logo-dark { display: block; }
.sidebar-brand { width: 222px; max-width: calc(100% - 12px); margin: 0 6px 10px; }
.login-brand { width: min(330px, 100%); margin: 4px auto 18px; }

.theme-toggle {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 8px 12px;
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 750;
  box-shadow: 0 3px 12px rgba(20, 36, 55, .05);
}
.theme-toggle:hover { background: var(--surface-2); }
.theme-toggle-icon { width: 20px; font-size: 19px; line-height: 1; text-align: center; }
.theme-toggle.compact { min-height: 34px; padding: 6px 9px; font-size: 12px; }
.login-theme-row { display: flex; justify-content: flex-end; margin: -10px -10px 8px 0; }

html[data-theme="dark"] .badge { background: #243953; color: #b8d6ff; }
html[data-theme="dark"] .badge.success { background: #173d32; color: #83dfbd; }
html[data-theme="dark"] .badge.off { background: #29313a; color: #acb6c0; }
html[data-theme="dark"] .badge.system { background: #362d52; color: #d0bfff; }
html[data-theme="dark"] .btn.danger { background: #4b272b; color: #ffb3b3; }
html[data-theme="dark"] .btn.warning { background: #4a3821; color: #ffd28e; }
html[data-theme="dark"] .notice { background: #172b45; }
html[data-theme="dark"] .notice.warning { background: #3b2f1e; }
html[data-theme="dark"] .toast { background: #e8eef5; color: #111820; }
html[data-theme="dark"] .project-card:hover { border-color: #4c6f9b; }

@media (max-width: 900px) {
  .sidebar-brand { width: 250px; }
  .topbar { align-items: flex-start; }
  .theme-toggle-label { display: none; }
  .theme-toggle { width: 42px; padding: 8px; }
}
