:root {
  --bg: var(--tg-theme-bg-color, #fcfcfb);
  --card: var(--tg-theme-secondary-bg-color, #f1f1ef);
  --text: var(--tg-theme-text-color, #0b0b0b);
  --muted: var(--tg-theme-hint-color, #52514e);
  --accent: var(--tg-theme-button-color, #2a78d6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--text) 10%, transparent);
  /* categorical, validated palette (light) */
  --cal-cfo3: #2a78d6; --cal-personal: #1baf7a; --cal-rhino: #6250d6; --cal-other: #eda100;
  --flex: #eda100; --clash: #d03b3b; --free: color-mix(in srgb, #1baf7a 16%, transparent);
  --radius: 14px;
}
html.dark {
  --cal-cfo3: #3987e5; --cal-personal: #199e70; --cal-rhino: #9085e9; --cal-other: #c98500;
  --flex: #c98500; --clash: #e66767;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body { padding-bottom: 92px; }
button { font: inherit; color: inherit; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 4px; }
.brand { display: flex; align-items: baseline; gap: 10px; }
.logo { font-weight: 800; letter-spacing: .5px; font-size: 18px; }
.muted { color: var(--muted); font-size: 13px; }
.icon { background: none; border: 0; font-size: 20px; padding: 4px 8px; color: var(--muted); }

.tabs { display: flex; gap: 6px; padding: 8px 16px 12px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.tab { flex: 1; border: 0; border-radius: 999px; padding: 8px 0; background: var(--card); color: var(--muted); font-weight: 600; }
.tab.active { background: var(--accent); color: var(--accent-text); }

main { padding: 0 16px; }
.view.hidden, .hidden { display: none !important; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.hero { font-size: 20px; font-weight: 700; margin-bottom: 2px; }
.sub { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; color: #fff; }
.badge.light { background: #1baf7a; } .badge.moderate { background: #eda100; } .badge.heavy { background: #d03b3b; } .badge.off { background: var(--muted); }

/* timeline bar */
.bar { position: relative; height: 16px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar .seg { position: absolute; top: 0; bottom: 0; border-radius: 4px; opacity: .95; outline: 2px solid var(--card); }
.bar .seg.clash { box-shadow: inset 0 0 0 2px var(--clash); }
.bar .seg.flex { background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.35) 0 4px, transparent 4px 8px); }
.bar .win { position: absolute; top: 0; bottom: 0; background: var(--free); }
.bar .now { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text); opacity: .7; }
.ticks { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); margin-top: 3px; }
.cal-cfo3 { background: var(--cal-cfo3); } .cal-personal { background: var(--cal-personal); }
.cal-rhino { background: var(--cal-rhino); } .cal-other { background: var(--cal-other); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* event list */
.ev { display: grid; grid-template-columns: 74px 1fr auto; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); align-items: start; }
.ev:first-of-type { border-top: 0; }
.ev .time { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); padding-top: 2px; }
.ev .time b { color: var(--text); display: block; }
.ev .title { font-weight: 600; }
.ev .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.ev .dot { width: 10px; height: 10px; border-radius: 3px; margin-top: 6px; }
.ev.clash .title::before { content: "⚠️ "; }
.gap { font-size: 12px; color: var(--muted); padding: 6px 0 6px 84px; border-top: 1px dashed var(--line); }
.gap b { color: #1baf7a; }

/* week rows */
.wrow { display: grid; grid-template-columns: 54px 1fr 64px; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.wrow:first-of-type { border-top: 0; }
.wrow .d { font-weight: 700; } .wrow .d small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.wrow .r { text-align: right; font-size: 12px; color: var(--muted); }
.wrow.today .d { color: var(--accent); }

/* focus + inbox items */
.item { padding: 10px 0; border-top: 1px solid var(--line); }
.item:first-of-type { border-top: 0; }
.item .t { font-weight: 600; } .item .m { font-size: 12px; color: var(--muted); margin: 2px 0 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.chip.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.chip.danger { color: var(--clash); }
.unread::before { content: "●"; color: var(--accent); margin-right: 6px; font-size: 10px; vertical-align: 2px; }
.snippet { font-size: 13px; color: var(--muted); margin: 4px 0 8px; }
pre.text { white-space: pre-wrap; font: inherit; margin: 8px 0; }
.empty { color: var(--muted); padding: 10px 0; }
.err { color: var(--clash); font-size: 13px; }

/* reply panel + ask bar */
.reply { position: fixed; left: 12px; right: 12px; bottom: 76px; background: var(--card); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: 0 8px 30px rgba(0,0,0,.18); max-height: 55vh; overflow: auto; z-index: 20; }
.reply .close { position: absolute; top: 6px; right: 10px; background: none; border: 0; font-size: 18px; color: var(--muted); }
.reply .body { white-space: pre-wrap; padding-right: 18px; }
.reply .row { margin-top: 10px; }
.ask { position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line); z-index: 20; }
.ask input { flex: 1; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px; padding: 11px 16px; font: inherit; outline: none; }
.send { width: 44px; border: 0; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-size: 16px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 140px; background: var(--text); color: var(--bg);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; z-index: 30; max-width: 90vw; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: s .8s linear infinite; vertical-align: -2px; }
@keyframes s { to { transform: rotate(360deg); } }

/* notes */
.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 4px; }
.filters .chip { white-space: nowrap; }
.filters .chip.on { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.note { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: start; padding: 10px 0; border-top: 1px solid var(--line); }
.note:first-of-type { border-top: 0; }
.note .ic { font-size: 18px; line-height: 1.2; }
.note .t { font-weight: 600; } .note .m { font-size: 12px; color: var(--muted); margin-top: 2px; }
.note .st { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--muted); white-space: nowrap; }
.st.Active { background: color-mix(in srgb, var(--cal-cfo3) 18%, transparent); color: var(--cal-cfo3); }
.st.Waiting { background: color-mix(in srgb, var(--flex) 22%, transparent); color: #8a5a00; }
.st.Done { background: color-mix(in srgb, var(--cal-personal) 18%, transparent); color: var(--cal-personal); }
.prio-High { border-left: 3px solid var(--clash); padding-left: 8px; }
.detail .title { font-size: 20px; font-weight: 700; margin: 2px 0 6px; }
.detail .meta { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.detail .body { white-space: pre-wrap; line-height: 1.5; }
.detail textarea { width: 100%; border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 10px; padding: 10px; font: inherit; min-height: 64px; margin: 8px 0; }
.block { display: flex; justify-content: space-between; font-size: 13px; padding: 6px 0; border-top: 1px solid var(--line); }
.block.past { color: var(--muted); }
a.link { color: var(--accent); text-decoration: none; font-weight: 600; }
