/* Панель дня. Цвета токенами: светлая и тёмная тема системы, в Mini App их
   переопределяет app.js из Telegram.WebApp.themeParams. */
:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --hint: #6e6e73;
  --line: #e5e5ea;
  --link: #0a66d6;
  --button: #0a84ff;
  --button-text: #ffffff;
  --accent: #1f9d55;
  --accent-soft: rgba(31, 157, 85, 0.12);
  --danger: #d70015;
  --warn: #b25000;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --hint: #98989f;
    --line: #2c2c2e;
    --link: #5eb1ff;
    --button: #0a84ff;
    --button-text: #ffffff;
    --accent: #32d74b;
    --accent-soft: rgba(50, 215, 75, 0.14);
    --danger: #ff453a;
    --warn: #ff9f0a;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #000000;
  --card: #1c1c1e;
  --text: #f2f2f7;
  --hint: #98989f;
  --line: #2c2c2e;
  --link: #5eb1ff;
  --accent: #32d74b;
  --accent-soft: rgba(50, 215, 75, 0.14);
  --danger: #ff453a;
  --warn: #ff9f0a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
}

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0 12px;
}

h1 { font-size: 22px; margin: 0; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--hint); margin: 0 0 10px; font-weight: 600; }

.hint { color: var(--hint); margin: 2px 0 0; }
.small-text { font-size: 13px; }

.grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.col { display: grid; gap: 12px; align-content: start; min-width: 0; }

@media (min-width: 900px) {
  .grid { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; }
  .col { gap: 16px; }
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0;
}

.list { display: grid; gap: 2px; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  min-width: 0;
}
.list > .row:first-child { border-top: 0; }

.row-main { flex: 1 1 auto; min-width: 0; }
.row-title {
  display: block;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  overflow-wrap: anywhere;
}
a.row-title:hover { color: var(--link); }
.row-meta { font-size: 13px; color: var(--hint); overflow-wrap: anywhere; }
.row-meta .overdue { color: var(--danger); }

.running { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; border-top: 0; margin-bottom: 6px; }
.clock { font-variant-numeric: tabular-nums; font-size: 26px; font-weight: 600; color: var(--accent); letter-spacing: 0.01em; }

button {
  font: inherit;
  border: 0;
  border-radius: 10px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 16px;
  background: var(--button);
  color: var(--button-text);
  font-weight: 600;
  cursor: pointer;
  flex: 0 0 auto;
  touch-action: manipulation;
}
button:disabled { opacity: 0.55; cursor: default; }
button.stop { background: var(--danger); color: #fff; }
button.big { min-height: 52px; min-width: 96px; font-size: 17px; }
button.ghost { background: transparent; color: var(--link); padding: 0 8px; }
button.small { min-height: 36px; font-size: 14px; }
button.more { margin-top: 4px; }
button.pause { background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }

/* Кнопки строки «Сейчас»: у идущего Пауза над Стоп, у паузы Продолжить и маленький Стоп */
.actions { display: flex; gap: 6px; flex: 0 0 auto; align-items: stretch; }
.actions.stack { flex-direction: column; }
.paused { border-radius: 10px; padding: 8px 12px; border-top: 0; margin-bottom: 6px; box-shadow: inset 0 0 0 1px var(--line); }
.paused .row-title { font-weight: 500; }

.search {
  width: 100%;
  min-height: 44px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  margin-bottom: 6px;
}

select {
  font: inherit;
  min-height: 44px;
  max-width: 100%;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 8px;
}

.total { font-size: 24px; font-weight: 600; margin: 0; }
.total .of { font-size: 15px; color: var(--hint); font-weight: 400; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 8px 0 10px; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.over > span { background: var(--warn); }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line); }
.kv:first-child { border-top: 0; }
.kv .k { min-width: 0; overflow-wrap: anywhere; }
.kv .v { color: var(--hint); font-variant-numeric: tabular-nums; white-space: nowrap; }

.marks { font-size: 13px; color: var(--warn); margin: 6px 0 0; }
.line { margin: 0; overflow-wrap: anywhere; }
.empty { color: var(--hint); margin: 4px 0; }
.error { color: var(--warn); font-size: 13px; margin: 6px 0 0; }

.assign { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  margin: 0 auto;
  max-width: 480px;
  background: var(--text);
  color: var(--card);
  border-radius: 12px;
  padding: 12px 16px;
  text-align: center;
  z-index: 10;
}

.login { max-width: 520px; }

/* Правка времени: кнопка «⋯» и форма внутри строки задачи */
button.edit { font-size: 20px; line-height: 1; letter-spacing: 0.05em; min-width: 40px; padding: 0 6px; }
.time-slot:empty { display: none; }
.time-result { margin: 0 0 8px; font-size: 13px; color: var(--accent); }
.time-form {
  display: grid;
  gap: 8px;
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
}
.time-form .f-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-width: 0; }
.time-form label { display: inline-flex; align-items: center; gap: 6px; color: var(--hint); font-size: 14px; }
.time-form input {
  font: inherit;
  min-height: 40px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  min-width: 0;
}
.time-form input[type="number"] { width: 96px; }
.time-form input[type="time"] { width: 116px; }
.time-form input[type="date"] { flex: 1 1 140px; max-width: 180px; }
.time-form input.note { flex: 1 1 200px; }
.time-form .error { margin: 0; }
.seg { flex: 0 0 auto; display: inline-flex; border-radius: 9px; box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; max-width: 100%; }
.seg button { min-height: 36px; border-radius: 0; background: transparent; color: var(--text); font-weight: 500; font-size: 14px; padding: 0 12px; }
.seg button.seg-on { background: var(--button); color: var(--button-text); }

/* Сегменты «Сегодня»: подзаголовки групп и строка «запущено N из M» */
.summary { margin: -4px 0 6px; }
h3.sub { font-size: 13px; font-weight: 600; color: var(--hint); margin: 12px 0 2px; }
.list > h3.sub:first-child { margin-top: 0; }
.list > .sub + .row { border-top: 0; }
.row.is-running .row-meta { color: var(--accent); }
.done-block { margin-top: 6px; border-top: 1px solid var(--line); padding-top: 4px; }
.row.done .row-title { color: var(--hint); }

/* Статистика: полоски и столбики недели, только CSS */
#stats-block > h3.sub:first-child { margin-top: 0; }
.bars { display: grid; gap: 8px; margin: 4px 0 4px; }
.bar-row { min-width: 0; }
.bar-head { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.bar-label { min-width: 0; overflow-wrap: anywhere; }
.bar-value { color: var(--hint); font-variant-numeric: tabular-nums; white-space: nowrap; }
.hbar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 3px; }
.hbar > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar-row.muted .hbar > span { background: var(--hint); opacity: 0.6; }
.bar-row.muted .bar-label { color: var(--hint); }

.week-chart { margin: 6px 0 4px; }
.wplot { position: relative; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; padding-top: 4px; }
.wcol { display: grid; grid-template-rows: 110px auto auto; justify-items: center; min-width: 0; }
.wtrack { position: relative; width: 100%; max-width: 36px; height: 110px; display: flex; align-items: flex-end; background: var(--bg); border-radius: 6px; overflow: hidden; }
.wbar { width: 100%; background: var(--accent); opacity: 0.55; border-radius: 6px 6px 0 0; }
.wcol.is-today .wbar { opacity: 1; }
.wcol.is-today .wlabel { color: var(--text); font-weight: 700; }
.wcol.is-future { opacity: 0.35; }
.wlabel { font-size: 12px; color: var(--hint); margin-top: 4px; }
.wvalue { font-size: 11px; color: var(--hint); font-variant-numeric: tabular-nums; white-space: nowrap; }
/* Линия 8 ч: зона = высота дорожек, bottom линии в процентах этой высоты */
.limit-zone { position: absolute; left: 0; right: 0; top: 4px; height: 110px; pointer-events: none; z-index: 1; }
.limit-line { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--warn); }
.limit-line > span { position: absolute; right: 0; top: -15px; font-size: 10px; line-height: 14px; color: var(--warn); background: var(--card); padding: 0 3px; border-radius: 3px; }

/* Узкий экран: название не сжимается в столбик, кнопки уходят под него */
.row { flex-wrap: wrap; }
.row > .row-main { flex: 1 1 160px; }
.row > .actions { margin-left: auto; }
.row.running, .row.paused { flex-wrap: nowrap; }
.row.running > .row-main, .row.paused > .row-main { flex: 1 1 auto; }

.clock-total { font-variant-numeric: tabular-nums; font-weight: 600; }

.login-paste { display: flex; gap: 8px; margin-top: 12px; }
.login-paste .search { flex: 1; }
