:root {
  --bg: #0e1014;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --track: #262b35;
  --text: #e7e9ee;
  --text-muted: #8b909c;
  --accent: #6b9ff2;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 70% -10%, #1a1f2b 0%, var(--bg) 55%);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  min-height: 100%;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { font-size: 26px; color: var(--accent); }
.topbar h1 { font-family: 'Fraunces', serif; font-size: 22px; margin: 0; font-weight: 600; }
.tagline { margin: 0; font-size: 12px; color: var(--text-muted); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.status { font-size: 12px; color: var(--text-muted); padding: 3px 9px; border: 1px solid var(--border); border-radius: 99px; }
.db-indicator { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.db-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-muted); display: inline-block; transition: background .2s; }
.db-dot.ok { background: #5fd28a; box-shadow: 0 0 7px rgba(95,210,138,.7); }
.db-dot.off { background: #f2554d; box-shadow: 0 0 7px rgba(242,85,77,.6); }
.db-dot.pending { background: #f2a25f; box-shadow: 0 0 7px rgba(242,162,95,.6); }
.user-info { font-size: 12px; color: var(--text-muted); }

.btn-ghost {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 9px; padding: 6px 12px; cursor: pointer; font-size: 13px;
  transition: background .15s, border-color .15s;
}
.btn-ghost:hover { background: var(--surface-2); border-color: var(--accent); }

/* ---------- year bar ---------- */
.yearbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 22px; border-bottom: 1px solid var(--border);
}
.year-label { font-family: 'Fraunces', serif; font-size: 20px; min-width: 64px; text-align: center; }
.breadcrumb { display: flex; align-items: center; gap: 6px; margin-left: 8px; flex: 1; flex-wrap: wrap; }
.crumb { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 14px; padding: 2px 4px; }
.crumb:hover { text-decoration: underline; }
.crumb-sep { color: var(--text-muted); }
.goal-btn { margin-left: auto; }

/* ---------- view toggle (Day / Week / Month / Year) ---------- */
.view-toggle {
  display: inline-flex; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 3px; gap: 2px; margin-left: 6px;
}
.view-toggle button {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 13px; font-family: inherit; padding: 5px 14px; border-radius: 7px;
  transition: background .15s, color .15s;
}
.view-toggle button:hover { color: var(--text); }
.view-toggle button.active { background: var(--accent); color: #0b1220; font-weight: 600; }

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: 1fr 380px; gap: 22px;
  padding: 22px; align-items: start;
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.map-pane { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }

/* ---------- fractal grid ---------- */
.fractal-grid { display: grid; gap: 14px; }
.fractal-grid.level-month { grid-template-columns: repeat(4, 1fr); }
.fractal-grid.level-week  { grid-template-columns: repeat(4, 1fr); }
.fractal-grid.level-day   { grid-template-columns: repeat(7, 1fr); }
@media (max-width: 600px) {
  .fractal-grid.level-month, .fractal-grid.level-week { grid-template-columns: repeat(3, 1fr); }
  .fractal-grid.level-day { grid-template-columns: repeat(4, 1fr); }
}

.cell {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 8px; cursor: pointer;
  transition: transform .12s, border-color .12s, box-shadow .12s;
}
.cell:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: var(--shadow); }
.cell-label { font-size: 12px; color: var(--text-muted); }
.cell-future { opacity: .4; }
.cell-muted { opacity: .55; }

.ring { display: block; }
.ring-pct { fill: var(--text); font-size: 18px; font-weight: 600; font-family: 'Inter', sans-serif; }
.cell-day .ring-pct { font-size: 15px; }

.skeleton { padding: 60px; text-align: center; color: var(--text-muted); }

/* ---------- legend ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.legend-item { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* ---------- detail pane ---------- */
.detail-pane { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; position: sticky; top: 22px; }
.detail-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 18px; padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.detail-head-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.detail-eyebrow { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.detail-head h2 { font-family: 'Fraunces', serif; font-size: 22px; margin: 0; line-height: 1.1; }
.detail-range { font-size: 12px; color: var(--text-muted); }
.detail-ring { flex: none; }
.detail-ring .ring-pct { font-size: 20px; }

.dim-grid { display: flex; flex-direction: column; gap: 10px; }
.dim-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; padding: 11px 13px; }
.dim-card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.dim-name { font-size: 13px; display: flex; align-items: center; gap: 7px; }
.dim-val { font-size: 15px; font-weight: 600; }
.dim-bar { height: 6px; background: var(--track); border-radius: 99px; overflow: hidden; }
.dim-bar span { display: block; height: 100%; border-radius: 99px; transition: width .4s; }
.dim-foot { display: flex; align-items: baseline; gap: 8px; margin-top: 6px; }
.dim-pct { font-size: 12px; font-weight: 600; color: var(--text); }
.dim-sub { font-size: 11px; color: var(--text-muted); }

/* ---------- hover tooltip ---------- */
.task-tip {
  position: absolute; z-index: 80; max-width: 240px; pointer-events: none;
  background: #0b0d12; border: 1px solid var(--border); border-radius: 9px;
  padding: 9px 11px; box-shadow: var(--shadow);
  display: none; flex-direction: column; gap: 4px;
}
.task-tip.open { display: flex; }
.task-tip strong { font-size: 13px; }
.task-tip .tt-sub { font-size: 11px; color: var(--accent); }
.task-tip .tt-desc { font-size: 12px; color: var(--text-muted); line-height: 1.35; }

/* ---------- click popover ---------- */
.task-pop {
  position: absolute; z-index: 90; width: 300px; max-width: calc(100vw - 20px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); display: none; overflow: hidden;
}
.task-pop.open { display: block; }
.pop-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-bottom: 2px solid var(--accent);
}
.pop-title { font-size: 15px; font-weight: 600; }
.pop-close { padding: 2px 8px; }
.pop-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 9px; }
.pop-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; }
.pop-k { color: var(--text-muted); font-size: 12px; flex: none; }
.pop-chip { font-size: 12px; padding: 2px 9px; border-radius: 99px; font-weight: 600; }
.pop-status { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.pop-status.on { color: #5fd28a; }
.pop-desc { font-size: 12.5px; color: var(--text-muted); line-height: 1.45; margin: 2px 0 0; }
.pop-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.pop-actions a { text-decoration: none; }

/* ---------- day cards ---------- */
.day-card { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.day-card h3 { font-size: 14px; margin: 0 0 10px; }
.duration { font-size: 12px; color: var(--accent); }
input[type=time], input[type=number] {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 7px;
  color: var(--text); padding: 5px 8px; font-family: inherit;
}

/* ---------- day timeline ---------- */
.day-timeline { display: flex; flex-direction: column; }
.timeline-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.tl-times { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tl-times label { font-size: 12px; color: var(--text-muted); display: flex; gap: 6px; align-items: center; }
.tl-edit.active { border-color: var(--accent); color: var(--accent); }

.timeline-body { position: relative; margin-left: 4px; }

.tl-hour { position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 8px; pointer-events: none; }
.tl-hour-label { font-size: 11px; color: var(--text-muted); width: 42px; flex: none; transform: translateY(-50%); }
.tl-hour-rule { flex: 1; height: 1px; background: var(--border); transform: translateY(-50%); opacity: .6; }

.tl-now { position: absolute; left: 50px; right: 0; height: 0; border-top: 2px solid #ff5d5d; z-index: 3; }
.tl-now span {
  position: absolute; right: 0; top: -9px; background: #ff5d5d; color: #1a0000;
  font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 99px;
}

.tl-block {
  position: absolute; left: 56px; right: 6px;
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 3px solid var(--text-muted); border-radius: 9px;
  padding: 4px 10px; overflow: hidden; z-index: 2;
  transition: background .12s, border-color .12s, opacity .12s;
}
.tl-block:hover { border-color: var(--accent); }
.tl-block.done { opacity: .92; background: color-mix(in srgb, var(--surface-2) 80%, #2f5d3f 20%); }
.tl-block-label { flex: 1; min-width: 0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-block.done .tl-block-label { text-decoration: line-through; color: var(--text-muted); }
.tl-time { font-size: 11px; color: var(--text-muted); flex: none; }
.tl-time-input { font-size: 11px; padding: 2px 4px; width: 86px; flex: none; }

.tl-check {
  width: 20px; height: 20px; flex: none; border-radius: 6px;
  border: 1.5px solid var(--border); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: #0b1220; background: var(--surface);
}
.tl-check.on { background: var(--accent); border-color: var(--accent); }
.tl-auto {
  width: 20px; height: 20px; flex: none; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--text-muted);
}
.tl-auto.on { color: #5fd28a; }

.btn-save { background: var(--accent); color: #0b1220; border: none; border-radius: 8px; padding: 7px 14px; font-weight: 600; cursor: pointer; }
.btn-save:hover { filter: brightness(1.08); }

.journal-list, .fit-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.journal-list li { font-size: 13px; color: var(--text-muted); }
.journal-list li.done { color: var(--text); }
.journal-list li.done::before { content: '✅ '; }
.journal-list li:not(.done)::before { content: '○ '; }
.fit-list li { font-size: 13px; }
.muted { color: var(--text-muted); font-size: 13px; }

/* editing affordances hidden until authed */
body:not(.authed) .btn-save { opacity: .5; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none;
  align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); width: 420px; max-width: 100%; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-family: 'Fraunces', serif; font-size: 17px; margin: 0; }
.modal-body { padding: 18px; }
.goal-form { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.goal-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; }
.goal-row em { color: var(--text-muted); font-style: normal; font-size: 11px; }
.goal-row input { width: 130px; }

/* ---------- control panel ---------- */
.modal.modal-wide { width: 580px; }
.cp-note {
  margin: 0 0 18px; line-height: 1.5; font-size: 12.5px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px;
}
.cp-note strong { color: var(--text); }

.cp-list { display: flex; flex-direction: column; gap: 12px; }
.cp-row {
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 3px solid var(--text-muted); border-radius: 11px; padding: 13px 15px 14px;
}
.cp-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.cp-name { font-size: 15px; font-weight: 600; }
.cp-input { display: flex; align-items: center; gap: 8px; }
.cp-input input {
  width: 128px; text-align: right; font-size: 16px; font-weight: 600;
  padding: 7px 11px; border-radius: 9px;
}
.cp-unit { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

.cp-breakdown { display: flex; flex-direction: column; gap: 10px; }
.cp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cp-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cp-cell {
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
  padding: 8px 11px; display: flex; flex-direction: column; gap: 3px;
}
.cp-cell span { font-size: 10px; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); }
.cp-cell b { font-size: 15px; }

.cp-bar { position: relative; height: 8px; background: var(--track); border-radius: 99px; }
.cp-bar-fill { position: absolute; left: 0; top: 0; height: 100%; border-radius: 99px; transition: width .3s; }
.cp-bar-mark { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); opacity: .85; border-radius: 2px; }

.cp-pace { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); }
.cp-pace.ok { color: #5fd28a; }
.cp-pace.behind { color: #f2a25f; }
.cp-pill {
  width: 17px; height: 17px; flex: none; border-radius: 50%; font-size: 10px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--track); color: var(--text-muted);
}
.cp-pace.ok .cp-pill { background: rgba(95,210,138,.18); color: #5fd28a; }
.cp-pace.behind .cp-pill { background: rgba(242,162,95,.18); color: #f2a25f; }

.cp-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 14px;
  margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border);
}

/* ---------- main tabs ---------- */
.tab-group { display: inline-flex; gap: 4px; margin-left: auto; }
.tab {
  background: transparent; border: 1px solid transparent; color: var(--text-muted);
  border-radius: 9px; padding: 7px 14px; cursor: pointer; font-size: 13px; font-family: inherit;
  transition: background .15s, color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); border-color: var(--accent); color: var(--text); }

/* ---------- control view (full page) ---------- */
.control-view { padding: 22px; }
.cp-wrap { max-width: 760px; margin: 0 auto; }
.cp-topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.cp-h2 { font-family: 'Fraunces', serif; font-size: 26px; margin: 2px 0 0; }
.cp-deploy { display: flex; align-items: center; gap: 12px; }
.cp-deploy-status { font-size: 12px; color: var(--text-muted); }
.cp-deploy-status.ok { color: #5fd28a; }
.cp-deploy-status.behind { color: #f2a25f; }
.cp-deploy .btn-save { padding: 9px 16px; }
.cp-deploy .btn-save.up-to-date {
  background: rgba(95,210,138,.16); color: #5fd28a; cursor: default;
}
.cp-deploy .btn-save:disabled { filter: none; }

.cp-card {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--text-muted); border-radius: 13px;
  padding: 16px 18px; margin-bottom: 14px;
}
.cp-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.cp-computed { font-size: 20px; font-weight: 700; }
.cp-computed small { font-size: 12px; color: var(--text-muted); font-weight: 400; margin-left: 2px; }

.cp-section { margin-bottom: 16px; }
.cp-field { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; margin-bottom: 14px; }
.cp-sub { font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 8px; }
.cp-money { display: inline-flex; align-items: center; gap: 0; }
.cp-money > span { background: var(--surface-2); border: 1px solid var(--border); border-right: none; border-radius: 8px 0 0 8px; padding: 7px 9px; color: var(--text-muted); font-size: 13px; }
.cp-money input { border-radius: 0 8px 8px 0 !important; width: 120px; text-align: right; }

.fx-list, .pf-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.fx-row { display: grid; grid-template-columns: 1fr auto 92px 36px; gap: 8px; align-items: center; }
.fx-row .cp-money input { width: 90px; }
.fx-label { min-width: 0; }
.fx-del, .pf-del { padding: 6px 9px; }
.pf-row { display: grid; grid-template-columns: 120px 1fr 1fr 36px; gap: 8px; align-items: center; }
.fx-period { padding: 7px 8px; }
.cp-fetch-note { line-height: 1.5; margin: 10px 0 0; }
.cp-fetch-note code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 11px; }

.cp-rates { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.cp-rates .cp-card { margin-bottom: 0; }
@media (max-width: 640px) {
  .cp-rates { grid-template-columns: 1fr; }
  .fx-row { grid-template-columns: 1fr 1fr; }
  .pf-row { grid-template-columns: 1fr 1fr; }
}
