:root {
  --bg: #0d0f13;
  --surface: #14171d;
  --surface-2: #1a1e26;
  --surface-3: #222733;
  --border: #252a34;
  --border-strong: #343b48;
  --text: #e7e9ee;
  --text-2: #a3abba;
  --text-3: #6f7889;
  --accent: #5b8def;
  --accent-strong: #7aa5ff;
  --accent-bg: rgba(91, 141, 239, 0.14);
  --success: #43c38a;
  --success-bg: rgba(67, 195, 138, 0.13);
  --warning: #e9b04c;
  --warning-bg: rgba(233, 176, 76, 0.14);
  --danger: #ef6b6b;
  --danger-bg: rgba(239, 107, 107, 0.14);
  --radius: 8px;
  --radius-lg: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; }
ul { margin: 0; padding: 0; }
.sprite { display: none; }
.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico-sm { width: 14px; height: 14px; vertical-align: -2px; margin-right: 4px; }

/* layout */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 15px; padding: 4px 8px 16px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
}
.brand-lg { font-size: 18px; padding: 0 0 4px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 14px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius);
  color: var(--text-2); font: inherit; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.is-active { background: var(--accent-bg); color: var(--text); }
.nav-item.is-active .ico { color: var(--accent-strong); }
.nav-item.is-soon { opacity: .5; cursor: default; }
.nav-item.is-soon:hover { background: none; color: var(--text-2); }
.soon { margin-left: auto; font-size: 10px; border: 1px solid var(--border-strong); border-radius: 999px; padding: 0 7px; }
.nav-button { background: none; border: 0; cursor: pointer; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.mode-chip {
  display: flex; align-items: center; gap: 8px; margin: 0 0 6px; padding: 7px 10px; border-radius: var(--radius);
  background: var(--accent-bg); color: var(--accent-strong); font-size: 13px;
}
.mode-chip:hover { text-decoration: none; }
.mode-chip-warning { background: var(--warning-bg); color: var(--warning); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 28px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: rgba(13, 15, 19, .92); backdrop-filter: blur(6px); z-index: 5;
}
.topbar-title { font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-meta { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.topbar .menu-toggle { display: none; }
.back { color: var(--text-2); display: inline-grid; place-items: center; border-radius: 6px; padding: 2px; }
.back:hover { color: var(--text); background: var(--surface-2); }
.content { padding: 24px 28px 48px; max-width: 1280px; width: 100%; display: flex; flex-direction: column; gap: 18px; }

/* primitives */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; }
.card-flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-form { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.muted { color: var(--text-2); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 13px; }
.nowrap { white-space: nowrap; }
.wrap { white-space: normal; overflow-wrap: anywhere; min-width: 260px; }
.strike { text-decoration: line-through; }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.spacer { flex: 1; }
.link { font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: var(--radius); border: 1px solid var(--border-strong); background: var(--surface-2);
  color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn .ico { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #4b7fe6; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-warning { background: var(--warning-bg); border-color: rgba(233, 176, 76, .45); color: var(--warning); }
.btn-warning:hover { background: rgba(233, 176, 76, .22); }
.btn-danger { background: var(--danger-bg); border-color: rgba(239, 107, 107, .4); color: var(--danger); }
.btn-danger:hover { background: rgba(239, 107, 107, .22); }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius);
  border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

input, select {
  height: 36px; padding: 0 11px; border-radius: var(--radius); border: 1px solid var(--border-strong);
  background: var(--bg); color: var(--text); font: inherit; width: 100%; min-width: 0;
}
input:focus, select:focus, .btn:focus-visible, .icon-btn:focus-visible, a:focus-visible, .switch input:focus-visible + .switch-track {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg);
}
input::placeholder { color: var(--text-3); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span, .field-label { font-size: 12.5px; color: var(--text-2); }
.field-label { margin: 16px 0 8px; }
.field.grow { flex: 1; }
.field.narrow { max-width: 180px; }
.form-grid { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.form-row > .field { flex: 1; min-width: 150px; }
.form-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.inline-form { margin-top: 10px; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; color: var(--text); min-height: 36px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { width: 36px; height: 20px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border-strong); position: relative; flex: none; transition: background .15s; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--text-2); transition: transform .15s, background .15s; }
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); background: #fff; }

.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-accent { background: var(--accent-bg); color: var(--accent-strong); }
.badge-neutral { background: var(--surface-3); color: var(--text-2); }
.pill { display: inline-flex; align-items: center; gap: 8px; height: 26px; padding: 0 10px; border-radius: 999px; font-size: 12.5px; }
.pill-accent { background: var(--accent-bg); color: var(--accent-strong); }
.spinner { width: 12px; height: 12px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot-info { background: var(--text-3); }
.dot-warning { background: var(--warning); }
.dot-error { background: var(--danger); }

.alert { border-radius: var(--radius); padding: 10px 14px; border: 1px solid; }
.alert ul { margin: 6px 0 0 18px; }
.alert-success { background: var(--success-bg); border-color: rgba(67, 195, 138, .35); color: #b9f0d6; }
.alert-warning { background: var(--warning-bg); border-color: rgba(233, 176, 76, .4); color: #f6dcaa; }
.alert-error { background: var(--danger-bg); border-color: rgba(239, 107, 107, .4); color: #ffc9c9; }
.banner { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: var(--radius-lg); border: 1px solid; }
.banner .ico { margin-top: 2px; }
.banner-accent { background: var(--accent-bg); border-color: rgba(91, 141, 239, .35); }
.banner-accent .ico { color: var(--accent-strong); }
.banner-warning { background: var(--warning-bg); border-color: rgba(233, 176, 76, .4); }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; display: flex; flex-direction: column; color: var(--text); }
.metric:hover { border-color: var(--border-strong); text-decoration: none; }
.metric-label { font-size: 12.5px; color: var(--text-2); }
.metric-value { font-size: 26px; font-weight: 600; line-height: 1.3; margin-top: 2px; }
.metric-sub { font-size: 12px; color: var(--text-3); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 500; font-size: 12px; color: var(--text-3); padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.card:not(.card-flush) .table th:first-child, .card:not(.card-flush) .table td:first-child { padding-left: 0; }
.table .num { text-align: right; }
.table-hover tbody tr { cursor: pointer; }
.table-hover tbody tr:hover td { background: var(--surface-2); }
.ellipsis { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-table .dot { margin-top: 6px; }
.log-table tr.level-error td { background: rgba(239, 107, 107, .04); }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters select { width: auto; }
.search { position: relative; display: block; width: 280px; max-width: 100%; }
.search .ico { position: absolute; left: 10px; top: 9px; color: var(--text-3); width: 17px; height: 17px; }
.search input { padding-left: 34px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; }

.feed { list-style: none; display: flex; flex-direction: column; }
.feed li { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: 12px; padding: 9px 0; border-top: 1px solid var(--border); align-items: start; }
.feed li:first-child { border-top: 0; }
.feed .dot { margin-top: 7px; }
.feed-title { font-weight: 500; }
.feed-text { color: var(--text-2); font-size: 13px; overflow-wrap: anywhere; }

.empty { text-align: center; color: var(--text-2); padding: 28px 16px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty h2 { color: var(--text); }

/* kit form */
.kit-status { display: flex; flex-direction: column; gap: 14px; }
.kit-status-main { display: flex; justify-content: space-between; gap: 18px; flex-wrap: wrap; }
.kit-title { font-size: 16px; font-weight: 600; }
.kit-status-line { display: flex; gap: 10px; align-items: baseline; margin-top: 6px; flex-wrap: wrap; }
.kit-prices { display: flex; gap: 28px; }
.kit-prices > div { display: flex; flex-direction: column; }
.kit-prices b { font-size: 20px; }
.kit-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 14px; }
.components { display: flex; flex-direction: column; gap: 6px; }
.component-head, .component-row { display: grid; grid-template-columns: minmax(0, 1fr) 92px 34px; gap: 8px; align-items: center; }
.component-head { font-size: 12px; color: var(--text-3); }
.component-row input[name="comp_article"] { font-family: var(--mono); font-size: 13px; }
.preview { position: sticky; top: 80px; }
.preview-table td, .preview-table th { padding: 8px 10px; }
.preview-total { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.preview-total .big { font-size: 22px; font-weight: 600; }
.issue { color: var(--danger); font-size: 12.5px; }
.danger-zone { border-color: rgba(239, 107, 107, .25); }

/* settings */
.settings { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 24px; align-items: start; }
.settings-nav { position: sticky; top: 80px; display: flex; flex-direction: column; gap: 2px; }
.settings-nav a { color: var(--text-2); padding: 6px 10px; border-radius: var(--radius); }
.settings-nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.settings-nav .nav-section { padding-top: 10px; }
.settings-body { display: flex; flex-direction: column; gap: 18px; max-width: 760px; }
.settings-body .card { scroll-margin-top: 80px; }
.narrow-card { max-width: 520px; }
.steps { margin: 0 0 14px 18px; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.chat-choice { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.chat-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius); }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; padding: 28px; }
.login-card p { margin: 0; }

@media (max-width: 1100px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-form { grid-template-columns: minmax(0, 1fr); }
  .preview { position: static; }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0, 0, 0, .5); }
  body.nav-open .sidebar { transform: none; }
  .topbar .menu-toggle { display: inline-grid; }
  .topbar { padding: 10px 16px; }
  .topbar-meta .muted { display: none; }
  .content { padding: 16px 16px 40px; }
  .grid-2, .settings { grid-template-columns: minmax(0, 1fr); }
  .settings-nav { position: static; flex-direction: row; flex-wrap: wrap; }
  .settings-nav .nav-section { display: none; }
  .search { width: 100%; }
  .filters { width: 100%; }
}
.show-sm { display: none; }
@media (max-width: 640px) {
  .hide-sm { display: none; }
  .show-sm { display: block; margin-top: 4px; }
  .ellipsis { max-width: 190px; }
  .table th, .table td { padding: 10px; }
}
@media (max-width: 520px) {
  .metrics { grid-template-columns: minmax(0, 1fr); }
  .kit-prices { gap: 18px; }
}
