/* Обороти – уеб приложение. Цветовете на марката идват от brands/<марка>/brand.css
   (генерира се от branding/apply.py): --brand, --brand-hover, --on-brand, --ink, --bg, --link, --radius-btn. */

:root {
  --brand: #444;
  --brand-hover: #222;
  --on-brand: #fff;
  --ink: #151515;
  --bg: #f5f5f5;
  --link: #222;
  --radius-btn: 6px;

  --surface: #fff;
  --muted: #5f6368;
  --line: #e3e3e3;
  --track: #ececec;
  --up: #1e7e34;
  --down: #c5221f;
  --prev: #8a8a8a;
  --shadow: 0 1px 3px rgb(0 0 0 / 8%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #ececec;
    --bg: #141414;
    --surface: #1f1f1f;
    --muted: #a8a8a8;
    --line: #333;
    --track: #2c2c2c;
    --up: #5cc97a;
    --down: #ff7a70;
    --prev: #8f8f8f;
    --link: #ececec;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 26px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; margin: 18px 0 8px; }
a { color: var(--link); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.spacer { flex: 1; }

/* ---------- бутони ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 18px;
  border: 1px solid var(--line); border-radius: var(--radius-btn);
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-block { display: flex; width: 100%; min-height: 50px; font-size: 16px; }
.btn-link { border: 0; background: none; color: var(--link); padding: 0 8px; min-height: 32px; text-decoration: underline; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--ink); outline-offset: 2px;
}
.icon-btn {
  position: relative; display: inline-grid; place-items: center;
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: none; color: var(--ink); cursor: pointer;
}
.icon-btn:hover { background: var(--track); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.badge {
  position: absolute; top: 3px; right: 2px; min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px; background: var(--brand); color: var(--on-brand);
  font-size: 11px; font-weight: 700; line-height: 17px; text-align: center;
}

/* ---------- зареждане / вход ---------- */
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--track); border-top-color: var(--brand);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.login-box { width: 100%; max-width: 400px; text-align: center; }
.login-logo { display: block; max-width: 260px; max-height: 80px; margin: 0 auto 24px; }
.login-box h1 { margin-bottom: 4px; }
.login-box > p { margin: 0 0 24px; }
.login-box .small { margin-top: 10px; }
.alert {
  margin: 12px 0; padding: 10px 14px; border-radius: 8px; text-align: left;
  background: color-mix(in srgb, var(--down) 12%, var(--surface)); color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--down) 35%, transparent);
}

/* ---------- горна лента ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 4px;
  height: 58px; padding: 0 8px 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar-logo { height: 28px; max-width: 120px; object-fit: contain; }
.topbar-title { margin-left: 12px; font-size: 18px; font-weight: 600; }
.menu {
  position: absolute; top: 52px; right: 8px; min-width: 220px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 15%); overflow: hidden;
}
.menu-head { display: flex; flex-direction: column; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.menu form { margin: 0; }
.menu-item {
  display: block; width: 100%; padding: 12px 16px; border: 0; background: none;
  color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
.menu-item:hover { background: var(--track); }

/* ---------- съдържание ---------- */
.content { max-width: 1100px; margin: 0 auto; padding: 12px 16px 40px; }
.segmented {
  display: flex; width: 100%; border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; background: var(--surface);
}
.segmented button {
  flex: 1; min-height: 40px; padding: 0 6px; border: 0; border-left: 1px solid var(--line);
  background: none; color: var(--ink); font: inherit; cursor: pointer; white-space: nowrap;
}
.segmented button:first-child { border-left: 0; }
.segmented button.on { background: var(--brand); color: var(--on-brand); font-weight: 600; }
.segmented.small { width: auto; }
.segmented.small button { min-height: 32px; padding: 0 12px; font-size: 13.5px; }

.custom-range { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; margin-top: 10px; }
.custom-range label { display: flex; flex-direction: column; font-size: 12.5px; color: var(--muted); gap: 2px; }
input[type=date], .search {
  min-height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink); font: inherit;
}
.period-line { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; margin: 6px 2px 0; }
.period-line #period-title { font-weight: 600; min-width: 11ch; text-align: center; }
.period-nav { display: inline-flex; align-items: center; gap: 2px; margin-left: -10px; }
.period-nav .icon-btn { width: 36px; height: 36px; }
.icon-btn:disabled { opacity: .3; cursor: default; background: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface);
  color: var(--ink); font: inherit; font-size: 13.5px; cursor: pointer;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--on-brand); font-weight: 600; }
.chip .x { font-size: 16px; line-height: 1; opacity: 0.7; }

.progress { height: 3px; margin-top: 10px; overflow: hidden; background: var(--track); border-radius: 2px; }
.progress div { width: 40%; height: 100%; background: var(--brand); animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.section { margin-top: 22px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 2px 8px; }

/* ---------- показатели ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
@media (min-width: 760px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { padding: 14px; }
.kpi-title { color: var(--muted); font-size: 13px; }
.kpi-value { margin: 6px 0 4px; font-size: clamp(18px, 4.6vw, 24px); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-prev { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.change { font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.change.up { color: var(--up); }
.change.down { color: var(--down); }

/* ---------- графика ---------- */
.chart-card { padding: 12px 12px 8px 4px; }
.chart { position: relative; height: 240px; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10.5px; }
.chart .cur { fill: none; stroke: var(--brand); stroke-width: 2.5; stroke-linejoin: round; }
.chart .prev { fill: none; stroke: var(--prev); stroke-width: 1.8; stroke-dasharray: 6 4; }
.chart .area { fill: var(--brand); opacity: 0.12; stroke: none; }
.chart .dot { fill: var(--brand); }
.chart .dot-on { fill: var(--surface); stroke: var(--brand); stroke-width: 3; }
.chart .dot-prev { fill: var(--surface); stroke: var(--prev); stroke-width: 2; }
.chart .hover-line { stroke: var(--muted); stroke-width: 1; }
.chart .empty { fill: var(--muted); font-size: 14px; }
.legend { display: flex; justify-content: center; gap: 18px; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 18px; margin-right: 6px; vertical-align: middle; }
.lg-cur { border-top: 3px solid var(--brand); }
.lg-prev { border-top: 2px dashed var(--prev); }
.tooltip {
  position: fixed; z-index: 20; pointer-events: none; padding: 8px 10px; border-radius: 8px;
  background: var(--ink); color: var(--bg); font-size: 12.5px; line-height: 1.45; white-space: nowrap;
}

/* ---------- разбивка ---------- */
.list { overflow: hidden; margin-top: 10px; }
.list .empty { padding: 28px; text-align: center; color: var(--muted); }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 10px 12px 16px;
  border: 0; border-top: 1px solid var(--line); background: none; color: var(--ink);
  font: inherit; text-align: left;
}
.row:first-child { border-top: 0; }
button.row { cursor: pointer; }
button.row:hover { background: var(--track); }
.row-main { flex: 1; min-width: 0; }
.row-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 6px; margin: 6px 0; border-radius: 3px; background: var(--track); overflow: hidden; }
.bar div { height: 100%; background: var(--brand); border-radius: 3px; }
.row-sub { color: var(--muted); font-size: 12.5px; }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.row-value { font-weight: 700; white-space: nowrap; }
.row-prev { color: var(--muted); font-size: 12px; white-space: nowrap; }
.chev { width: 18px; color: var(--muted); font-size: 20px; text-align: center; }

/* ---------- филтри ---------- */
.sheet {
  width: min(560px, 100vw); max-height: 88vh; padding: 0; border: 0; border-radius: 14px;
  background: var(--surface); color: var(--ink);
}
.sheet::backdrop { background: rgb(0 0 0 / 40%); }
.sheet form { display: flex; flex-direction: column; max-height: 88vh; padding: 18px 18px 0; }
.search { width: 100%; margin-bottom: 6px; }
.sheet-body { overflow-y: auto; min-height: 0; }
.checklist { overflow-y: auto; max-height: 34vh; border-top: 1px solid var(--line); }
.checklist .sub { padding-left: 30px; }
.checklist .expand {
  margin-left: auto; padding: 2px 8px; border: 1px solid var(--line); border-radius: 12px;
  background: none; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap;
}
.check-head { padding: 10px 2px 4px; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; }
.checklist .empty { padding: 12px 2px; }
.chip-clear { border-style: dashed; color: var(--muted); }
.checklist label {
  display: flex; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.checklist input { width: 18px; height: 18px; accent-color: var(--brand); }
.sheet-actions {
  position: sticky; bottom: 0; display: flex; gap: 8px; padding: 14px 0 18px; background: var(--surface);
}
@media (max-width: 600px) {
  .sheet { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 14px 14px 0 0; }
  .segmented button { font-size: 13.5px; }
}

/* тъмна тема: логата са за светъл фон */
@media (prefers-color-scheme: dark) {
  .brand-logo { background: #fff; padding: 4px 8px; border-radius: 6px; }
  .login-logo { padding: 10px 14px; }
}
#trend-note { font-weight: 400; margin-left: 4px; }

/* ---------- изгледи: табло / обекти ---------- */
.view-tabs { display: inline-flex; margin-left: 14px; border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.view-tabs button {
  padding: 6px 14px; border: 0; background: none; color: var(--ink); font: inherit; font-size: 14px; cursor: pointer;
}
.view-tabs button.on { background: var(--brand); color: var(--on-brand); font-weight: 600; }
@media (max-width: 520px) {
  .topbar-title { display: none; }
  .view-tabs { margin-left: 8px; }
  .view-tabs button { padding: 6px 10px; font-size: 13px; }
}

/* ---------- сравнение на обектите ---------- */
.table-wrap { overflow-x: auto; }
table.sites { width: 100%; border-collapse: collapse; font-size: 14px; }
table.sites th, table.sites td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; white-space: nowrap; }
table.sites thead th { position: sticky; top: 0; background: var(--surface); font-size: 12.5px; font-weight: 600; color: var(--muted); }
table.sites thead button { padding: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; }
table.sites thead th[aria-sort] { color: var(--ink); }
table.sites .name { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; }
table.sites tbody .name { font-weight: 600; }
table.sites .link { padding: 0; border: 0; background: none; color: var(--ink); font: inherit; cursor: pointer; text-align: left; }
table.sites .link:hover { color: var(--link); text-decoration: underline; }
table.sites .strong { font-weight: 700; }
table.sites .bar { margin-top: 6px; min-width: 110px; }
table.sites .change { display: block; }
table.sites tr.none td, table.sites tr.none th { color: var(--muted); font-weight: 400; }
table.sites tfoot th, table.sites tfoot td { border-bottom: 0; font-weight: 700; }
table.sites tbody tr:hover td, table.sites tbody tr:hover th { background: color-mix(in srgb, var(--track) 55%, var(--surface)); }
.spark { width: 96px; height: 26px; display: block; }
.spark polyline { fill: none; stroke: var(--brand); stroke-width: 1.6; stroke-linejoin: round; }
@media (max-width: 760px) { .spark-col { display: none; } }
