/* Lodestar UI — чиста тема з динамічним оформленням за порою дня.
   Палітра керується data-theme (light|dark) і data-accent на <html>. */

:root {
  --accent: #6366f1;
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px -12px rgba(0,0,0,.18);
  --sp: sans-serif;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, var(--sp);
}

/* --- світла тема (день) --- */
html[data-theme="light"] {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f2f3f6;
  --text: #1a1d23;
  --muted: #6b7280;
  --border: #e6e8ec;
  --shadow-c: rgba(20,25,40,.10);
}
/* --- темна тема (ніч/вечір) --- */
html[data-theme="dark"] {
  --bg: #0e1015;
  --surface: #171a21;
  --surface-2: #1e222b;
  --text: #e9ebef;
  --muted: #9aa2af;
  --border: #262b35;
  --shadow-c: rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
       transition: background .4s ease, color .4s ease; }

.app { display: grid; grid-template-columns: 232px 1fr; height: 100vh; }

/* ---------------- Sidebar ---------------- */
.sidebar { background: var(--surface); border-right: 1px solid var(--border);
           display: flex; flex-direction: column; padding: 18px 12px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 20px; }
.brand-mark { color: var(--accent); font-size: 20px; }
.brand-name { font-weight: 700; letter-spacing: .2px; font-size: 17px; }
.nav { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.nav li { display: flex; align-items: center; gap: 11px; padding: 10px 12px;
          border-radius: var(--radius-sm); cursor: pointer; color: var(--muted);
          font-weight: 500; transition: background .15s, color .15s; user-select: none; }
.nav li:hover { background: var(--surface-2); color: var(--text); }
.nav li.active { background: var(--accent-soft); color: var(--accent); }
.nav .ico { width: 18px; text-align: center; font-size: 15px; }
.nav-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.nav-settings { display: flex; align-items: center; gap: 11px; padding: 10px 12px;
                background: transparent; border: 0; color: var(--muted); cursor: pointer;
                border-radius: var(--radius-sm); font: inherit; font-weight: 500; }
.nav-settings:hover { background: var(--surface-2); color: var(--text); }
.greeting { font-size: 12px; color: var(--muted); padding: 4px 12px; }

/* ---------------- Content ---------------- */
.content { overflow-y: auto; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center;
          justify-content: space-between; padding: 20px 28px 14px;
          background: color-mix(in srgb, var(--bg) 86%, transparent);
          backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.topbar h1 { margin: 0; font-size: 22px; font-weight: 700; }
.subtitle { color: var(--muted); font-size: 13px; margin-top: 2px; }
.refresh { background: var(--surface); border: 1px solid var(--border); color: var(--muted);
           width: 36px; height: 36px; border-radius: 10px; cursor: pointer; font-size: 16px; }
.refresh:hover { color: var(--text); }
.view { padding: 22px 28px 60px; max-width: 900px; }

/* ---------------- Спільні елементи ---------------- */
.card { background: var(--surface); border: 1px solid var(--border);
        border-radius: var(--radius); box-shadow: var(--shadow); }
.muted { color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }

.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 20px;
         background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.sphere-tag { font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 20px;
              color: #fff; }
.prio { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px; }
.prio.hi { background: #ef4444; color: #fff; }
.prio.mid { background: #f59e0b; color: #fff; }
.prio.lo { background: var(--surface-2); color: var(--muted); }
.routine-dot { color: var(--accent); }

/* Порожній / setup стан */
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .big { font-size: 34px; margin-bottom: 12px; opacity: .6; }
.demo-flag { display: inline-block; font-size: 11px; font-weight: 600; color: var(--accent);
             background: var(--accent-soft); padding: 3px 10px; border-radius: 20px; margin-bottom: 14px; }

/* verdict banner (Today) */
.verdict { display: flex; align-items: center; gap: 14px; padding: 16px 18px; margin-bottom: 18px;
           border-radius: var(--radius); border: 1px solid var(--border); }
.verdict.ok { background: color-mix(in srgb, #22c55e 12%, var(--surface)); }
.verdict.over { background: color-mix(in srgb, #ef4444 12%, var(--surface)); }
.verdict .v-ico { font-size: 26px; }
.verdict .v-title { font-weight: 700; }
.verdict .v-sub { font-size: 13px; color: var(--muted); }

/* Таймлайн (Today, у дусі Structured) */
.timeline { position: relative; margin-left: 8px; }
.tl-item { display: grid; grid-template-columns: 62px 1fr; gap: 14px; padding: 4px 0; }
.tl-time { text-align: right; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums;
           padding-top: 12px; }
.tl-block { position: relative; padding: 12px 14px 12px 18px; border-radius: var(--radius-sm);
            background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.tl-block::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 4px;
                    border-radius: 4px; background: var(--sph, var(--accent)); }
.tl-title { font-weight: 600; }
.tl-meta { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; gap: 8px; align-items: center; }

.section-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
                 color: var(--muted); margin: 26px 0 10px; }

/* Список задач (Backlog / Upcoming / flexible) */
.task { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.task + .task { border-top: 1px solid var(--border); }
.task .t-main { flex: 1; min-width: 0; }
.task .t-title { font-weight: 500; }
.task .t-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
/* Статуси: чекбокс задачі (явний виконано/невиконано) + бейдж події (derived) */
.task-check { width: 22px; height: 22px; min-width: 22px; border-radius: 6px;
  border: 1.5px solid var(--accent); background: transparent; color: #fff; font: inherit;
  font-weight: 700; line-height: 1; cursor: pointer; display: inline-flex;
  align-items: center; justify-content: center; }
.task-check.done { background: var(--accent); }
.task-check:disabled { opacity: .5; cursor: default; }
.task.done .t-title { text-decoration: line-through; opacity: .55; }
.tl-title-row { display: flex; align-items: center; gap: 8px; }
.st-badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600; }
.st-happened { background: color-mix(in srgb, #22c55e 16%, transparent); color: #16a34a; }
.st-upcoming { background: var(--accent-soft); color: var(--accent); }
.st-missed { background: color-mix(in srgb, #ef4444 14%, transparent); color: #dc2626; }
/* CRUD задач: форма + іконки редагувати/видалити */
.toolbar { margin-bottom: 12px; }
.task-form { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; padding: 16px; }
.task-form input, .task-form select { padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; width: 100%; }
.tf-field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 110px; }
.tf-lbl { font-size: 11px; color: var(--muted); font-weight: 600; }
.tf-row { display: flex; gap: 10px; flex-wrap: wrap; }
.tf-actions { display: flex; gap: 8px; margin-top: 2px; }
.ghost-btn { background: transparent; border: 1px solid var(--border); color: var(--muted);
  border-radius: 20px; padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer; }
.t-actions { display: flex; gap: 2px; }
.icon-btn { background: transparent; border: none; cursor: pointer; font-size: 14px;
  opacity: .45; padding: 4px 7px; border-radius: 6px; line-height: 1; }
.icon-btn:hover { opacity: 1; background: var(--accent-soft); }
.icon-btn.danger:hover { background: color-mix(in srgb, #ef4444 14%, transparent); }
.group-date { font-size: 13px; font-weight: 700; margin: 20px 0 8px; color: var(--text); }
.group-date span { color: var(--muted); font-weight: 500; }

/* Reporting */
.grid2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
.panel { padding: 18px; }
.panel h3 { margin: 0 0 14px; font-size: 14px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 44px; align-items: center; gap: 10px; margin: 9px 0; }
.bar-track { background: var(--surface-2); border-radius: 20px; height: 10px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 20px; }
.bar-val { font-size: 12px; color: var(--muted); text-align: right; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 8px 12px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
        border: 1px solid var(--border); }
.chip.met { background: color-mix(in srgb, #22c55e 14%, var(--surface)); }
.chip.unmet { background: color-mix(in srgb, #f59e0b 12%, var(--surface)); }
.cap-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.pill { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 20px; }
.pill.ok { background: color-mix(in srgb,#22c55e 16%,var(--surface)); color: #16a34a; }
.pill.over { background: color-mix(in srgb,#ef4444 16%,var(--surface)); color: #dc2626; }

/* Chat */
.chat { display: flex; flex-direction: column; height: calc(100vh - 150px); max-width: 760px; }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 4px; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.msg.bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--border);
           border-bottom-left-radius: 5px; }
.msg.think { color: var(--muted); font-style: italic; }
.chat-form { display: flex; gap: 8px; padding-top: 12px; }
.chat-form input { flex: 1; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
                   background: var(--surface); color: var(--text); font-size: 15px; }
.chat-form button { padding: 0 20px; border: 0; border-radius: 12px; background: var(--accent);
                    color: #fff; font-size: 16px; cursor: pointer; }
.chat-form button:disabled { opacity: .5; }
/* Портрет (червоні лінії) у Settings */
.portrait-box { display: flex; flex-direction: column; gap: 8px; }
.portrait-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.portrait-label { font-size: 13px; color: var(--muted); flex: 1; }
.portrait-row input { width: 130px; padding: 6px 8px; border: 1px solid var(--border);
                      border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
.portrait-foot { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
/* Меню-first (router-first): швидкі дії чіпами над інпутом */
.chat-quick { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 4px 0; }
.quick-chip { padding: 7px 13px; border-radius: 20px; border: 1px solid var(--border);
              background: var(--surface-2); color: var(--text); font: inherit; font-size: 13px; cursor: pointer; }
.quick-chip:hover { border-color: var(--accent); color: var(--accent); }
.quick-chip.talk { border-style: dashed; color: var(--muted); }
/* Структуровані питання агента (ask_user) → кнопки вибору */
.msg.question { max-width: 86%; }
.q-prompt { font-weight: 600; margin-bottom: 8px; }
.q-options { display: flex; flex-wrap: wrap; gap: 8px; }
.q-option { padding: 8px 14px; border-radius: 20px; border: 1px solid var(--accent);
            background: var(--accent-soft); color: var(--accent); font: inherit;
            font-weight: 600; cursor: pointer; }
.q-option:hover:not(:disabled) { background: var(--accent); color: #fff; }
.q-option:disabled { cursor: default; opacity: .55; }
.q-option.chosen { background: var(--accent); color: #fff; opacity: 1; }
/* батч питань код-потоку: розділяємо блоки й даємо кнопку «Надіслати» */
.msg.question.batch .q-options { margin-bottom: 12px; }
.msg.question.batch .q-prompt:not(:first-child) { margin-top: 6px;
            padding-top: 12px; border-top: 1px solid var(--border, rgba(128,128,128,.25)); }
.q-submit { margin-top: 6px; padding: 9px 18px; border-radius: 20px; border: none;
            background: var(--accent); color: #fff; font: inherit; font-weight: 700; cursor: pointer; }
.q-submit:disabled { opacity: .55; cursor: default; }
.q-progress { font-size: 12px; color: var(--muted); margin-top: 8px; }
.q-hint { font-size: 13px; color: var(--muted); margin-top: 6px; font-style: italic; }

/* ---------------- Drawer (Settings) ---------------- */
.drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex;
                  justify-content: flex-end; z-index: 50; }
/* критично: атрибут hidden має перемагати display:flex вище (інакше панель
   завжди видима й не закривається) */
.drawer-overlay[hidden] { display: none; }
.drawer { width: min(400px, 92vw); height: 100%; background: var(--surface);
          border-left: 1px solid var(--border); display: flex; flex-direction: column;
          animation: slidein .22s ease; }
@keyframes slidein { from { transform: translateX(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between;
               padding: 18px 20px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-size: 17px; }
.close { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }
.drawer-body { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 26px; }
.setting > label { display: block; font-size: 12px; font-weight: 700; text-transform: uppercase;
                   letter-spacing: .5px; color: var(--muted); margin-bottom: 10px; }
.seg { display: flex; flex-direction: column; gap: 6px; }
.seg button { text-align: left; padding: 10px 12px; border-radius: var(--radius-sm);
              border: 1px solid var(--border); background: var(--surface); color: var(--text);
              cursor: pointer; font: inherit; }
.seg button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.swatches { display: flex; gap: 10px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; }
.swatch.on { border-color: var(--text); }
.usage-box { font-size: 13px; }
.usage-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); }
.usage-total { display: flex; justify-content: space-between; font-weight: 700; padding-top: 10px; }

/* ---------------- Журнал (§8.3 прозорість + undo) ---------------- */
.undo-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; margin-bottom: 12px; background: var(--accent-soft);
  border-radius: var(--radius-sm); }
.undo-btn { border: 1px solid var(--accent); color: var(--accent); background: transparent;
  padding: 6px 12px; border-radius: var(--radius-sm); cursor: pointer; font-weight: 600;
  white-space: nowrap; }
.undo-btn:hover { background: var(--accent); color: #fff; }
.undo-btn:disabled { opacity: .5; cursor: default; }
.activity-list { display: flex; flex-direction: column; }
.activity-row { display: flex; align-items: baseline; gap: 10px; padding: 8px 0;
  border-bottom: 1px solid var(--border); }
.activity-row.undone { opacity: .55; }
.activity-row.undone .act-sum { text-decoration: line-through; }
.act-ico { width: 20px; text-align: center; }
.act-time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.act-sum { flex: 1; }
.act-undone { font-size: 11px; color: var(--muted); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 8px; }

/* ---------------- Логін (single-user auth) ---------------- */
.login-overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center;
  justify-content: center; background: color-mix(in srgb, var(--bg) 90%, #000); }
/* критично: атрибут hidden має перемагати display:flex вище (як у .drawer-overlay),
   інакше після успішного входу картка не зникає — оверлей висить попри hidden=true. */
.login-overlay[hidden] { display: none; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 28px 26px; width: min(340px, 88vw); display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .25); }
.login-brand { font-size: 20px; font-weight: 700; }
.login-hint { color: var(--muted); font-size: 13px; margin: 0; }
.login-card input { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); font-size: 15px; }
.login-card button { padding: 10px; border: 0; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.login-card button:hover { filter: brightness(1.05); }
.login-err { color: #ef4444; font-size: 13px; margin: 0; }
.pass-wrap { position: relative; display: flex; align-items: stretch; }
.pass-wrap input { flex: 1; padding-right: 46px; }
.login-card .pass-eye { position: absolute; right: 4px; top: 4px; bottom: 4px; width: auto;
  padding: 0 10px; background: transparent; color: var(--muted); border: 0;
  font-size: 16px; line-height: 1; cursor: pointer; }
.login-card .pass-eye:hover { filter: none; background: var(--border); }

/* ---- Лоадери: скелетони під час завантаження + «зайняті» кнопки ---- */
@keyframes ls-spin { to { transform: rotate(360deg); } }
@keyframes ls-shimmer { 0% { background-position: -450px 0; } 100% { background-position: 450px 0; } }
.skel-list { display: flex; flex-direction: column; gap: 10px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
  background-size: 450px 100%; animation: ls-shimmer 1.3s ease-in-out infinite; border-radius: var(--radius-sm); }
.skel-card { height: 62px; }
button[aria-busy="true"] { position: relative; color: transparent !important; pointer-events: none; }
button[aria-busy="true"]::after { content: ""; position: absolute; left: 50%; top: 50%;
  width: 15px; height: 15px; margin: -8px 0 0 -8px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .45); border-top-color: #fff;
  animation: ls-spin .7s linear infinite; }

/* ---------------- Адаптив ---------------- */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; align-items: center; padding: 8px; gap: 6px; overflow-x: auto; }
  .brand, .greeting { display: none; }
  .nav { flex-direction: row; }
  .nav li span:not(.ico) { display: none; }
  .nav-foot { margin: 0; }
  .nav-settings span:not(.ico) { display: none; }
}
