* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); font-size: 14px; line-height: 1.5; color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased; transition: background .2s, color .2s; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round;
  stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh;
  background: linear-gradient(to right, var(--side) 248px, var(--bg) 248px); }
.sidebar { background: var(--side); color: var(--side-ink); padding: 20px 14px; display: flex; flex-direction: column;
  gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 18px; color: var(--side-ink); }
.brand-logo { height: 42px; width: auto; display: block; margin: -6px -8px -6px -10px; }
.brand-sub { font-size: 11.5px; color: var(--side-muted); font-weight: 500; line-height: 1.25; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--side-muted);
  padding: 14px 10px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 8px; color: var(--side-ink);
  font-weight: 500; opacity: .86; }
.nav a:hover { background: var(--side-2); text-decoration: none; opacity: 1; }
.nav a.active { background: var(--side-active); opacity: 1; color: #f2e9de; }
.nav a.active svg { color: var(--yongoq); }
.side-foot { margin-top: auto; border-top: 1px solid var(--side-line); padding-top: 14px; display: flex; align-items: center;
  gap: 10px; }
.side-foot .who { font-size: 13px; color: #f2e9de; font-weight: 550; }
.side-foot .role { font-size: 11.5px; color: var(--side-muted); }
.side-foot a { margin-left: auto; color: var(--side-muted); }
.side-foot .avatar { background: var(--side-active); color: var(--qum); }
.dev-badge { display: inline-block; background: #3a2418; color: #e0a458; border: 1px solid #57391f; font-size: 10.5px;
  font-weight: 700; letter-spacing: .06em; padding: 1px 6px; border-radius: 4px; }

.theme-toggle { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 34px;
  padding: 0 12px; border-radius: 8px; border: 1px solid var(--side-line); background: var(--side-2); color: var(--side-ink);
  font: 500 12.5px var(--font); cursor: pointer; margin: 6px 0 10px; }
.theme-toggle:hover { background: var(--side-active); }
.theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }
.theme-toggle .lbl-dark { display: none; }
:root[data-theme="dark"] .theme-toggle .lbl-dark { display: inline; }
:root[data-theme="dark"] .theme-toggle .lbl-light { display: none; }

.main { min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 24px 32px 0; }
.topbar h1 { font-size: 23px; font-weight: 650; }
.topbar .sub { color: var(--muted); margin-top: 2px; }
.content { padding: 22px 32px 48px; display: flex; flex-direction: column; gap: 20px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px;
  border-bottom: 1px solid var(--line); }
.card-head h2 { font-size: 15px; font-weight: 620; }
.card-head .muted { font-size: 13px; }
.card-body { padding: 18px; }
.grid { display: grid; gap: 20px; }
.g-2 { grid-template-columns: 1fr 1fr; }
.g-3-1 { grid-template-columns: 2fr 1fr; }
.g-1-2 { grid-template-columns: 1fr 2fr; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.kpi .value { font-size: 27px; font-weight: 650; letter-spacing: -0.02em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .value small { font-size: 14px; color: var(--muted); font-weight: 500; margin-left: 3px; }
.kpi .foot { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.kpi .foot .up { color: var(--ok); font-weight: 600; }

.btn { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2); font: inherit; font-weight: 550;
  cursor: pointer; white-space: nowrap; box-shadow: var(--shadow); }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn svg.i { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--bad); border-color: var(--bad-line); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-ghost { border-color: transparent; box-shadow: none; background: transparent; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 8px;
  border-radius: 20px; white-space: nowrap; border: 1px solid transparent; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge svg.i { width: 13px; height: 13px; }
.b-new { background: var(--info-soft); color: var(--info); border-color: var(--info-line); }
.b-confirmed { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.b-done, .b-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-line); }
.b-cancelled, .b-bad { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-line); }
.b-no_show, .b-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.b-gray { background: var(--surface-2); color: var(--ink-2); border-color: var(--line); }

table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 18px;
  background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.t td { padding: 12px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t tr:hover td { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.t .right { text-align: right; }
.t td .cell-main, .t td .cell-sub, .time-pill, .t td .badge { white-space: nowrap; }
.cell-main { font-weight: 560; color: var(--ink); }
.cell-sub { font-size: 12.5px; color: var(--muted); }
.who-cell { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 650;
  font-size: 12px; display: grid; place-items: center; flex: none; }
.avatar.lg { width: 40px; height: 40px; font-size: 14px; }
.time-pill { font-variant-numeric: tabular-nums; font-weight: 650; background: var(--surface-2); border-radius: 6px;
  padding: 3px 8px; font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 560; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input { height: 38px; padding: 0 12px; border: 1px solid var(--line-strong);
  border-radius: 8px; font: inherit; color: var(--ink); background: var(--surface); width: 100%; box-shadow: var(--shadow); }
textarea.input { height: auto; padding: 10px 12px; min-height: 110px; resize: vertical; line-height: 1.5; }
.input::placeholder { color: var(--muted); opacity: .75; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--focus); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line);
  background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.check-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-check { position: relative; }
.chip-check input { position: absolute; opacity: 0; }
.chip-check span { display: inline-block; padding: 6px 12px; border: 1px solid var(--line-strong); border-radius: 8px;
  cursor: pointer; font-weight: 500; background: var(--surface); }
.chip-check input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.filters { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.filters .input { width: auto; min-width: 170px; }

.flash { padding: 11px 14px; border-radius: 8px; border: 1px solid; font-weight: 500; display: flex; gap: 8px; }
.flash.success { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-line); }
.flash.error { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-line); }

.alert { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--radius);
  border: 1px solid var(--warn-line); background: var(--warn-soft); color: var(--ink); }
.alert svg { color: var(--warn); }
.alert.info { border-color: var(--line-strong); background: var(--accent-soft); }
.alert.info svg { color: var(--accent); }
.alert b { display: block; margin-bottom: 2px; }

.bars { display: flex; align-items: flex-end; gap: 8px; height: 180px; padding: 8px 4px 0; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar .fill { width: 100%; max-width: 44px; background: var(--accent-soft); border-radius: 5px 5px 2px 2px; min-height: 3px; }
.bar.cur .fill { background: var(--accent); }
.bar .lbl { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar .val { font-size: 11px; color: var(--ink-2); font-weight: 600; font-variant-numeric: tabular-nums; }

.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 10px 16px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 520; }

.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; background: var(--surface-2);
  border: 1px solid var(--line); padding: 2px 7px; border-radius: 6px; }
.big-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 22px; letter-spacing: .15em;
  font-weight: 650; }
.empty { padding: 40px 18px; text-align: center; color: var(--muted); }

/* chats */
.chat-wrap { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 140px); min-height: 520px; overflow: hidden; }
.chat-list { border-right: 1px solid var(--line); overflow-y: auto; }
.chat-item { display: flex; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); color: var(--ink); }
.chat-item:hover { background: var(--surface-2); text-decoration: none; }
.chat-item.active { background: var(--accent-soft); }
.chat-item .grow { flex: 1; min-width: 0; }
.chat-main { display: flex; flex-direction: column; min-width: 0; }
.chat-head { padding: 14px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.chat-body { flex: 1; overflow-y: auto; padding: 22px; background: var(--bg); display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 68%; padding: 9px 13px; border-radius: 14px; font-size: 14px; line-height: 1.45; }
.msg .meta { font-size: 11px; margin-top: 4px; opacity: .7; display: flex; gap: 6px; align-items: center; }
.msg.user { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.assistant { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.voice-tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; background: var(--surface-2);
  color: var(--muted); padding: 1px 6px; border-radius: 4px; margin-bottom: 4px; }
.voice-tag svg.i { width: 12px; height: 12px; }

/* login */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-side { background: var(--side); color: var(--side-ink); padding: 48px; display: flex; flex-direction: column;
  justify-content: space-between; position: relative; overflow: hidden; }
.auth-side::after { content: ""; position: absolute; width: 560px; height: 560px; right: -200px; bottom: -220px;
  border-radius: 50%; background: radial-gradient(circle, rgba(168,132,98,.32), transparent 65%); }
.auth-side h2 { font-size: 32px; line-height: 1.18; color: #f2e9de; max-width: 440px; font-weight: 650; text-wrap: balance; }
.auth-side p { color: var(--side-muted); max-width: 420px; }
.auth-points { display: flex; flex-direction: column; gap: 12px; margin-top: 26px; position: relative; z-index: 1; }
.auth-points div { display: flex; gap: 10px; align-items: center; color: var(--side-ink); }
.auth-points svg { color: var(--yongoq); }
.auth-form { display: grid; place-items: center; padding: 32px; background: var(--bg); position: relative; }
.auth-form .theme-toggle { position: absolute; top: 20px; right: 20px; margin: 0; background: var(--surface); color: var(--ink-2);
  border-color: var(--line); }
.auth-box { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; }
.auth-box h1 { font-size: 27px; font-weight: 650; }

.steps { counter-reset: s; display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 0; list-style: none; }
.steps li { counter-increment: s; display: flex; gap: 12px; align-items: flex-start; }
.steps li::before { content: counter(s); width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent); font-weight: 700; font-size: 12px; display: grid; place-items: center; flex: none; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .g-2, .g-3-1, .g-1-2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; background: var(--bg); }
  .sidebar { position: static; height: auto; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .auth { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .chat-wrap { grid-template-columns: 1fr; }
  .t { display: block; overflow-x: auto; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
