:root {
  --bg: #f6f4f1; --surface: #ffffff; --surface-2: #f1eee9; --line: #e4dfd7; --line-2: #d6cfc4;
  --ink: #1f1b24; --ink-2: #5d5664; --ink-3: #8a8390;
  --accent: #5b3fa6; --accent-ink: #ffffff; --accent-soft: #ece6f8; --accent-line: #cdbff0;
  --ok: #1f7a4d; --ok-soft: #e1f3e9; --warn: #9a5b00; --warn-soft: #fbefd9; --bad: #b42335; --bad-soft: #fbe4e7;
  --radius: 14px; --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(31, 27, 36, .05), 0 4px 16px rgba(31, 27, 36, .04);
  --font: 'Onest', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15131a; --surface: #1e1b25; --surface-2: #262230; --line: #322d3d; --line-2: #403a4d;
    --ink: #f1eef6; --ink-2: #bdb6c8; --ink-3: #8c8597;
    --accent: #a48af0; --accent-ink: #15131a; --accent-soft: #2e2645; --accent-line: #4b3e78;
    --ok: #5fd39a; --ok-soft: #173326; --warn: #f0b75a; --warn-soft: #3a2b12; --bad: #ff7d8d; --bad-soft: #3d1a20;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.block { display: block; }
.grow { flex: 1; min-width: 0; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.w100 { width: 100%; }

/* ---------- оформление ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 14px;
  padding: 22px 14px; background: var(--surface); border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 19px; color: var(--ink); padding: 0 8px; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink); font-size: 17px; }
.brand-lg { font-size: 22px; padding: 0; margin-bottom: 22px; }
.brand-lg .brand-mark { width: 38px; height: 38px; font-size: 20px; }
.clinic-name { padding: 0 8px; color: var(--ink-2); font-size: 13px; font-weight: 500; }
.clinic-pick select { width: 100%; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { display: flex; align-items: center; justify-content: space-between; padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--ink-2); font-weight: 500; }
nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
nav a.on { background: var(--accent-soft); color: var(--accent); }
.count { min-width: 22px; padding: 1px 7px; border-radius: 99px; background: var(--warn); color: #fff; font-size: 12px; text-align: center; font-weight: 600; }
.me { margin-top: auto; position: relative; }
.me-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border: 0; background: none; border-radius: var(--radius-sm); cursor: pointer; text-align: left; }
.me-btn:hover { background: var(--surface-2); }
.avatar { display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--surface-2); font-weight: 600; }
.me-text { display: flex; flex-direction: column; min-width: 0; }
.me-text > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-menu { position: absolute; bottom: 100%; left: 0; right: 0; margin-bottom: 6px; padding: 6px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow); }
.me-menu button { display: block; width: 100%; padding: 8px 10px; border: 0; background: none; text-align: left; border-radius: 7px; cursor: pointer; }
.me-menu button:hover { background: var(--surface-2); }
.content { padding: 32px clamp(16px, 4vw, 44px) 64px; max-width: 1180px; width: 100%; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: sticky; z-index: 5; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; gap: 10px;
    border-right: 0; border-bottom: 1px solid var(--line); }
  .clinic-name, .clinic-pick { order: 2; flex: 1; }
  nav { order: 4; flex-direction: row; width: 100%; overflow-x: auto; gap: 4px; padding-bottom: 2px; scrollbar-width: none; }
  nav a { white-space: nowrap; padding: 7px 10px; gap: 6px; }
  .me { order: 3; margin: 0; }
  .me-text { display: none; }
  .me-menu { bottom: auto; top: 100%; left: auto; right: 0; width: 190px; margin: 6px 0 0; }
  .content { padding-top: 22px; }
  h1 { font-size: 22px; }
}

/* ---------- заглавие на страница ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head .sub { margin: 4px 0 0; color: var(--ink-2); max-width: 680px; }
.toolbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }

/* ---------- карти ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.flush { padding: 4px 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head a { font-size: 14px; font-weight: 500; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 16px; }
.cards .card { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 16px; }
.grid-2 .card { margin: 0; }
.sub-h { font-size: 14px; color: var(--ink-2); margin: 18px 0 6px; font-weight: 600; }
.hint { color: var(--ink-2); font-size: 13.5px; margin: 8px 0 0; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { display: flex; flex-direction: column; gap: 2px; padding: 16px 18px; text-align: left; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); cursor: pointer; transition: border-color .15s, transform .15s; }
.kpi:not(.static):hover { border-color: var(--accent-line); transform: translateY(-1px); }
.kpi.static { cursor: default; }
.kpi-value { font-size: 30px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-label { color: var(--ink-2); font-size: 13.5px; }
.kpi-warn .kpi-value { color: var(--warn); }
.kpi-bad .kpi-value { color: var(--bad); }

/* ---------- списъци ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list .row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.list .row:first-child { border-top: 0; }
.list .row-top { align-items: flex-start; }
.list.compact .row { padding: 6px 0; }
.time { flex: none; min-width: 52px; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }
.row-top .time, .calls .time { min-width: 116px; font-weight: 500; color: var(--ink-2); font-size: 14px; }
.phone { font-variant-numeric: tabular-nums; font-size: 14px; white-space: nowrap; }
.is-cancelled strong, .is-cancelled .time { text-decoration: line-through; color: var(--ink-3); }
.day { padding-top: 14px; }
.day-title { font-size: 15px; margin-bottom: 4px; text-transform: capitalize; }

.calls .call { border-top: 1px solid var(--line); }
.calls .call:first-child { border-top: 0; }
.call-row { display: flex; align-items: flex-start; gap: 12px; width: 100%; padding: 12px 20px; border: 0; background: none; text-align: left; cursor: pointer; }
.call-row:hover { background: var(--surface-2); }
.call.open .call-row { background: var(--surface-2); }
.badges { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.call-detail { padding: 4px 20px 18px 148px; background: var(--surface-2); }
@media (max-width: 640px) {
  .call-row { flex-wrap: wrap; }
  .call-row .grow { flex-basis: 100%; order: 3; }
  .call-detail { padding-left: 20px; }
}
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
.kv dt { color: var(--ink-2); font-size: 13.5px; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.kv-line { margin: 12px 0 0; }
.more { text-align: center; margin: 8px 0; }

/* ---------- значки ---------- */
.badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.badge-ai { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }

/* ---------- бутони и форми ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:not(:disabled):hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: var(--line-2); color: var(--ink); }
.btn-ghost:not(:disabled):hover { background: var(--surface-2); }
.btn-sm { padding: 5px 11px; font-size: 13px; }
.icon-btn { border: 0; background: none; width: 30px; height: 30px; border-radius: 8px; cursor: pointer; color: var(--ink-2); flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 4px; font-weight: 500; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; font-weight: 500; color: var(--ink-2); }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > label { flex: 1 1 140px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=time], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); font-size: 15px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; }
textarea.autogrow { resize: none; overflow: hidden; min-height: 64px; line-height: 1.45; }
.counter { align-self: flex-end; font-size: 12px; font-weight: 400; font-variant-numeric: tabular-nums; }
.price-note { white-space: pre-wrap; }
.cost { font-size: 12px; color: var(--ink-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.admin-only { border-style: dashed; }
.admin-tag { font-size: 12px; color: var(--ink-2); font-weight: 500; }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 14px; cursor: pointer; }
.err-text { color: var(--bad); margin: 0; }
.warn-text { color: var(--warn); margin: 0; }

.seg { display: inline-flex; padding: 3px; background: var(--surface-2); border-radius: 11px; border: 1px solid var(--line); flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 6px 13px; border-radius: 8px; cursor: pointer; font-weight: 500; color: var(--ink-2); font-size: 14px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- цени ---------- */
.price h2 { font-size: 16px; }
.price-big { font-size: 24px; font-weight: 700; margin: 6px 0 2px; }
.say { margin: 0; padding: 10px 12px; background: var(--accent-soft); border-radius: var(--radius-sm); font-size: 14px; color: var(--ink-2); }
.say em { color: var(--ink); font-style: normal; font-weight: 500; }

/* ---------- обратни обаждания ---------- */
.fu { display: flex; flex-direction: column; gap: 8px; }
.fu-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.fu-phone { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.fu-reason { margin: 0; }
.fu details summary { cursor: pointer; color: var(--ink-2); font-size: 13.5px; }
.fu-actions { margin-top: auto; padding-top: 4px; }
.fu-done { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-top: auto; }
.fu-done p { margin: 0; }

/* ---------- работно време ---------- */
.week { display: flex; flex-direction: column; }
.wd { display: grid; grid-template-columns: 130px 1fr auto; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.wd:first-child { border-top: 0; }
.wd-name { font-weight: 600; }
.wd.off .wd-name { color: var(--ink-3); }
.wd-iv { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.iv { display: inline-flex; align-items: center; gap: 6px; padding: 4px 4px 4px 6px; background: var(--surface-2); border-radius: var(--radius-sm); }
.iv input[type=time] { width: 112px; padding: 6px 8px; }
.wd-act { display: flex; gap: 6px; }
@media (max-width: 640px) {
  .wd { grid-template-columns: 1fr auto; }
  .wd-iv { grid-column: 1 / -1; order: 3; }
}
.locked { background: var(--surface-2); box-shadow: none; }
.num-field { max-width: 320px; }
.lock { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.hours-ro { grid-template-columns: 130px 1fr; }

/* ---------- статистика ---------- */
.legend { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 13px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-left: 8px; }
.sw-calls, .bar-calls { background: var(--line-2); }
.sw-booked, .bar-booked { background: var(--accent); }
.bars { display: flex; align-items: stretch; gap: 4px; height: 220px; overflow-x: auto; padding-top: 18px; }
.bar-col { flex: 1 0 18px; display: flex; flex-direction: column; gap: 6px; min-width: 18px; }
.bar-pair { flex: 1; display: flex; align-items: flex-end; gap: 2px; justify-content: center; }
.bar { position: relative; flex: 1; max-width: 22px; min-height: 2px; border-radius: 4px 4px 1px 1px; }
.bar b { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--ink-2); font-weight: 600; padding-bottom: 2px; }
.bar-label { font-size: 11px; color: var(--ink-3); text-align: center; font-variant-numeric: tabular-nums; }
.hbars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.hbars li { display: grid; grid-template-columns: minmax(120px, 260px) 1fr 36px; gap: 12px; align-items: center; }
.hb-track { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.hb-fill { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.hb-val { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- състояния ---------- */
.state { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 48px 16px; color: var(--ink-2); text-align: center; }
.state-empty { padding: 28px 16px; }
.spin { width: 18px; height: 18px; border: 2px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.alert { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: var(--radius-sm); margin: 0 0 16px; }
.alert-err { background: var(--bad-soft); color: var(--bad); }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; max-width: min(92vw, 520px);
  padding: 12px 18px; border-radius: 12px; background: var(--ink); color: var(--bg); box-shadow: 0 8px 30px rgba(0,0,0,.2); font-weight: 500; }
.toast-err { background: var(--bad); color: #fff; }
.toast-warn { background: var(--warn); color: #fff; }

/* ---------- модал ---------- */
.modal-bg { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgba(20, 16, 26, .45); }
.modal { width: min(100%, 520px); max-height: 90vh; overflow: auto; background: var(--surface); border-radius: var(--radius); padding: 20px 22px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.modal p { margin-top: 0; }

/* ---------- вход ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(100%, 400px); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 30px 28px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 21px; margin-bottom: 18px; }
.auth-card .form p { margin: 0; }
