:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --card: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: var(--tg-theme-section-separator-color, rgba(0, 0, 0, 0.08));
  --danger: #d9362b;
  --weld: #c77800;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-secondary-bg-color, #000000);
    --card: var(--tg-theme-bg-color, #1c1c1e);
    --text: var(--tg-theme-text-color, #ffffff);
    --hint: var(--tg-theme-hint-color, #8e8e93);
    --line: var(--tg-theme-section-separator-color, rgba(255, 255, 255, 0.1));
    --weld: #e0a040;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
.app { max-width: 560px; margin: 0 auto; padding: 12px 16px 0; }
.num { font-variant-numeric: tabular-nums; }

/* шапка */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0 14px; }
.top h1 { font-size: 20px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.top .sub { color: var(--hint); font-size: 13px; }
.iconbtn {
  width: 36px; height: 36px; border-radius: 10px; border: 0; background: var(--card); color: var(--text);
  font-size: 18px; line-height: 36px; text-align: center; padding: 0; cursor: pointer; flex: none;
}
.iconbtn:active { opacity: 0.6; }
.iconbtn.ghost { background: transparent; color: var(--accent); font-size: 15px; width: auto; padding: 0 4px; }

.monthnav { display: flex; align-items: center; justify-content: space-between; margin: 0 0 12px; }
.monthnav .label { font-size: 17px; font-weight: 600; }

/* карточки */
.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.card h2 { font-size: 13px; font-weight: 500; color: var(--hint); margin: 0 0 8px; text-transform: uppercase; letter-spacing: 0.04em; }
.total { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.total small { font-size: 18px; font-weight: 500; color: var(--hint); margin-left: 4px; }
.split { display: flex; gap: 12px; margin-top: 14px; }
.split .col { flex: 1; min-width: 0; }
.split .k { color: var(--hint); font-size: 13px; }
.split .v { font-size: 17px; font-weight: 600; margin-top: 2px; }
.split .h { color: var(--hint); font-size: 13px; margin-top: 1px; }
.weld .k::before, .tag-weld::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--weld); margin-right: 6px; vertical-align: 1px;
}
.regular .k::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--accent); margin-right: 6px; vertical-align: 1px;
}

.monthsum { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; align-items: baseline; }
.monthsum .k { color: var(--hint); font-size: 14px; }
.monthsum .v { font-size: 17px; font-weight: 600; grid-column: 2; grid-row: 1 / span 2; align-self: center; }
.monthsum .h { color: var(--hint); font-size: 13px; }

/* кнопки */
.btn {
  display: block; width: 100%; border: 0; border-radius: 12px; padding: 14px 16px;
  font-size: 16px; font-weight: 600; cursor: pointer; text-align: center;
  background: var(--accent); color: var(--accent-text);
}
.btn:active { opacity: 0.75; }
.btn:disabled { opacity: 0.5; }
.btn.secondary { background: var(--card); color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); font-weight: 500; }
.btn + .btn { margin-top: 10px; }
.btn.add { background: transparent; color: var(--accent); font-weight: 500; padding: 10px 0; text-align: left; font-size: 15px; }

.topbtns { display: flex; gap: 12px; }

/* админка */
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 15px; }
.kv:first-of-type, h2 + .kv { border-top: 0; }
.kv .k { color: var(--hint); }
.kv .v { text-align: right; }
.listhead { font-size: 13px; font-weight: 500; color: var(--hint); margin: 4px 0 8px 16px; text-transform: uppercase; letter-spacing: 0.04em; }
.row .who { width: 92px; flex: none; min-width: 0; }
.row .who + .mid + .amt { font-size: 15px; }
.row .who b { display: block; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .who span { font-size: 12px; color: var(--hint); }

/* список дней */
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer;
  border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
.row:active { background: var(--bg); }
.row .d { width: 64px; flex: none; }
.row .d b { display: block; font-size: 17px; font-weight: 600; line-height: 1.1; }
.row .d span { font-size: 12px; color: var(--hint); text-transform: capitalize; }
.row .mid { flex: 1; min-width: 0; font-size: 14px; color: var(--hint); }
.row .mid div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .mid .note { font-style: italic; }
.row .mid.wrap div { white-space: normal; font-size: 13px; line-height: 1.3; }
.row .mid.wrap div + div { margin-top: 2px; }
.row .amt { font-weight: 600; font-size: 16px; white-space: nowrap; }
.row .chev { color: var(--hint); font-size: 18px; margin-left: -4px; }
.empty { color: var(--hint); text-align: center; padding: 28px 16px; font-size: 15px; }

/* форма дня */
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.field label { color: var(--text); font-size: 16px; }
input[type="date"], input[type="time"], input[type="number"], input[type="text"] {
  font: inherit; color: var(--text); background: var(--bg); border: 0; border-radius: 10px;
  padding: 10px 12px; min-width: 0; outline: none; -webkit-appearance: none; appearance: none;
}
input[type="date"] { font-size: 16px; }
input[type="time"] { width: 100%; text-align: center; font-size: 17px; font-variant-numeric: tabular-nums; }
input[type="number"] { width: 130px; text-align: right; font-size: 17px; }
input[type="text"] { width: 100%; }
input:focus { box-shadow: 0 0 0 2px var(--accent); }

.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 0 0 6px; }
.section-head h2 { margin: 0; }
.section-head .sum { font-size: 14px; color: var(--hint); }
.ivl { display: grid; grid-template-columns: 1fr 20px 1fr 36px; gap: 8px; align-items: center; padding: 6px 0; }
.ivl .dash { text-align: center; color: var(--hint); padding-top: 18px; }
.ivl .tf { display: block; min-width: 0; }
.ivl .tf span { display: block; font-size: 12px; color: var(--hint); margin: 0 0 4px 2px; }
.ivl input.time { width: 100%; text-align: center; font-size: 20px; font-variant-numeric: tabular-nums; letter-spacing: 0.03em; padding: 10px 8px; }
.ivl input.time::placeholder { color: var(--hint); opacity: 0.55; }
.ivl .del { margin-top: 18px; }
.ivl .mins { grid-column: 1 / -1; font-size: 13px; color: var(--hint); margin-top: -4px; padding-left: 2px; }
.ivl.single { grid-template-columns: 1fr 36px; }
.ivl.single input.range { width: 100%; font-size: 18px; letter-spacing: 0.02em; font-variant-numeric: tabular-nums; text-align: left; padding: 11px 14px; }
.ivl.single input.range::placeholder { color: var(--hint); opacity: 0.7; }
.ivl.manual { grid-template-columns: auto 1fr 36px; }
.ivl.manual .lbl { color: var(--hint); font-size: 15px; padding-right: 4px; }
.ivl.manual input.hours { width: 100%; text-align: center; font-size: 17px; }
.addrow { display: flex; gap: 16px; }
.addrow .btn.add { width: auto; }
.ivl .del {
  width: 36px; height: 40px; border: 0; background: transparent; color: var(--hint); font-size: 20px; cursor: pointer; padding: 0;
}
.ivl .del:active { color: var(--danger); }

.daytotal { display: flex; justify-content: space-between; align-items: baseline; }
.daytotal .big { font-size: 24px; font-weight: 700; }
.hintline { color: var(--hint); font-size: 13px; margin: 2px 0 12px; }
.err { color: var(--danger); font-size: 14px; margin: 0 0 10px; }

/* настройки */
.rate { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.rate:first-of-type { border-top: 0; }
.rate .t { font-size: 16px; }
.rate .t small { display: block; color: var(--hint); font-size: 13px; }
.rate .unit { color: var(--hint); font-size: 14px; margin-left: 6px; }

/* график по неделям */
.chart svg { display: block; overflow: visible; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .bar path { fill: var(--accent); opacity: 0.38; }
.chart .bar.sel path { opacity: 1; }
.chart .bar .val { font-size: 9.5px; fill: var(--hint); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.chart .bar.sel .val { fill: var(--text); font-weight: 600; }
.chart .bar .lbl { font-size: 10.5px; fill: var(--hint); }
.chart .bar.sel .lbl { fill: var(--text); font-weight: 600; }
.chart .bar { cursor: pointer; }
.chart .bar:active path { opacity: 0.7; }
.chart-tip { font-size: 14px; margin-top: 6px; }
.chart-tip[hidden] { display: none; }

/* переключатель */
input.switch { appearance: none; -webkit-appearance: none; width: 48px; height: 28px; border-radius: 14px; background: var(--line); position: relative; margin: 0; cursor: pointer; flex: none; }
input.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
input.switch:checked { background: var(--accent); }
input.switch:checked::after { left: 23px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--card); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: 90vw; z-index: 10; opacity: 0.95;
}
.toast[hidden] { display: none; }

.fade { animation: fade 0.18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .fade { animation: none; } }
