/* Pythia tasks Mini App. Telegram theme params first, own fallbacks for a plain browser. */

:root {
  --fb-bg: #ffffff;
  --fb-bg2: #f2f3f5;
  --fb-text: #16191d;
  --fb-hint: #737c87;
  --fb-link: #2c6fb3;
  --fb-button: #2c6fb3;
  --fb-button-text: #ffffff;
  --fb-destructive: #cf3b33;
  --fb-sep: rgba(22, 25, 29, .09);
  --fb-ok: #2f8a57;
  --fb-chip-on-bg: #2c6fb3;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-scheme="light"]) {
    --fb-bg: #17191c;
    --fb-bg2: #0f1113;
    --fb-text: #e9ecef;
    --fb-hint: #8c96a1;
    --fb-link: #6aaef0;
    --fb-button: #3a8ad6;
    --fb-destructive: #ff6b60;
    --fb-sep: rgba(233, 236, 239, .09);
    --fb-ok: #4fc182;
    color-scheme: dark;
  }
}
:root[data-scheme="dark"] {
  --fb-bg: #17191c;
  --fb-bg2: #0f1113;
  --fb-text: #e9ecef;
  --fb-hint: #8c96a1;
  --fb-link: #6aaef0;
  --fb-button: #3a8ad6;
  --fb-destructive: #ff6b60;
  --fb-sep: rgba(233, 236, 239, .09);
  --fb-ok: #4fc182;
  color-scheme: dark;
}

:root {
  --bg: var(--tg-theme-bg-color, var(--fb-bg));
  --bg2: var(--tg-theme-secondary-bg-color, var(--fb-bg2));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --link: var(--tg-theme-link-color, var(--fb-link));
  --accent: var(--tg-theme-button-color, var(--fb-button));
  --accent-text: var(--tg-theme-button-text-color, var(--fb-button-text));
  --danger: var(--tg-theme-destructive-text-color, var(--fb-destructive));
  --section-title: var(--tg-theme-section-header-text-color, var(--hint));
  --sep: var(--tg-theme-section-separator-color, var(--fb-sep));
  --ok: var(--fb-ok);

  --radius-s: 8px;
  --radius-m: 12px;
  --radius-l: 18px;
  --gutter: 16px;
  --row-min: 58px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.35 var(--font);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

.dev-banner {
  position: fixed; top: 0; right: 0; z-index: 50;
  background: #d62d2d; color: #fff;
  font: 700 11px/1 var(--font); letter-spacing: .06em;
  padding: 4px 8px; border-bottom-left-radius: 6px;
  pointer-events: none;
}

/* ---------------------------------------------------------------- header */

.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding: 14px var(--gutter) 0;
  max-width: 680px; margin: 0 auto;
}
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.today-label { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.01em; line-height: 1.15; }
.summary { margin: 4px 0 12px; color: var(--hint); font-size: 14px; line-height: 1.4; min-height: 1.4em; }
.summary .s-hard { color: var(--danger); font-weight: 600; }

.tabs {
  display: grid; grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--sep);
  margin: 0 calc(-1 * var(--gutter));
  padding: 0 var(--gutter);
}
.tab {
  appearance: none; background: none; border: 0;
  padding: 10px 4px 11px; min-height: 44px;
  color: var(--hint); font-size: 15px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-bottom: 2.5px solid transparent; margin-bottom: -1px;
}
.tab.on { color: var(--text); border-bottom-color: var(--accent); }
.badge:empty { display: none; }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--bg2); color: var(--hint);
  font-size: 12px; font-weight: 700; line-height: 20px; text-align: center;
}
.tab.on .badge { background: var(--accent); color: var(--accent-text); }
.badge.hot { background: var(--danger); color: #fff; }

.icon-btn {
  appearance: none; border: 0; background: none;
  width: 44px; height: 44px; flex: none;
  display: inline-grid; place-items: center;
  color: var(--hint); border-radius: 50%;
}
.icon-btn:active { background: var(--bg2); }
.ico { display: inline-grid; place-items: center; width: 22px; height: 22px; }
.ico svg { width: 22px; height: 22px; }
#refresh { margin-right: -10px; }

/* ---------------------------------------------------------------- view + groups */

.view { max-width: 680px; margin: 0 auto; padding: 4px 0 0; }
.loading { padding: 40px var(--gutter); color: var(--hint); text-align: center; }

.group { margin-top: 18px; }
.group-title {
  margin: 0; padding: 0 var(--gutter) 6px;
  display: flex; align-items: baseline; gap: 8px;
  font-size: 14px; font-weight: 650; color: var(--section-title);
}
.group-count { font-weight: 500; color: var(--hint); font-variant-numeric: tabular-nums; }
.group-note { margin: -2px var(--gutter) 6px; font-size: 13px; color: var(--hint); }
.group.hard .group-title { color: var(--danger); }
.group.waiting { margin-top: 28px; }
.group.waiting .row-fg { opacity: .62; }
.group.waiting .row-fg .check { visibility: visible; }

.rows { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--sep); }

/* ---------------------------------------------------------------- rows */

.row { position: relative; overflow: hidden; border-bottom: 1px solid var(--sep); }
.row-fg {
  position: relative; z-index: 1;
  display: flex; align-items: center; gap: 2px;
  min-height: var(--row-min);
  padding: 4px 4px 4px 6px;
  background: var(--bg);
  touch-action: pan-y;
}
.notch {
  position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0;
  background: transparent;
}
.notch[data-prio="P1"] { background: var(--danger); }
.notch[data-prio="P2"] { background: color-mix(in srgb, var(--accent) 55%, transparent); }

.check {
  appearance: none; border: 0; background: none; flex: none;
  width: 44px; height: 44px; display: grid; place-items: center; padding: 0;
}
.check .ico {
  width: 24px; height: 24px; border-radius: 50%;
  border: 1.8px solid color-mix(in srgb, var(--hint) 70%, transparent);
  color: transparent;
}
.check .ico svg { width: 16px; height: 16px; }
.check:hover .ico, .check:focus-visible .ico { color: var(--ok); border-color: var(--ok); }
.check:active .ico { background: var(--ok); border-color: var(--ok); color: #fff; }

.row-main {
  appearance: none; border: 0; background: none; text-align: left;
  flex: 1; min-width: 0; padding: 7px 4px; min-height: 44px;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.title { font-size: 16px; line-height: 1.3; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: 13px; color: var(--hint); line-height: 1.35; }
.meta .late { color: var(--danger); }
.meta .dl { color: var(--text); opacity: .75; }
.meta .dl.missed { color: var(--danger); opacity: 1; font-weight: 600; }
.meta .cat { font-weight: 600; }
.meta .folder { max-width: 14em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-reply { color: var(--link); font-weight: 600; }
.side { color: color-mix(in srgb, var(--hint) 80%, transparent); }

/* swipe underlay */
.swipe-bg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px; font-size: 14px; font-weight: 700; color: #fff;
  background: var(--ok);
}
.swipe-bg .sb-left { visibility: hidden; }
.row[data-dir="left"] .swipe-bg { background: var(--accent); color: var(--accent-text); }
.row[data-dir="left"] .sb-left { visibility: visible; }
.row[data-dir="left"] .sb-right { visibility: hidden; }
.row:not(.dragging) .swipe-bg { visibility: hidden; }
.row.dragging:not(.armed) .swipe-bg { filter: saturate(.35); opacity: .75; }

/* inbox queue rows */
.row.queue .row-fg { align-items: flex-start; padding: 8px 4px 12px 6px; }
.q-body { flex: 1; min-width: 0; padding-left: 10px; }
.q-head { display: flex; align-items: flex-start; gap: 2px; }
.q-head .row-main { padding-left: 0; }
.q-actions { display: flex; flex: none; margin-top: -2px; }
.icon-btn.ok:hover { color: var(--ok); }
.icon-btn.drop:hover { color: var(--danger); }
.q-controls { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 8px; }
/* The list choice is one joined control; the dates beside it are the actions that file. */
.cats {
  gap: 0; flex-wrap: nowrap;
  border: 1px solid color-mix(in srgb, var(--hint) 38%, transparent); border-radius: 17px; overflow: hidden;
}
.cats .chip { border: 0; border-radius: 0; min-width: 54px; justify-content: center; min-height: 32px; line-height: 32px; }
.cats .chip + .chip { border-left: 1px solid color-mix(in srgb, var(--hint) 24%, transparent); }
.dues .chip:not([aria-disabled="true"]) { color: var(--link); border-color: color-mix(in srgb, var(--link) 45%, transparent); }
.row.queue .chip { font-size: 14px; min-height: 32px; line-height: 30px; padding: 0 11px; }

/* ---------------------------------------------------------------- chips */

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  appearance: none; position: relative;
  border: 1px solid color-mix(in srgb, var(--hint) 38%, transparent);
  background: transparent; color: var(--text);
  min-height: 34px; padding: 0 12px; border-radius: 17px;
  font-size: 14px; font-weight: 500; line-height: 32px; white-space: nowrap;
  display: inline-flex; align-items: center;
}
.chip:active { background: var(--bg2); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.chip[aria-disabled="true"] { color: var(--hint); border-style: dashed; }
.nudge { animation: nudge .32s ease; }
@keyframes nudge { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.chip.picker { overflow: hidden; }
.chip.picker .date-input {
  position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0;
}

/* ---------------------------------------------------------------- lists tab */

.list-controls { padding: 14px var(--gutter) 0; display: grid; gap: 10px; }
.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--bg2); border-radius: var(--radius-m); padding: 3px; gap: 2px;
}
.seg-btn {
  appearance: none; border: 0; background: none; border-radius: 9px;
  min-height: 38px; padding: 0 6px; font-size: 14px; font-weight: 600; color: var(--hint);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.seg-btn.on { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.seg-n { font-weight: 500; font-size: 12px; color: var(--hint); font-variant-numeric: tabular-nums; }
.seg.small { max-width: 260px; }
.seg-btn[data-prio="P1"].on { color: var(--danger); }
.extra { margin: 24px var(--gutter); display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; color: var(--hint); }
.extra dd { margin: 0; color: var(--text); }

.empty { padding: 44px var(--gutter); text-align: center; color: var(--hint); }
.empty p { margin: 0 0 14px; font-size: 16px; }

/* ---------------------------------------------------------------- buttons */

.btn {
  appearance: none; border: 0; border-radius: var(--radius-m);
  min-height: 46px; padding: 0 18px; font-size: 15px; font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.secondary { background: var(--bg2); color: var(--link); }
.btn.danger { color: var(--danger); }
.add-fallback {
  position: fixed; z-index: 20;
  right: max(var(--gutter), calc(50vw - 340px + var(--gutter)));
  bottom: calc(18px + env(safe-area-inset-bottom));
  appearance: none; border: 0; border-radius: 26px;
  min-height: 52px; padding: 0 22px 0 18px;
  background: var(--accent); color: var(--accent-text);
  font-size: 16px; font-weight: 650;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 35%, transparent);
  display: inline-flex; align-items: center; gap: 8px;
}
.add-fallback::before { content: "+"; font-size: 24px; font-weight: 400; line-height: 1; margin-top: -2px; }

/* ---------------------------------------------------------------- sheet */

.scrim { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .45); opacity: 0; transition: opacity .18s ease; }
.scrim.show { opacity: 1; }
.sheet {
  position: fixed; z-index: 31; left: 0; right: 0; bottom: 0;
  max-width: 560px; margin: 0 auto;
  max-height: 88vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); color: var(--text);
  border-radius: var(--radius-l) var(--radius-l) 0 0;
  padding: 6px var(--gutter) calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .22s cubic-bezier(.2, .8, .2, 1);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .18);
}
.sheet.show { transform: none; }
.sheet-head { display: grid; grid-template-columns: 1fr auto; align-items: start; gap: 4px; padding-top: 12px; position: relative; }
.grab { position: absolute; top: 2px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: var(--sep); }
.sheet-title { margin: 8px 0 0; font-size: 19px; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.sheet-sub { margin: 3px 0 0; color: var(--hint); font-size: 14px; }
.sheet .icon-btn { margin: 0 -10px 0 0; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; margin: 12px 0 0; font-size: 15px; }
.facts dt { color: var(--hint); }
.facts dd { margin: 0; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.tag { font-size: 13px; padding: 2px 9px; border-radius: 6px; background: var(--bg2); color: var(--hint); }
.detail { white-space: pre-line; margin: 12px 0 0; font-size: 15px; line-height: 1.45; color: var(--text); opacity: .85; }
.field { margin-top: 18px; }
.field-label { font-size: 13px; font-weight: 650; color: var(--section-title); margin-bottom: 8px; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.sheet-actions .btn { flex: 1 1 140px; }
.add-text {
  width: 100%; margin-top: 14px; resize: none;
  border: 1px solid var(--sep); border-radius: var(--radius-m);
  background: var(--bg2); padding: 12px 14px; font-size: 17px; line-height: 1.35;
}
.add-text:focus { outline: 2px solid var(--link); outline-offset: 0; }

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed; z-index: 40; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px); opacity: 0;
  max-width: min(92vw, 520px); width: max-content;
  padding: 11px 16px; border-radius: var(--radius-m);
  background: color-mix(in srgb, var(--text) 90%, var(--bg)); color: var(--bg);
  font-size: 14px; line-height: 1.35; box-shadow: 0 6px 22px rgba(0, 0, 0, .22);
  transition: opacity .18s ease, transform .18s ease;
  overflow-wrap: anywhere;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="error"] { background: var(--danger); color: #fff; }

/* ---------------------------------------------------------------- desktop */

@media (min-width: 700px) {
  .rows { border: 1px solid var(--sep); border-radius: var(--radius-m); overflow: hidden; }
  .group-title, .group-note { padding-left: 4px; }
  .view { padding: 4px var(--gutter) 0; }
  .row:last-child { border-bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
