/* Токены и компоненты — из макета Modernist.
   Ноль скруглений, плотная сетка с зазором 2px, сильные линии 2px,
   крупные числа. Цвета не хардкодятся нигде, кроме этого блока. */

@import url('https://fonts.googleapis.com/css2?family=Archivo:wght@400;600;800&display=swap');

:root,
[data-th="light"] {
  --bg:#f3f2f2; --sf:#ffffff; --sf2:#eae9e9; --tx:#201e1d; --mut:#706c6a;
  --dv:rgba(32,30,29,.42); --dvw:rgba(32,30,29,.14);
  --acc:#ec3013; --accw:#ffe0d9;
  --ok:#1f6f57; --low:#8a5900; --out:#c22a10;
  --okbg:#dcece5; --lowbg:#f5e7cc; --outbg:#ffdfd8;
  --c1:#1f4e9c; --c2:#6b4c9a; --c3:#1f7480; --c4:#7a5c2e; --c5:#59636e; --c6:#a53a7a;
  --r1:#2d2b2b; --r2:#605d5d; --r3:#9b9797; --r4:#d7d3d3; --r5:#eae7e7;
}

/* Тёмная тема — не инверсия светлой: шаги подобраны заново под тёмную подложку,
   иначе акцент и статусы теряют различимость. */
[data-th="dark"] {
  --bg:#141312; --sf:#1e1c1b; --sf2:#272423; --tx:#f2efec; --mut:#a49e99;
  --dv:rgba(242,239,236,.34); --dvw:rgba(242,239,236,.13);
  --acc:#ff5c40; --accw:#4a1d13;
  --ok:#5ec79b; --low:#e3ad4d; --out:#ff6a52;
  --okbg:#16332a; --lowbg:#392c15; --outbg:#3f1a12;
  --c1:#7aa7f0; --c2:#b48ce6; --c3:#4fb3c4; --c4:#c9a06a; --c5:#98a4b0; --c6:#e28ab8;
  --r1:#efeae6; --r2:#b8b2ad; --r3:#7d7773; --r4:#4a4644; --r5:#332f2e;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--tx);
  font-family: 'Archivo', system-ui, 'Segoe UI', Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea, select { font-family: inherit; }
button { cursor: pointer; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
::selection { background: var(--accw); }

/* ── каркас ─────────────────────────────────────────────────────────── */

#app { display: flex; flex-direction: column; min-height: 100dvh; }
.view { flex: 1; padding-bottom: 24px; }
.hidden { display: none !important; }

.tabbar {
  position: sticky; bottom: 0; z-index: 20;
  /* minmax(0,…), а не просто 1fr: иначе колонка не может стать уже своего
     текста, «Статистика» распирает полосу и вкладки разъезжаются по ширине. */
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  border-top: 2px solid var(--dv); background: var(--sf);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  min-height: 64px; border: 0; background: transparent; padding: 0 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 5px; color: var(--mut); font-size: 10px; font-weight: 800;
  letter-spacing: -.02em;
}
/* Подпись скорее подрежется многоточием, чем сломает полосу: с шестой вкладкой
   на узком телефоне на колонку остаётся 53px. */
.tabbar button div {
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tabbar button[aria-current="page"] { color: var(--acc); }

.sidebar { display: none; }

/* ── типографика ────────────────────────────────────────────────────── */

.kicker {
  font-size: 12px; letter-spacing: .09em; text-transform: uppercase; color: var(--mut);
}
.h1 { font-size: 28px; font-weight: 800; letter-spacing: -.03em; line-height: 1.15; }
.h2 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.h3 { font-size: 17px; font-weight: 800; }
.muted { color: var(--mut); }
.hero { font-size: 52px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.num { font-weight: 800; font-variant-numeric: tabular-nums; }
.rule { height: 2px; background: var(--dv); border: 0; margin: 0; }

.pad { padding: 16px; }
.pad-x { padding-left: 16px; padding-right: 16px; }
.stack { display: flex; flex-direction: column; gap: 2px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.spacer { height: 20px; }

/* ── кнопки ─────────────────────────────────────────────────────────── */

.btn {
  min-height: 48px; padding: 0 16px; border: 1px solid var(--dv);
  background: transparent; color: var(--tx);
  font-size: 15px; font-weight: 800; text-align: left;
  display: inline-flex; align-items: center; gap: 8px;
}
.btn:hover { background: var(--sf2); }
.btn-primary { border-color: var(--acc); background: var(--acc); color: #fff; }
.btn-primary:hover { background: var(--acc); filter: brightness(.92); }
.btn-quiet { border-color: transparent; color: var(--mut); }
.btn-quiet:hover { background: var(--sf2); }
.btn-link {
  border: 0; background: transparent; color: var(--acc);
  font-weight: 800; font-size: 14px; padding: 6px 0; min-height: 0;
}
.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: 18px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-center { justify-content: center; text-align: center; }

.seg { display: flex; gap: 2px; }
.seg button {
  flex: 1; min-height: 44px; border: 1px solid var(--dv);
  background: transparent; color: var(--tx); font-size: 14px; font-weight: 800;
}
.seg button[aria-pressed="true"] { background: var(--tx); color: var(--bg); border-color: var(--tx); }

/* ── поля ───────────────────────────────────────────────────────────── */

.input {
  width: 100%; min-height: 48px; padding: 0 14px;
  border: 1px solid var(--dv); background: var(--sf); color: var(--tx);
  font-size: 16px; border-radius: 0;
}
textarea.input { min-height: 84px; padding: 12px 14px; line-height: 1.5; resize: vertical; }
.input-big { min-height: 56px; font-size: 22px; font-weight: 800; }
.input::placeholder { color: var(--mut); }

/* ── карточки списков ───────────────────────────────────────────────── */

.card { background: var(--sf); padding: 13px 14px; }
.card-accent { border-left: 3px solid var(--acc); }
.card-flat { background: var(--sf2); }
.card-done { background: var(--sf2); opacity: .72; }
.tile { background: var(--sf); padding: 14px; }
.tile .kicker { font-size: 11px; letter-spacing: .08em; }
.tile-value { font-size: 30px; font-weight: 800; letter-spacing: -.03em; margin-top: 6px; line-height: 1.05; }
.empty {
  background: var(--sf); border: 2px solid var(--dvw); padding: 24px 18px; margin: 16px;
}
.empty-dashed { border-style: dashed; }

.avatar {
  width: 38px; height: 38px; flex: none; background: var(--sf2);
  display: flex; align-items: center; justify-content: center; font-weight: 800;
}
.check {
  width: 20px; height: 20px; flex: none; background: var(--ok); color: var(--bg);
  font-size: 13px; font-weight: 800; display: flex; align-items: center; justify-content: center;
}

/* ── статусы склада ─────────────────────────────────────────────────── */

.st-ok   { --st: var(--ok);  --stbg: var(--okbg); }
.st-low  { --st: var(--low); --stbg: var(--lowbg); }
.st-out  { --st: var(--out); --stbg: var(--outbg); }
.st-badge {
  width: 16px; height: 16px; flex: none; background: var(--stbg); color: var(--st);
  font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center;
}
.st-word { font-size: 13px; font-weight: 800; color: var(--st); }
.meter { height: 4px; background: var(--sf2); }
.meter > i { display: block; height: 4px; background: var(--st); }

/* ── календарь ──────────────────────────────────────────────────────── */

.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal .wd { font-size: 11px; color: var(--mut); text-align: center; padding-bottom: 4px; }
.cal button {
  position: relative; height: 48px; border: 0; background: var(--sf2); color: var(--tx);
  font-size: 16px; font-weight: 400;
}
.cal button.other { background: transparent; color: var(--mut); opacity: .4; }
.cal button.today { border: 2px solid var(--tx); font-weight: 800; }
.cal button[aria-pressed="true"] { background: var(--acc); color: #fff; font-weight: 800; }
.cal .cnt {
  position: absolute; top: 3px; right: 5px; font-size: 11px; font-weight: 800; color: var(--acc);
}
.cal button[aria-pressed="true"] .cnt { color: #fff; }

.slotgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; }
.slotgrid button {
  min-height: 48px; border: 1px solid var(--dv); background: transparent; color: var(--tx);
  font-size: 14px; font-weight: 800;
}
.slotgrid button[aria-pressed="true"] { background: var(--acc); color: #fff; border-color: var(--acc); }
.slotgrid button:disabled { background: var(--sf2); color: var(--mut); opacity: .55; }

.dayscroll { display: flex; gap: 2px; overflow-x: auto; padding-bottom: 2px; }
.dayscroll button {
  flex: none; min-width: 64px; min-height: 64px; border: 1px solid var(--dv);
  background: transparent; color: var(--tx);
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  gap: 2px; padding: 0 10px;
}
.dayscroll button[aria-pressed="true"] { background: var(--acc); color: #fff; border-color: var(--acc); }
.dayscroll .wd { font-size: 11px; opacity: .75; }
.dayscroll .dn { font-size: 20px; font-weight: 800; }

/* ── графики ────────────────────────────────────────────────────────── */

.chart { background: var(--sf); padding: 14px; }
.chart-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 12px; }
.chart-head .h3 { flex: 1; }
.chart-toggle {
  border: 1px solid var(--dv); background: transparent; color: var(--tx);
  font-size: 12px; font-weight: 800; padding: 7px 10px;
}

.bars { display: flex; align-items: flex-end; gap: 2px; height: 160px; }
.bars .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.bars .val { font-size: 11px; font-weight: 800; text-align: center; height: 14px; }
/* Скругление 4px только на дальнем от базовой линии конце — столбец
   остаётся приклеенным к оси. */
.bars .fill { border-radius: 4px 4px 0 0; background: var(--c1); min-height: 2px; }
.bars .lab { font-size: 11px; color: var(--mut); text-align: center; margin-top: 6px; }

.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar-top { display: flex; gap: 8px; font-size: 13px; margin-bottom: 4px; }
.hbar-track { height: 14px; background: var(--sf2); }
.hbar-track > i { display: block; height: 14px; border-radius: 0 4px 4px 0; }

/* Стопка: зазор 2px цветом подложки, чтобы сегменты не сливались. */
.stack-bars { display: flex; align-items: flex-end; gap: 2px; height: 150px; }
.stack-bars .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.stack-bars .seg-a { background: var(--c1); }
.stack-bars .seg-b { background: var(--c2); border-bottom: 2px solid var(--sf); }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; font-size: 13px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; color: var(--mut); }
.legend i { width: 12px; height: 12px; display: block; }

.heat { display: grid; gap: 2px; overflow-x: auto; }
.heat .cell { height: 26px; background: var(--sf2); font-size: 10px; }
.heat .lab { font-size: 11px; color: var(--mut); display: flex; align-items: center; }
/* Последовательная шкала: один тон от светлого к тёмному, без радуги.
   Ступени фиксированы, чтобы одна и та же нагрузка всегда красилась одинаково. */
.heat .l0 { background: var(--sf2); }
.heat .l1 { background: color-mix(in srgb, var(--c1) 22%, var(--sf2)); }
.heat .l2 { background: color-mix(in srgb, var(--c1) 45%, var(--sf2)); }
.heat .l3 { background: color-mix(in srgb, var(--c1) 70%, var(--sf2)); }
.heat .l4 { background: var(--c1); }
.heat .l3, .heat .l4 { color: var(--bg); }
.heat .cell { display: flex; align-items: center; justify-content: center; font-weight: 800; }

.datatable { width: 100%; border-collapse: collapse; font-size: 14px; }
.datatable th {
  text-align: left; font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--mut); padding: 8px; border-bottom: 2px solid var(--dv); font-weight: 800;
}
.datatable td { padding: 8px; border-bottom: 1px solid var(--dvw); }
.datatable td.n, .datatable th.n { text-align: right; font-variant-numeric: tabular-nums; }

/* ── всплывающие подсказки и тосты ──────────────────────────────────── */

.tip {
  position: fixed; z-index: 60; pointer-events: none;
  background: var(--tx); color: var(--bg); font-size: 12px; font-weight: 800;
  padding: 6px 9px; white-space: nowrap;
}
.toast {
  position: fixed; left: 16px; right: 16px; bottom: 84px; z-index: 50;
  background: var(--tx); color: var(--bg); padding: 14px 16px;
  font-size: 15px; font-weight: 800;
  display: flex; align-items: center; gap: 12px;
}
.toast button { border: 0; background: transparent; color: var(--acc); font-weight: 800; font-size: 15px; }

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 520px; max-height: 88dvh; overflow: auto;
  background: var(--bg); border-top: 2px solid var(--dv);
}

/* ── экран входа ────────────────────────────────────────────────────── */

.login {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: flex-start; justify-content: center; gap: 16px; padding: 32px 24px;
  max-width: 480px; margin: 0 auto;
}

/* ── десктоп ────────────────────────────────────────────────────────── */

@media (min-width: 1024px) {
  body { font-size: 15px; }

  #app { flex-direction: row; }

  /* Боковое меню 212px — как в макете: шапка с названием кабинета,
     пункты с трёхпиксельной меткой активного, блок пользователя внизу. */
  .sidebar {
    display: flex; flex-direction: column; width: 212px; flex: none;
    border-right: 2px solid var(--dv); background: var(--bg);
    height: 100dvh; position: sticky; top: 0;
  }
  .sidebar .brand { padding: 22px 18px 18px; border-bottom: 2px solid var(--dv); }
  .sidebar .brand .kicker { font-size: 11px; letter-spacing: .1em; }
  .sidebar .brand .name {
    font-size: 20px; font-weight: 800; margin-top: 4px; letter-spacing: -.02em;
  }
  .sidebar nav { display: flex; flex-direction: column; }
  .sidebar nav button {
    min-height: 52px; border: 0; border-left: 3px solid transparent;
    background: transparent; color: var(--tx);
    display: flex; align-items: center; gap: 10px; padding: 0 15px;
    font-size: 15px; font-weight: 800; text-align: left;
  }
  .sidebar nav button:hover { background: var(--sf2); }
  .sidebar nav button[aria-current="page"] {
    border-left-color: var(--acc); background: var(--sf); color: var(--acc);
  }
  .sidebar .fill { flex: 1; }
  .sidebar .who {
    padding: 18px; border-top: 2px solid var(--dv);
    display: flex; align-items: center; gap: 10px;
  }
  .sidebar .who .avatar { width: 34px; height: 34px; }
  .sidebar .tools { display: flex; gap: 2px; padding: 0 12px 12px; }
  .sidebar .tools button {
    flex: 1; min-height: 34px; border: 1px solid var(--dv); background: transparent;
    color: var(--mut); font-size: 12px; font-weight: 800; justify-content: center;
  }

  .tabbar { display: none; }

  /* Экраны с правой панелью управляют отступами сами. */
  .view:has(> .split) { padding: 0; max-width: none; }
  .split { display: flex; align-items: stretch; min-height: 100dvh; }
  .split > .main { flex: 1; min-width: 0; padding: 26px 28px; }
  .split > .main.ruled { border-right: 2px solid var(--dv); }
  .split > .rail { width: 380px; flex: none; padding: 26px 24px; }
  .split > .rail.panel { border-left: 2px solid var(--dv); background: var(--sf); padding: 24px; }
  .split > .rail.narrow { width: 360px; }

  .page-head { display: flex; align-items: center; gap: 16px; }
  .page-title { font-size: 30px; font-weight: 800; letter-spacing: -.03em; }

  /* Сетка недели: получасовые строки, подписаны целые часы. */
  .weekgrid { display: grid; grid-template-columns: 56px repeat(7, 1fr); gap: 2px; }
  .weekgrid .head { padding: 6px 8px; background: var(--sf2); }
  .weekgrid .head .wd {
    font-size: 11px; color: var(--mut); text-transform: uppercase; letter-spacing: .08em;
  }
  .weekgrid .head .num { font-size: 17px; font-weight: 800; }
  .weekgrid .head.today .num { color: var(--acc); }
  .weekgrid .hour {
    font-size: 11px; color: var(--mut);
    display: flex; align-items: center; justify-content: flex-end; padding-right: 8px;
  }
  .weekgrid .cell { min-height: 26px; background: var(--sf2); cursor: pointer; }
  .weekgrid .cell:hover { background: var(--accw); }
  .weekgrid .cell.busy {
    background: var(--sf); border-left: 3px solid var(--acc);
    padding: 2px 6px; font-size: 12px; font-weight: 800;
    display: flex; flex-direction: column; justify-content: center;
    overflow: hidden; white-space: nowrap;
  }
  .weekgrid .cell.busy .sub { font-size: 11px; font-weight: 400; color: var(--mut); }
  .weekgrid .cell.busy.done { opacity: .6; border-left-color: var(--ok); }
  .legend-row { display: flex; gap: 18px; margin-top: 16px; font-size: 13px; color: var(--mut); }
  .legend-row > div { display: flex; align-items: center; gap: 8px; }
  .legend-row i { width: 14px; height: 14px; display: block; }

  /* Месяц на десктопе: в ячейке день, число записей и сумма. */
  .monthgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
  .monthgrid .wd {
    font-size: 11px; color: var(--mut); text-transform: uppercase;
    letter-spacing: .08em; padding-bottom: 6px;
  }
  .monthgrid button {
    min-height: 96px; border: 0; background: var(--sf2); color: var(--tx);
    padding: 8px; display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  }
  .monthgrid button.other { background: transparent; color: var(--mut); opacity: .45; }
  .monthgrid button.today { border: 2px solid var(--tx); }
  .monthgrid button:hover { background: var(--accw); }
  .monthgrid .dnum { font-size: 16px; font-weight: 800; }
  .monthgrid .dcnt { font-size: 12px; font-weight: 800; color: var(--acc); }
  .monthgrid .dsum { font-size: 12px; color: var(--mut); }

  .rowbar {
    background: var(--sf); border-left: 3px solid var(--acc); padding: 14px 16px;
    display: flex; align-items: center; gap: 14px; margin-top: 14px;
  }
  .chips { display: flex; gap: 2px; flex-wrap: wrap; }
  .chips button {
    min-height: 38px; padding: 0 12px; border: 1px solid var(--dv);
    background: transparent; color: var(--tx); font-size: 13px; font-weight: 800;
  }
  .chips button[aria-pressed="true"] { background: var(--tx); color: var(--bg); border-color: var(--tx); }

  .datatable th { cursor: pointer; }
  .datatable th[aria-sort] { color: var(--acc); }
  .datatable tbody tr { cursor: pointer; }
  .datatable tbody tr:hover { background: var(--sf2); }
  .datatable tbody tr[aria-selected="true"] { background: var(--accw); }

  .view { padding: 28px 32px 48px; max-width: 1180px; }
  .pad, .pad-x { padding-left: 0; padding-right: 0; }
  .empty { margin: 16px 0; }
  .toast { left: auto; right: 32px; bottom: 32px; max-width: 420px; }

  /* Плотность выше: таблицы вместо карточек, видно больше за раз. */
  .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
  .cols-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
  .kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; }
  .kpis .tile { padding: 18px; }
  .kpis .tile-value { font-size: 40px; margin-top: 8px; }
  .hero { font-size: 64px; }
  .chart { padding: 20px; }
  .chart-head .h3 { font-size: 18px; }
  .cal button { height: 64px; font-size: 18px; }
  .slotgrid { grid-template-columns: repeat(8, 1fr); }
  .bars { height: 220px; }
  .stack-bars { height: 200px; }
  .heat .cell { height: 30px; }
  .sheet-backdrop { align-items: center; }
  .sheet { max-width: 640px; border: 2px solid var(--dv); }
}

@media (max-width: 1023px) {
  .kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
  .cols-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
  .desktop-only { display: none !important; }
}
