:root {
    --ink: #172033;
    --muted: #657087;
    --canvas: #f3f5f8;
    --surface: #ffffff;
    --line: #dfe3ea;
    --nav: #111827;
    --nav-soft: #1d2638;
    --primary: #5b43e8;
    --green: #0a9f6e;
    --red: #d83b52;
    --orange: #d97706;
    --blue: #2878d0;
    --radius: 6px;
    --shadow: 0 8px 24px rgba(23, 32, 51, .07);
}

* { box-sizing: border-box; }
html { background: var(--canvas); }
body { margin: 0; color: var(--ink); background: var(--canvas); font-family: Inter, Arial, sans-serif; font-size: 14px; line-height: 1.5; letter-spacing: 0; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg { width: 18px; height: 18px; stroke-width: 1.8; }
.skip-link { position: fixed; z-index: 1000; top: -80px; left: 16px; padding: 10px 14px; color: #fff; background: var(--primary); }
.skip-link:focus { top: 12px; }
:focus-visible { outline: 3px solid rgba(91, 67, 232, .35); outline-offset: 2px; }

.app-shell { min-height: 100dvh; display: grid; grid-template-columns: 252px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; color: #e7ebf3; background: var(--nav); border-right: 1px solid #293247; overflow-y: auto; }
.brand-block { min-height: 76px; padding: 16px; display: flex; align-items: center; gap: 11px; border-bottom: 1px solid #2a3347; }
.brand-mark { width: 40px; height: 40px; flex: 0 0 auto; display: grid; place-items: center; color: #111827; background: #d7ff45; border-radius: 5px; font: 700 11px "JetBrains Mono", monospace; }
.brand-block div { min-width: 0; }
.brand-block strong, .brand-block span { display: block; }
.brand-block strong { font-size: 14px; }
.brand-block span { margin-top: 2px; color: #8f9aae; font-size: 11px; }
.close-nav { display: none; margin-left: auto; color: #fff; }
#module-nav { padding: 12px 10px 24px; }
.nav-group { margin-top: 16px; }
.nav-group:first-child { margin-top: 0; }
.nav-group-label { display: block; padding: 7px 10px; color: #76829a; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.nav-item { width: 100%; min-height: 42px; margin: 2px 0; padding: 9px 10px; display: flex; align-items: center; gap: 10px; color: #b9c2d2; background: transparent; border: 0; border-radius: 5px; text-align: left; }
.nav-item:hover { color: #fff; background: var(--nav-soft); }
.nav-item.active { color: #fff; background: var(--primary); }
.nav-item svg { flex: 0 0 auto; width: 17px; }
.sidebar-foot { margin-top: auto; padding: 16px; display: flex; gap: 10px; align-items: center; border-top: 1px solid #2a3347; }
.sidebar-foot strong, .sidebar-foot span { display: block; }
.sidebar-foot strong { font-size: 11px; }
.sidebar-foot span { color: #8591a8; font-size: 10px; }
.status-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: #28d89c; box-shadow: 0 0 0 4px rgba(40, 216, 156, .12); }

.main-area { min-width: 0; }
.topbar { position: sticky; z-index: 20; top: 0; min-height: 64px; padding: 0 28px; display: flex; align-items: center; justify-content: space-between; gap: 20px; background: rgba(255,255,255,.94); border-bottom: 1px solid var(--line); backdrop-filter: blur(10px); }
.breadcrumb { min-width: 0; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.breadcrumb svg { width: 14px; }
.breadcrumb strong { overflow: hidden; color: var(--ink); text-overflow: ellipsis; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.demo-badge { min-height: 34px; padding: 7px 10px; display: inline-flex; align-items: center; gap: 7px; color: #176646; background: #e8f8f1; border: 1px solid #bcebd8; border-radius: 4px; font-size: 11px; font-weight: 700; }
.demo-badge svg { width: 15px; }
.icon-button { width: 40px; height: 40px; padding: 0; display: inline-grid; place-items: center; color: var(--ink); background: transparent; border: 1px solid var(--line); border-radius: 5px; }
.icon-button:hover { background: #f0f2f6; }
.menu-button { display: none; }
.content { width: min(100%, 1500px); margin: 0 auto; padding: 26px 28px 56px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 25px; line-height: 1.2; }
.page-head p { max-width: 720px; margin: 6px 0 0; color: var(--muted); }
.head-actions, .toolbar, .filters { display: flex; flex-wrap: wrap; align-items: end; gap: 9px; }
.button { min-height: 40px; padding: 9px 13px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line); border-radius: 5px; color: var(--ink); background: var(--surface); font-weight: 700; font-size: 12px; }
.button:hover { border-color: #b9c1cf; background: #f8f9fb; }
.button.primary { color: #fff; border-color: var(--primary); background: var(--primary); }
.button.success { color: #fff; border-color: var(--green); background: var(--green); }
.button.danger { color: #fff; border-color: var(--red); background: var(--red); }
.button svg { width: 16px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.metric { min-height: 112px; padding: 17px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--metric-color, var(--primary)); border-radius: var(--radius); box-shadow: var(--shadow); }
.metric span { display: block; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.metric strong { display: block; margin-top: 10px; font-size: 23px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.metric small { display: block; margin-top: 7px; color: var(--muted); font-size: 10px; }
.metric.green { --metric-color: var(--green); }
.metric.orange { --metric-color: var(--orange); }
.metric.red { --metric-color: var(--red); }
.metric.blue { --metric-color: var(--blue); }

.panel { margin-bottom: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head { min-height: 56px; padding: 13px 16px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 14px; }
.panel-head p { margin: 2px 0 0; color: var(--muted); font-size: 10px; }
.panel-body { padding: 16px; }
.filter-panel { padding: 14px 16px; }
.field { min-width: 150px; flex: 1 1 160px; }
.field.wide { flex-basis: 300px; }
.field label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 700; }
.field input, .field select, .field textarea { width: 100%; min-height: 40px; padding: 8px 10px; color: var(--ink); background: #fff; border: 1px solid #cfd5df; border-radius: 4px; }
.field textarea { min-height: 86px; resize: vertical; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 12px 13px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; z-index: 1; color: #5c667a; background: #f8f9fb; font-size: 10px; text-transform: uppercase; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfc; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: "JetBrains Mono", monospace; font-size: 11px; }
.status { display: inline-flex; align-items: center; gap: 5px; padding: 4px 7px; border-radius: 3px; font-size: 10px; font-weight: 700; white-space: nowrap; }
.status.ok { color: #087653; background: #ddf7ec; }
.status.warn { color: #96510a; background: #fff0d9; }
.status.bad { color: #b4253b; background: #ffe2e7; }
.status.info { color: #2859a5; background: #e5efff; }
.trend-up { color: var(--green); font-weight: 700; }
.trend-down { color: var(--red); font-weight: 700; }

.split { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(280px, .55fr); gap: 16px; }
.chart { height: 250px; padding: 24px 18px 12px; display: flex; align-items: end; gap: 8px; border-bottom: 1px solid var(--line); background: repeating-linear-gradient(to top, #fff 0, #fff 49px, #edf0f4 50px); }
.bar { flex: 1; min-width: 12px; height: var(--h); position: relative; background: var(--bar, var(--primary)); border-radius: 3px 3px 0 0; transition: opacity .2s ease; }
.bar:hover { opacity: .72; }
.bar span { position: absolute; bottom: -28px; left: 50%; color: var(--muted); font-size: 9px; transform: translateX(-50%); }
.chart-legend { padding: 34px 16px 14px; display: flex; flex-wrap: wrap; gap: 16px; color: var(--muted); font-size: 10px; }
.legend-dot { width: 8px; height: 8px; display: inline-block; margin-right: 5px; border-radius: 2px; background: var(--dot); }

.scanner { min-height: 210px; display: grid; place-items: center; color: #fff; background: #101c2d; border-radius: 5px; text-align: center; }
.scanner-box { width: min(76%, 560px); padding: 30px 22px; border: 2px solid #39dca1; border-radius: 6px; }
.scanner-box svg { width: 42px; height: 42px; }
.scanner-box strong { display: block; margin-top: 10px; font-size: 18px; }
.scanner-box span { display: block; margin-top: 5px; color: #a7b6ca; font-size: 11px; }
.chat { min-height: 440px; display: flex; flex-direction: column; background: #f6f7fa; }
.message { max-width: 72%; margin: 14px 16px 0; padding: 12px 14px; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
.message.user { align-self: flex-end; color: #fff; background: var(--primary); border-color: var(--primary); }
.message strong { display: block; margin-bottom: 5px; font-size: 11px; }
.message p { margin: 0; }
.composer { margin-top: auto; padding: 12px; display: flex; gap: 8px; background: #fff; border-top: 1px solid var(--line); }
.composer input { flex: 1; min-width: 0; min-height: 42px; padding: 9px 11px; border: 1px solid #cfd5df; border-radius: 4px; }
.mail-layout { min-height: 480px; display: grid; grid-template-columns: 185px minmax(0, 1fr); }
.mail-folders { padding: 12px; color: #dfe6f2; background: #202044; }
.mail-folders button { width: 100%; min-height: 40px; padding: 8px 10px; display: flex; gap: 9px; align-items: center; color: inherit; background: transparent; border: 0; border-radius: 4px; text-align: left; }
.mail-folders button.active { background: #5145dc; }
.mail-list { min-width: 0; }
.mail-row { padding: 13px 16px; display: grid; grid-template-columns: 160px minmax(180px, 1fr) 80px; gap: 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.mail-row:hover { background: #f8f9fb; }
.mail-row strong, .mail-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-row time { color: var(--muted); font-size: 10px; text-align: right; }
.empty { padding: 50px 20px; color: var(--muted); text-align: center; }
.toast { position: fixed; z-index: 100; right: 20px; bottom: 20px; max-width: min(360px, calc(100% - 40px)); padding: 12px 15px; color: #fff; background: #172033; border-radius: 5px; box-shadow: 0 12px 32px rgba(0,0,0,.22); opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .2s ease, transform .2s ease; }
.toast.show { opacity: 1; transform: none; }

@media (max-width: 1050px) {
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .split { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
    .app-shell { display: block; }
    .sidebar { position: fixed; z-index: 60; inset: 0 auto 0 0; width: min(86vw, 300px); transform: translateX(-102%); transition: transform .22s ease-out; }
    .sidebar.open { transform: none; box-shadow: 16px 0 50px rgba(0,0,0,.28); }
    .close-nav, .menu-button { display: inline-grid; }
    .topbar { padding: 0 14px; }
    .breadcrumb > span, .demo-badge { display: none; }
    .content { padding: 20px 14px 44px; }
    .page-head { display: block; }
    .head-actions { margin-top: 14px; }
    .metric-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .metric { min-height: 96px; padding: 13px; }
    .metric strong { font-size: 18px; }
    .mail-layout { grid-template-columns: 1fr; }
    .mail-folders { display: flex; overflow-x: auto; }
    .mail-folders button { width: auto; flex: 0 0 auto; }
    .mail-row { grid-template-columns: 100px minmax(150px, 1fr) 58px; padding: 12px; }
}
@media (max-width: 440px) {
    .metric-grid { grid-template-columns: 1fr; }
    .field { flex-basis: 100%; }
    .button { flex: 1 1 auto; }
    .message { max-width: 88%; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
