:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #172033;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #047857;
  --warning: #b45309;
  --danger: #b91c1c;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 8px 24px rgba(15, 23, 42, .04);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
[hidden], .hidden { display: none !important; }
.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; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--surface); z-index: 30; }
.brand { min-height: 72px; display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; color: #fff; background: var(--primary); font-size: 12px; font-weight: 800; letter-spacing: .04em; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.nav-list { flex: 1; padding: 16px 12px; }
.nav-link { display: flex; align-items: center; gap: 11px; min-height: 42px; margin-bottom: 4px; padding: 9px 12px; border-radius: 9px; color: #475569; text-decoration: none; font-size: 14px; font-weight: 550; }
.nav-link span { width: 20px; text-align: center; color: #64748b; }
.nav-link:hover { background: var(--surface-soft); color: var(--text); }
.nav-link.is-active { color: #1e40af; background: #eff6ff; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid var(--border); color: #94a3b8; font-size: 11px; }
.main-column { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 20; min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px 28px; border-bottom: 1px solid var(--border); background: rgba(255,255,255,.96); }
.topbar-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar h1 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 18px; }
.menu-button { display: none; width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); cursor: pointer; }
.account { display: flex; align-items: center; gap: 14px; }
.account-role { color: var(--muted); font-size: 13px; }
.logout-button { border: 0; background: transparent; color: var(--danger); cursor: pointer; font-size: 13px; }
.page-content { width: 100%; max-width: 1480px; margin: 0 auto; padding: 28px; }

.page-stack { display: grid; gap: 20px; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.page-heading h2, .section-heading h2 { margin: 0; font-size: 22px; line-height: 1.25; }
.page-heading p, .section-heading p { margin: 6px 0 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.card { overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.card-body { padding: 20px; }
.section-heading { padding: 18px 20px; border-bottom: 1px solid var(--border); }
.section-heading h2 { font-size: 16px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat-card { padding: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 600; }
.stat-value { margin-top: 9px; font-size: 26px; font-weight: 750; letter-spacing: -.025em; }
.stat-note { margin-top: 6px; color: var(--muted); font-size: 12px; }
.content-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, .8fr); gap: 20px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.field { display: grid; gap: 6px; min-width: 180px; color: #334155; font-size: 13px; font-weight: 600; }
.field.grow { flex: 1; }
.field input, .field select, .field textarea { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid #cbd5e1; border-radius: 9px; color: var(--text); background: var(--surface); }
.field textarea { min-height: 96px; resize: vertical; }
.field small { color: var(--muted); font-weight: 400; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.form-grid { display: grid; gap: 16px; }
.check-row { display: flex; align-items: center; gap: 9px; min-height: 42px; font-size: 14px; }
.check-row input { width: 17px; height: 17px; accent-color: var(--primary); }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding-top: 4px; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; padding: 8px 14px; border: 1px solid transparent; border-radius: 9px; text-decoration: none; font-size: 13px; font-weight: 650; cursor: pointer; }
.button:disabled { cursor: not-allowed; opacity: .55; }
.button-primary { color: #fff; background: var(--primary); }
.button-primary:hover { background: var(--primary-hover); }
.button-secondary { border-color: #cbd5e1; color: #334155; background: var(--surface); }
.button-secondary:hover { background: var(--surface-soft); }
.button-success { color: #fff; background: var(--success); }
.button-danger { border-color: #fecaca; color: var(--danger); background: #fff; }

.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { padding: 11px 16px; background: var(--surface-soft); color: var(--muted); text-align: left; text-transform: uppercase; letter-spacing: .035em; font-size: 10px; white-space: nowrap; }
.data-table td { padding: 13px 16px; border-top: 1px solid #edf2f7; vertical-align: middle; }
.data-table tbody tr:hover { background: #fbfdff; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.success-text { color: var(--success); }
.danger-text { color: var(--danger); }
.empty-state { padding: 36px 20px; color: var(--muted); text-align: center; font-size: 14px; }
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 650; white-space: nowrap; }
.badge-neutral { color: #475569; background: #f1f5f9; }
.badge-success { color: #065f46; background: #d1fae5; }
.badge-warning { color: #92400e; background: #fef3c7; }
.badge-danger { color: #991b1b; background: #fee2e2; }
.badge-info { color: #1e40af; background: #dbeafe; }
.status-box { margin-top: 14px; padding: 11px 13px; border-radius: 9px; font-size: 13px; }
.status-box.success { color: #065f46; background: #ecfdf5; }
.status-box.error { color: #991b1b; background: #fef2f2; }
.notice { padding: 14px; border-radius: 9px; color: #854d0e; background: #fefce8; font-size: 13px; }
.action-row { display: flex; flex-wrap: wrap; gap: 7px; }
.small-button { min-height: 32px; padding: 5px 9px; border: 1px solid #cbd5e1; border-radius: 7px; background: #fff; color: #334155; font-size: 11px; font-weight: 650; cursor: pointer; }
.small-button:hover { background: var(--surface-soft); }
.small-button.danger { border-color: #fecaca; color: var(--danger); }
.list { margin: 0; padding: 0; list-style: none; }
.list-item { display: flex; justify-content: space-between; gap: 16px; padding: 13px 0; border-bottom: 1px solid #edf2f7; }
.list-item:last-child { border-bottom: 0; }
.list-item strong, .list-item small { display: block; }
.list-item small { margin-top: 4px; color: var(--muted); }
.tabs { display: flex; gap: 4px; padding: 4px; border-radius: 10px; background: #f1f5f9; }
.tab { flex: 1; min-height: 36px; padding: 7px 10px; border: 0; border-radius: 7px; color: #475569; background: transparent; cursor: pointer; font-size: 12px; font-weight: 650; }
.tab.is-active { color: #1e40af; background: #fff; box-shadow: 0 1px 2px rgba(15,23,42,.08); }
.settings-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 20px; }
.settings-nav { display: grid; align-content: start; gap: 5px; }
.settings-nav button { padding: 10px 12px; border: 0; border-radius: 8px; color: #475569; background: transparent; text-align: left; cursor: pointer; }
.settings-nav button.is-active { color: #1e40af; background: #eff6ff; font-weight: 650; }
.settings-panel { display: none; }
.settings-panel.is-active { display: block; }
.panel-title { margin: 0; font-size: 17px; }
.panel-copy { margin: 5px 0 0; font-size: 13px; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(145deg, #eef4ff, #f8fafc 45%, #eef2ff); }
.auth-shell { width: min(100%, 430px); }
.auth-card { padding: 30px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); box-shadow: 0 18px 55px rgba(15,23,42,.12); }
.auth-brand { text-align: center; }
.auth-brand .brand-mark { margin: 0 auto 12px; }
.auth-brand h1 { margin: 0; font-size: 24px; }
.auth-brand p, .auth-telegram > p, .auth-admin > p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.auth-telegram, .auth-admin { margin-top: 24px; }
.auth-telegram > script { display: block; margin-top: 12px; }
.auth-help { color: var(--muted); font-size: 11px; line-height: 1.5; }
.auth-divider { display: flex; align-items: center; gap: 12px; margin: 24px 0; color: #94a3b8; font-size: 12px; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.auth-form { display: grid; gap: 15px; margin-top: 14px; }
.auth-error { margin-bottom: 14px; }
.auth-submit { width: 100%; }
.auth-footer { margin: 18px 0 0; color: #94a3b8; text-align: center; font-size: 12px; }

:focus-visible { outline: 3px solid rgba(37,99,235,.28); outline-offset: 2px; }
@media (max-width: 1050px) { .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .content-grid { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; left: 0; transform: translateX(-102%); width: min(280px, 86vw); transition: transform .18s ease; }
  body.menu-open .sidebar { transform: translateX(0); }
  .nav-backdrop { position: fixed; inset: 0; z-index: 25; display: block; background: rgba(15,23,42,.42); }
  .menu-button { display: inline-grid; place-items: center; }
  .topbar { padding: 10px 16px; }
  .account-role { display: none; }
  .page-content { padding: 18px 14px 28px; }
  .page-heading { display: grid; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 21px; }
  .field-row, .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { display: flex; overflow-x: auto; }
  .settings-nav button { white-space: nowrap; }
}
@media (max-width: 430px) { .stat-grid { grid-template-columns: 1fr; } .account { gap: 6px; } .topbar h1 { font-size: 16px; } }
@media (max-width: 430px) { .auth-page { padding: 12px; } .auth-card { padding: 22px 18px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; } }
