:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #6b7076;
  --line: #e6e6e3;
  --accent: #2f5fd0;
  --accent-text: #ffffff;
  --ok: #3f9b62;
  --warn: #c98a1b;
  --warn-bg: #fdf6e7;
  --urgent: #d0453a;
  --decision: #c98a1b;
  --action: #3f9b62;
  --hover: #f3f3f1;
  --open-bg: #fbfbfa;
  --c0: #2f5fd0;
  --c1: #3f9b8e;
  --c2: #c98a1b;
  --c3: #7a5fc4;
  --c4: #c25b6a;
  --c5: #c9cbcf;
  --radius: 12px;
  --space: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161719;
    --surface: #1e2023;
    --text: #e6e6e3;
    --muted: #9a9ea4;
    --line: #2c2f33;
    --accent: #7c9cf0;
    --accent-text: #10131a;
    --ok: #5cc184;
    --warn: #e0a940;
    --warn-bg: #2a2416;
    --urgent: #e06a60;
    --decision: #e0a940;
    --action: #5cc184;
    --hover: #24272a;
    --open-bg: #1b1d20;
  --c0: #7c9cf0;
  --c1: #5cc1b4;
  --c2: #e0a940;
  --c3: #a58ef0;
  --c4: #e08896;
  --c5: #4a4e54;
    --c0: #7c9cf0;
    --c1: #5cc1b4;
    --c2: #e0a940;
    --c3: #a58ef0;
    --c4: #e08896;
    --c5: #4a4e54;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #161719;
  --surface: #1e2023;
  --text: #e6e6e3;
  --muted: #9a9ea4;
  --line: #2c2f33;
  --accent: #7c9cf0;
  --accent-text: #10131a;
  --ok: #5cc184;
  --warn: #e0a940;
  --warn-bg: #2a2416;
  --urgent: #e06a60;
  --decision: #e0a940;
  --action: #5cc184;
  --hover: #24272a;
  --open-bg: #1b1d20;
  --c0: #7c9cf0;
  --c1: #5cc1b4;
  --c2: #e0a940;
  --c3: #a58ef0;
  --c4: #e08896;
  --c5: #4a4e54;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 22px; font-weight: 600; margin: 0 0 8px; }
p { margin: 0 0 12px; }

.page { max-width: 720px; margin: 0 auto; padding: 32px 16px 64px; }
.page.centered { min-height: 100vh; display: flex; align-items: center; justify-content: center; }

.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.top-right { display: flex; gap: 16px; align-items: baseline; flex-wrap: wrap; justify-content: flex-end; }
.tenant { font-size: 20px; font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 24px;
}
.card.narrow { max-width: 380px; width: 100%; text-align: center; padding: 40px 32px; }
.card.ghost { height: 66px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { text-align: center; margin-top: 48px; }

.button {
  display: inline-block;
  font: inherit;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.button:hover:not(:disabled) { border-color: var(--muted); }
.button:disabled { opacity: 0.45; cursor: default; }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); margin-top: 8px; }

.link { color: var(--accent); text-decoration: none; background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }
.link:hover { text-decoration: underline; }
.link.quiet { color: var(--muted); font-size: 18px; line-height: 1; }

.statusline { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.summary {
  display: flex; align-items: center; gap: 10px;
  background: none; border: 0; padding: 4px 0; font: inherit; color: var(--text); cursor: pointer; text-align: left;
}
.chevron { color: var(--muted); font-size: 13px; margin-left: 4px; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.busy { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

.problem { margin-top: 16px; padding: 12px 16px; border-radius: 8px; background: var(--warn-bg); font-size: 14px; }
.problem p { margin: 0 0 4px; }

.notice {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 16px; margin-bottom: 24px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--line); font-size: 14px; text-align: left;
}

.details { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 24px; margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--line); }
.block-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 8px; }
.row { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; padding: 3px 0; }

/* Inbox */
.inbox { margin-top: 8px; }
.section { margin-bottom: 28px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; padding: 0 4px; }
.section-toggle { display: flex; align-items: baseline; gap: 10px; background: none; border: 0; padding: 4px 0; font: inherit; color: var(--text); cursor: pointer; }
.section-title { font-size: 15px; font-weight: 600; }
.count { color: var(--muted); font-size: 13px; }
.cards { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.card-row + .card-row { border-top: 1px solid var(--line); }
.card-row.open { background: var(--open-bg); }
.row {
  display: grid; grid-template-columns: 10px minmax(90px, 160px) 1fr auto auto; align-items: center; gap: 14px;
  width: 100%; padding: 13px 20px; background: none; border: 0; font: inherit; color: var(--text); text-align: left; cursor: pointer;
}
.row:hover { background: var(--hover); }
.prio { width: 8px; height: 8px; border-radius: 50%; }
.prio.urgent { background: var(--urgent); }
.prio.decision { background: var(--decision); }
.prio.action { background: var(--action); }
.prio.none { background: transparent; }
.sender { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.line { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.line strong { font-weight: 600; }
.date { color: var(--muted); font-size: 13px; white-space: nowrap; }
.star { background: none; border: 0; padding: 0 2px; font-size: 16px; line-height: 1; color: var(--muted); cursor: pointer; }
.star.on { color: var(--decision); }
.row .star { font-size: 13px; cursor: inherit; }
.pad { padding: 16px 20px; margin: 0; }
.more { display: block; width: 100%; padding: 12px; background: none; border: 0; border-top: 1px solid var(--line); color: var(--accent); font: inherit; font-size: 14px; cursor: pointer; }
.more:hover { background: var(--hover); }

.detail { padding: 4px 20px 20px 44px; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.subject { font-size: 16px; font-weight: 600; }
.detail-summary { margin: 0 0 14px; }
.meta { font-size: 13px; margin-bottom: 12px; }
.meta-row { display: grid; grid-template-columns: 130px 1fr; gap: 8px; padding: 1px 0; word-break: break-word; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--hover); color: var(--muted); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.body-block, .effects { margin-bottom: 12px; }
.mail-frame { display: block; width: 100%; height: 60vh; margin-top: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.mail-text { margin-top: 8px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; white-space: pre-wrap; font-size: 13px; max-height: 50vh; overflow: auto; }
.fx-list { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.fx.failed { color: var(--urgent); }
.actions { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 14px; }
.action + .action { margin-top: 10px; }
.action-head { display: flex; align-items: baseline; gap: 10px; cursor: pointer; }
.compose { display: grid; gap: 8px; margin: 10px 0 0 26px; }
.field { display: grid; grid-template-columns: 60px 1fr; align-items: center; gap: 8px; }
.compose input, .compose textarea {
  font: inherit; font-size: 14px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%;
}
.compose textarea { min-height: 160px; resize: vertical; }
.compose input:focus, .compose textarea:focus { outline: none; border-color: var(--accent); }
.detail-foot { display: flex; align-items: center; gap: 10px; margin-top: 18px; }
.detail-foot .button.primary { margin-top: 0; }
.push { margin-left: auto; }

/* Custom instructions */
.instruct { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); display: grid; gap: 10px; }
.instruct textarea, .rule-form textarea {
  font: inherit; font-size: 14px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%; min-height: 72px; resize: vertical;
}
.instruct textarea:focus { outline: none; border-color: var(--accent); }
.instruct-foot { display: flex; align-items: center; gap: 14px; }
.instruct-foot .button.primary { margin-top: 0; }
.check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.review { margin: 4px 0 16px; padding: 16px 18px; border: 1px solid var(--accent); border-radius: 10px; background: var(--surface); }
.review-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 6px; }
.review-head .block-title { margin-bottom: 0; }
.review-summary { margin: 0 0 12px; }
.review-actions { display: grid; gap: 12px; margin-bottom: 14px; }
.proposed { padding-top: 12px; border-top: 1px solid var(--line); }
.proposed-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.proposed-type { font-weight: 600; font-size: 14px; }
.risk { font-size: 12px; color: var(--decision); }
.proposed .compose { margin-left: 0; }
.compose textarea.short { min-height: 64px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 4px; }
.rule { padding: 14px 20px; }
.rule + .rule { border-top: 1px solid var(--line); }
.rule.off .rule-text { color: var(--muted); }
.rule-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.rule-text { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 2px 0; font: inherit; color: var(--text); cursor: text; white-space: pre-wrap; }
.add-rule { margin-top: 14px; }
.rule-form { margin-top: 16px; }
.rule-form .compose { margin: 0; }

/* Tabs and phase 5 views */
.tabs { display: flex; gap: 22px; margin-bottom: 28px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tab { padding: 8px 0 10px; color: var(--muted); text-decoration: none; font-size: 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); border-bottom-color: var(--text); }
.link.on { text-decoration: underline; }
.searchbar { display: flex; gap: 10px; margin-bottom: 22px; flex-wrap: wrap; }
.search {
  flex: 1; min-width: 200px; font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; width: 100%;
}
.search:focus { outline: none; border-color: var(--accent); }
.searchbar select { font: inherit; font-size: 14px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.cards + .search, .search + .cards { margin-top: 14px; }
.row-lite { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; font-size: 14px; }
.task-row { grid-template-columns: 10px 1fr auto; }
.person-row { grid-template-columns: minmax(120px, 220px) 1fr auto; }
.sent-tasks .summary { width: 100%; justify-content: space-between; }
.sent-details { grid-template-columns: 1fr; }
.days { display: flex; gap: 14px; margin: 6px 0 12px; grid-column: 1 / -1; }
.back { margin-bottom: 14px; display: inline-block; }
.person .detail-head { margin-bottom: 16px; }
.profile { cursor: text; }
.profile.built { max-height: 50vh; overflow: auto; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; }
.profile-edit { min-height: 50vh !important; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px !important; }
.person-tasks { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.steps { margin: 6px 0 10px; max-height: 160px; overflow: auto; }
.draft-frame { height: 40vh; }
.md { font-size: 14px; }
.md-title { font-size: 17px; font-weight: 600; margin: 4px 0 8px; }
.md-heading { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 16px 0 6px; }
.md p { margin: 0 0 8px; }
.md ul { margin: 0 0 8px; padding-left: 18px; }
.md li { margin: 2px 0; }

/* Phase 6 */
.tab.secondary { font-size: 13px; }
.tab.first-secondary { margin-left: auto; }
.rule-line { margin: 2px 0 0; }
.rule.failed .row-lite span:first-child { color: var(--urgent); }
.section.log { margin-top: 36px; }
.match { display: flex; gap: 8px; }
.match select { font: inherit; font-size: 14px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.prompt { margin-bottom: 16px; }
.prompt .compose { margin-left: 0; }
.prompt-preview { margin: 6px 0 10px; }
.nowrap { white-space: nowrap; }

/* Pulse */
.pulse-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.pulse-head .days { margin: 0; }
.sep { width: 1px; background: var(--line); margin: 0 4px; }
.chart-card { padding: 20px 20px 14px; }
.chart { display: block; overflow: visible; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 10px; }
.chart .tick.mid { text-anchor: middle; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .bar:hover .hit, .chart .bar.on .hit { fill: var(--hover); }
.chart .seg { cursor: pointer; }
.c0 { fill: var(--c0); background: var(--c0); }
.c1 { fill: var(--c1); background: var(--c1); }
.c2 { fill: var(--c2); background: var(--c2); }
.c3 { fill: var(--c3); background: var(--c3); }
.c4 { fill: var(--c4); background: var(--c4); }
.c5 { fill: var(--c5); background: var(--c5); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: 12px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 9px; height: 9px; border-radius: 2px; flex: none; }
.hint { margin: 4px 0 24px; }
.pulse-row { grid-template-columns: 10px minmax(90px, 160px) 1fr auto; text-decoration: none; }
.summary-card { margin-top: 24px; }
.summary-controls { margin: 10px 0; flex-wrap: wrap; }
.summary-controls select { font: inherit; font-size: 14px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.summary-frame { height: 55vh; }

@media (max-width: 520px) {
  .sent-details { grid-template-columns: 1fr; }
  .person-row { grid-template-columns: 1fr auto; }
  .person-row .line { display: none; }
  .row { grid-template-columns: 10px 1fr auto; gap: 10px; padding: 12px 14px; }
  .row .line { grid-column: 2 / 4; }
  .detail { padding: 4px 14px 16px; }
  .meta-row { grid-template-columns: 1fr; }
  .statusline { flex-direction: column; align-items: flex-start; }
  .top { flex-direction: column; }
  .top-right { justify-content: flex-start; }
}
