:root {
  --bg: #f4f5f8; --panel: #ffffff; --panel2: #f0f2f6; --text: #1d2230; --muted: #6b7385; --line: #e1e4ea;
  --accent: #3e6ff4; --accent-text: #ffffff; --ok: #1f9d55; --warn: #d97706; --bad: #dc2626;
  --radius: 10px; --shadow: 0 1px 3px rgba(20, 30, 60, .08);
}
/* темная тема: по теме телефона, а в Telegram - по теме Telegram (атрибут data-theme ставит app.js) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --bg: #12151c; --panel: #1b1f29; --panel2: #232836; --text: #e6e9f0; --muted: #98a0b3; --line: #2e3445;
    --accent: #6b8eff; --accent-text: #0d1020; --shadow: none;
  }
}
:root[data-theme=dark] {
  --bg: #12151c; --panel: #1b1f29; --panel2: #232836; --text: #e6e9f0; --muted: #98a0b3; --line: #2e3445;
  --accent: #6b8eff; --accent-text: #0d1020; --shadow: none;
  color-scheme: dark;
}
:root[data-theme=light] { color-scheme: light; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
a.btn { text-decoration: none; display: inline-block; color: inherit; }
a.btn.pri { color: var(--accent-text); }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
#app { display: flex; min-height: 100vh; }
#side { width: 220px; flex: none; background: var(--panel); border-right: 1px solid var(--line); padding: 12px 8px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
#side .brand { font-weight: 700; padding: 6px 10px 14px; }
#side a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; }
#side a:hover { background: var(--panel2); }
#side a.on { background: var(--accent); color: var(--accent-text); }
#side .grp { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 12px 10px 4px; }
#wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
#top h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#search { width: 240px; }
#menuBtn { display: none; }
#main { padding: 16px; flex: 1; min-width: 0; }
#bottom { display: none; }
.icon-btn { background: none; border: 0; padding: 6px; cursor: pointer; line-height: 0; }
.icon-btn svg, #bottom svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

input[type=text], input[type=search], input[type=number], input[type=date], input[type=time], input[type=password], input[type=url], select, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; max-width: 100%;
}
textarea { width: 100%; min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(.97); }
.btn.pri { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.bad { color: var(--bad); }
.btn.sm { padding: 4px 8px; font-size: 13px; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.stack > * + * { margin-top: 12px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.list { display: flex; flex-direction: column; }
.li { display: flex; align-items: center; gap: 8px; padding: 9px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.li:last-child { border-bottom: 0; }
.li:hover { background: var(--panel2); }
.tag { display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 10px; background: var(--panel2); color: var(--muted); margin-right: 4px; }
.pill { font-size: 12px; padding: 1px 8px; border-radius: 10px; border: 1px solid var(--line); }
.pr3 { color: var(--bad); } .pr2 { color: var(--warn); } .pr1 { color: var(--accent); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.tabs button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.empty { color: var(--muted); padding: 20px; text-align: center; }
.kpi { font-size: 26px; font-weight: 700; }

/* модальное окно */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; width: min(640px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 18px; }
.modal .head { display: flex; align-items: center; margin-bottom: 12px; }
.modal .head h2 { flex: 1; margin: 0; }
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 3px; }
.field input, .field select { width: 100%; }
.fields2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

/* канбан */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: flex-start; scroll-snap-type: x mandatory; }
.col { background: var(--panel2); border-radius: var(--radius); width: 290px; flex: none; padding: 8px; scroll-snap-align: start; }
.col.over { outline: 2px dashed var(--accent); }
.col-h { display: flex; align-items: center; gap: 6px; font-weight: 600; padding: 4px 4px 8px; }
.col-b { min-height: 40px; display: flex; flex-direction: column; gap: 8px; }
.kcard { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 9px; cursor: grab; touch-action: pan-y; user-select: none; }
.kcard.drag { opacity: .4; }
.ghost { position: fixed; pointer-events: none; z-index: 200; opacity: .9; transform: rotate(2deg); box-shadow: 0 8px 20px rgba(0, 0, 0, .25); }
.kcard .meta { font-size: 12px; color: var(--muted); margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; }
.overdue { color: var(--bad); }

/* календарь */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal .dh { background: var(--panel2); text-align: center; font-size: 12px; padding: 4px; color: var(--muted); }
.cal .d { background: var(--panel); min-height: 92px; padding: 4px; cursor: pointer; overflow: hidden; }
.cal .d.other { opacity: .45; }
.cal .d.today .n { background: var(--accent); color: var(--accent-text); border-radius: 10px; padding: 0 6px; }
.cal .d .n { font-size: 12px; font-weight: 600; display: inline-block; }
.cal .ev { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: 4px; padding: 0 4px; margin-top: 2px; background: var(--panel2); }
.cal .ev.e { background: rgba(62, 111, 244, .15); }

/* Гант */
.gantt { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.g-row { display: flex; border-bottom: 1px solid var(--line); min-height: 30px; }
.g-name { width: 200px; flex: none; padding: 5px 8px; border-right: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: sticky; left: 0; background: var(--panel); z-index: 2; font-size: 13px; cursor: pointer; }
.g-track { position: relative; flex: none; }
.g-day { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--line); font-size: 10px; color: var(--muted); padding-left: 2px; }
.g-day.we { background: rgba(127, 127, 127, .07); }
.g-bar { position: absolute; top: 6px; height: 18px; border-radius: 5px; background: var(--accent); color: var(--accent-text); font-size: 11px; padding: 0 6px; white-space: nowrap; overflow: hidden; }
.g-bar.done { background: var(--ok); }
.g-today { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--bad); z-index: 1; }

/* заметки */
.notes { display: grid; grid-template-columns: 280px 1fr; gap: 14px; }
.md h1, .md h2, .md h3 { margin: 12px 0 6px; }
.md p { margin: 6px 0; }
.md pre { background: var(--panel2); padding: 10px; border-radius: 8px; overflow-x: auto; }
.md code { background: var(--panel2); padding: 0 4px; border-radius: 4px; }
.md a.wl { background: rgba(62, 111, 244, .12); border-radius: 4px; padding: 0 3px; text-decoration: none; }
.md a.wl.missing { color: var(--muted); border: 1px dashed var(--line); }
.md ul { padding-left: 22px; margin: 6px 0; }
.md blockquote { border-left: 3px solid var(--line); margin: 6px 0; padding-left: 10px; color: var(--muted); }

/* доска, галерея */
.masonry { columns: 4 240px; column-gap: 12px; }
.masonry .pin { break-inside: avoid; margin-bottom: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; }
.pin img, .pin video { width: 100%; display: block; }
.pin .pb { padding: 8px 10px; }
.pin .dom { font-size: 12px; color: var(--muted); word-break: break-all; }
.media-full { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto; border-radius: 8px; }

/* тренировка */
.ex { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.ex .hint { background: var(--panel2); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin: 8px 0; }
.ex .hint b { font-weight: 600; }
.setrow { display: grid; grid-template-columns: 34px 1fr 1fr 1fr auto; gap: 6px; align-items: center; padding: 4px 0; }
.setrow input { width: 100%; text-align: center; padding: 8px 4px; }
.setrow.done input { background: rgba(31, 157, 85, .12); }
.setrow .no { text-align: center; color: var(--muted); font-weight: 600; }
.ex img, .ex video { max-width: 100%; max-height: 240px; border-radius: 8px; display: block; margin: 6px 0; }
#restBar { position: fixed; left: 50%; transform: translateX(-50%); bottom: 16px; z-index: 90; background: var(--text); color: var(--bg); border-radius: 14px; padding: 10px 14px; display: flex; gap: 10px; align-items: center; box-shadow: 0 6px 20px rgba(0, 0, 0, .3); }
#restBar .t { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 70px; text-align: center; }
#restBar .btn { background: transparent; color: inherit; border-color: currentColor; }
#restBar.end { background: var(--ok); color: #fff; }
.chart { width: 100%; height: 280px; }
#toast { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 10px; z-index: 300; max-width: 90vw; }
#timerBox .run { display: flex; gap: 6px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px 4px 3px 10px; font-size: 13px; }
#timerBox .run b { font-variant-numeric: tabular-nums; }
.login { max-width: 360px; margin: 12vh auto; }
.tree .node { padding-left: 18px; }
.progress { height: 8px; background: var(--panel2); border-radius: 4px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }
.foodgrid td, .foodgrid th { padding: 6px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.foodgrid td:first-child, .foodgrid th:first-child { text-align: left; }
table { border-collapse: collapse; width: 100%; }
.tbl-wrap { overflow-x: auto; }
.tbl th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 500; padding: 6px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 7px 6px; border-bottom: 1px solid var(--line); }
.tbl tr { cursor: pointer; }
.tbl tr:hover td { background: var(--panel2); }

/* вертикальная версия: телефон и Telegram */
@media (max-width: 899px) {
  #side { position: fixed; left: 0; top: 0; bottom: 0; z-index: 150; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 30px rgba(0, 0, 0, .3); width: 260px; }
  #side.open { transform: none; }
  #menuBtn { display: block; }
  #top { padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); }
  #search { width: 120px; }
  #main { padding: 12px 12px 84px; }
  #bottom { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  #bottom a { flex: 1; text-align: center; padding: 7px 0 6px; color: var(--muted); text-decoration: none; font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
  #bottom a.on { color: var(--accent); }
  .notes { grid-template-columns: 1fr; }
  .col { width: 82vw; }
  .grid { grid-template-columns: 1fr; }
  .cal .d { min-height: 58px; }
  .cal .ev { font-size: 10px; }
  .g-name { width: 120px; }
  .masonry { columns: 2 150px; column-gap: 8px; }
  .fields2 { grid-template-columns: 1fr; }
  #restBar { bottom: 74px; }
  .modal-bg { align-items: flex-end; padding: 0; }
  .modal { border-radius: 14px 14px 0 0; max-height: 92vh; padding-bottom: max(18px, env(safe-area-inset-bottom)); }
}
