:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #16181d;
  --muted: #6b7280;
  --border: #e3e6eb;
  --accent: #3b5bdb;
  --accent-ink: #ffffff;
  --good: #1f9d55;
  --warn: #c98a00;
  --bad: #d64545;
  --good-bg: #e7f6ee;
  --warn-bg: #fdf4dc;
  --bad-bg: #fdeaea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 14px;
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #22262e;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --border: #2a2f38;
    --accent: #7c93ff;
    --accent-ink: #0f1115;
    --good: #4cc38a;
    --warn: #e5b94a;
    --bad: #f07575;
    --good-bg: #16301f;
    --warn-bg: #33290f;
    --bad-bg: #3a1a1a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
small { color: var(--muted); font-size: .8em; font-weight: 400; }
h1, h2 { margin: 0; line-height: 1.25; }
h2 { font-size: 1rem; font-weight: 650; display: flex; align-items: center; gap: 6px; }
.ic { flex: none; }

/* ---- layout ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
}
.topbar h1 { font-size: 1.6rem; font-weight: 750; flex: 1; letter-spacing: -.02em; }
.topbar h1 .date { font-size: .95rem; margin-left: 4px; }
.topbar h1.filetitle { font-size: 1.05rem; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border-radius: 12px; color: var(--text); background: var(--surface-2); border: 0;
}
.content {
  max-width: 680px; margin: 0 auto;
  padding: 4px 16px calc(var(--tabbar-h) + var(--safe-b) + 88px);
  display: flex; flex-direction: column; gap: 12px;
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--border);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .68rem; font-weight: 550;
}
.tabbar a.on { color: var(--accent); }

.fab {
  position: fixed; z-index: 21; right: 18px;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  width: 56px; height: 56px; border-radius: 18px; border: 0;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 6px 20px rgba(59, 91, 219, .35);
}
.tab-files .fab, .tab-advisor .fab { display: none; }

/* ---- cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.card > h2 { margin-bottom: 10px; }
.subtle { color: var(--muted); font-size: .85rem; margin: 0; }
.center { text-align: center; }
.empty { color: var(--muted); font-size: .9rem; margin: 0; }
.section-title { margin: 12px 2px 0; font-size: 1.05rem; justify-content: space-between; }
.section-title .small { font-size: .85rem; font-weight: 500; }
.count { margin-left: auto; font-size: .8rem; font-weight: 500; color: var(--muted); }
.more { display: inline-block; margin-top: 6px; font-size: .85rem; }

.alert-card { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.alert-card h2 { color: var(--warn); }
ul.plain { margin: 0; padding-left: 18px; }
ul.plain li + li { margin-top: 6px; }

/* ---- tiles ---- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; color: var(--text); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.tile-label { font-size: .78rem; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-value { font-size: 1.45rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.delta { font-size: .78rem; font-weight: 600; }
.good { color: var(--good); } .warn { color: var(--warn); } .bad { color: var(--bad); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--border); flex: none; }
.dot.green { background: var(--good); } .dot.yellow { background: var(--warn); } .dot.red { background: var(--bad); }

/* ---- tasks ---- */
ul.tasks { list-style: none; margin: 0; padding: 0; }
.task-row { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 4px 8px; padding: 9px 0; border-top: 1px solid var(--border); }
.task-row:first-child { border-top: 0; padding-top: 2px; }
.task-row label {
  flex-direction: row; gap: 10px; align-items: flex-start; flex: 1 1 60%; min-width: 0;
  color: var(--text); font-size: .95rem; font-weight: 450;
}
.task-text { padding-top: 1px; }
.task-row.done .task-text { color: var(--muted); text-decoration: line-through; }
.task-row.overdue .task-text { color: var(--bad); }
.task-meta { display: flex; gap: 4px; flex-wrap: wrap; margin-left: 32px; }
input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 22px; height: 22px; margin: 0; border-radius: 7px;
  border: 2px solid var(--muted); background: var(--surface); display: inline-grid; place-items: center;
}
input[type="checkbox"]:checked { background: var(--good); border-color: var(--good); }
input[type="checkbox"]:checked::after {
  content: ""; width: 6px; height: 11px; border: solid #fff; border-width: 0 2.5px 2.5px 0;
  transform: translateY(-1px) rotate(45deg);
}
input[type="checkbox"].busy { opacity: .4; }
.chip {
  display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--text);
}
.chip.muted { color: var(--muted); font-weight: 500; }
.chip.red, .chip.off-track, .chip.blocked { background: var(--bad-bg); color: var(--bad); }
.chip.at-risk { background: var(--warn-bg); color: var(--warn); }
.chip.done { background: var(--good-bg); color: var(--good); }

/* ---- goals / progress ---- */
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width .4s ease; }
.bar.at-risk > span { background: var(--warn); }
.bar.off-track > span, .bar.blocked > span { background: var(--bad); }
.bar.done > span { background: var(--good); }
.goal-mini { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.goal-mini a { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; color: var(--text); }
.goal-mini .bar { grid-column: 1 / -1; }
.goal-title { font-size: .92rem; }
.pct { font-weight: 700; font-size: .9rem; font-variant-numeric: tabular-nums; }
.pct.big { font-size: 1.3rem; }
.goal-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; margin-bottom: 10px; }
.goal-meta { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 0; }
.why { color: var(--muted); font-size: .88rem; margin: 8px 0 0; }
.goal .tasks { margin-top: 10px; }
details > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: "›"; margin-left: 8px; color: var(--muted); transition: transform .2s; }
details[open] > summary::after { transform: rotate(90deg); }
details[open] > summary { margin-bottom: 10px; }

/* ---- deadlines ---- */
ul.deadlines { list-style: none; margin: 0; padding: 0; }
.deadlines li { display: grid; grid-template-columns: 56px 1fr auto; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); align-items: baseline; }
.deadlines li:first-child { border-top: 0; padding-top: 0; }
.deadlines .when { font-weight: 650; font-size: .85rem; font-variant-numeric: tabular-nums; }
.deadlines .left { font-size: .8rem; color: var(--muted); font-weight: 600; }
.deadlines li.warn .left { color: var(--warn); }
.deadlines li.bad .left, .deadlines li.bad .when { color: var(--bad); }
.inbox-link { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: .92rem; }

/* ---- numbers ---- */
.runway { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.runway strong { font-size: 1.3rem; }
.runway.good { background: var(--good-bg); } .runway.warn { background: var(--warn-bg); } .runway.bad { background: var(--bad-bg); }
.metric-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.metric-now { text-align: right; display: flex; flex-direction: column; white-space: nowrap; }
.metric-now .tile-value { font-size: 1.25rem; }
.chart { position: relative; height: 170px; margin-top: 10px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ---- forms ---- */
label { display: flex; flex-direction: column; gap: 5px; font-size: .85rem; color: var(--muted); font-weight: 550; }
input[type="text"], input[type="password"], input[type="search"], input[type="month"], textarea {
  font: inherit; font-size: 16px; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 11px; padding: 11px 12px; width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; line-height: 1.5; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .95rem; padding: 11px 16px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.block { width: 100%; }
.btn.small { padding: 7px 14px; }
.link { background: none; border: 0; color: var(--accent); font: inherit; font-weight: 550; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.error { color: var(--bad); background: var(--bad-bg); padding: 8px 12px; border-radius: 10px; margin: 0; font-size: .9rem; }

/* ---- sheets ---- */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 680px;
  background: var(--surface); color: var(--text); border-radius: 20px 20px 0 0;
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, .45); }
dialog.sheet form { display: flex; flex-direction: column; gap: 12px; padding: 16px 16px calc(16px + var(--safe-b)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }

/* ---- files ---- */
.crumbs { display: flex; flex-wrap: wrap; gap: 4px; font-size: .85rem; color: var(--muted); }
.crumbs .cur { color: var(--text); }
.searchbox { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 12px; padding: 0 12px; color: var(--muted); }
.searchbox input { background: transparent; border: 0; padding-left: 0; }
.searchbox input:focus { outline: none; }
ul.filelist { list-style: none; margin: 0; padding: 4px 0; }
.filelist li + li { border-top: 1px solid var(--border); }
.filelist li.empty { padding: 14px 16px; }
.filelist a { display: flex; align-items: center; gap: 12px; padding: 11px 16px; color: var(--text); min-height: 52px; }
.fname { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: .95rem; }
.fmeta { color: var(--muted); font-size: .8rem; }
.snippet { display: block; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fi { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--surface-2); color: var(--muted); flex: none; }
.fi.dir { color: var(--accent); }
.fi.pdf { color: var(--bad); }
.fi.docx { color: #2b6cb0; }
.fi.csv { color: var(--good); }
.fi.markdown { color: var(--text); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions .btn { width: 100%; }
.upload { margin: 0; }
.upload label { flex-direction: row; color: var(--text); font-size: .95rem; }

.prose { overflow-wrap: anywhere; line-height: 1.6; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose h1 { font-size: 1.4rem; margin: 1.2em 0 .5em; }
.prose h2 { font-size: 1.15rem; margin: 1.3em 0 .5em; display: block; }
.prose h3 { font-size: 1rem; margin: 1.2em 0 .4em; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li.task { list-style: none; margin-left: -1.3em; display: flex; gap: 8px; align-items: flex-start; }
.prose li.task > input { margin-top: 2px; }
.prose blockquote { margin: 1em 0; padding: 2px 14px; border-left: 3px solid var(--accent); color: var(--muted); }
.prose code { background: var(--surface-2); padding: 1px 5px; border-radius: 6px; font-size: .9em; }
.prose pre { background: var(--surface-2); padding: 12px; border-radius: 10px; overflow-x: auto; }
.prose pre code { background: none; padding: 0; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }
.prose img { max-width: 100%; height: auto; }
.prose table, .table-wrap table { border-collapse: collapse; font-size: .88rem; width: 100%; }
.prose table { display: block; overflow-x: auto; }
.prose th, .prose td, .table-wrap th, .table-wrap td { border-bottom: 1px solid var(--border); padding: 7px 10px; text-align: left; white-space: nowrap; }
.table-wrap { overflow-x: auto; padding: 4px 0; }
.table-wrap th { position: sticky; top: 0; background: var(--surface); }
.plain-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .85rem; margin: 0; }
.preview { max-width: 100%; height: auto; padding: 6px; }
.pdf { display: flex; flex-direction: column; gap: 10px; }
.pdf canvas { width: 100%; height: auto; border-radius: 8px; box-shadow: var(--shadow); background: #fff; }

.editor textarea { min-height: calc(100vh - 260px); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; }

/* ---- advisor ---- */
.prompts { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 14px; }
.prompt {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px;
  background: var(--surface-2); color: var(--text); font-size: .88rem; font-weight: 550;
}
.prompt.copied { background: var(--good-bg); color: var(--good); }
ul.linklist { list-style: none; margin: 0; padding: 0; }
.linklist li + li { border-top: 1px solid var(--border); }
.linklist a { display: block; padding: 9px 0; }
.review .prose { margin-top: 8px; }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 84px);
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-size: .88rem; font-weight: 550;
}

/* ---- login ---- */
body.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 28px 22px; box-shadow: var(--shadow);
}
.login-card img { align-self: center; border-radius: 14px; }
.login-card h1 { text-align: center; font-size: 1.4rem; }

@media (min-width: 720px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .fab { right: calc(50% - 340px); }
}
