@font-face { font-family: "Instrument Serif"; src: url("/fonts/InstrumentSerif-Regular.ttf") format("truetype"); font-display: swap; }
@font-face { font-family: "Geist"; src: url("/fonts/Geist-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Geist"; src: url("/fonts/Geist-Medium.ttf") format("truetype"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Geist"; src: url("/fonts/Geist-SemiBold.ttf") format("truetype"); font-weight: 600; font-display: swap; }

:root {
  --accent: #2B45E0; --accent-ink: #ffffff; --accent-soft: #e8ebfc;
  --bg: #f6f7fb; --surface: #ffffff; --ink: #14161c; --muted: #5b6070; --rule: #dde1ea;
  --mine: #2B45E0; --mine-ink: #ffffff; --theirs: #ffffff; --theirs-ink: #14161c; --notice: #eef0f5;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #6f84ff; --accent-ink: #0b0d14; --accent-soft: #1d2340;
    --bg: #0d0f15; --surface: #161922; --ink: #eceef4; --muted: #9aa0b2; --rule: #262a36;
    --mine: #3d55e8; --mine-ink: #ffffff; --theirs: #1b1f2a; --theirs-ink: #eceef4; --notice: #151822;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 16px/1.45 "Geist", -apple-system, system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }

.app { height: 100dvh; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; background: var(--bg); }

.top { position: relative; display: flex; align-items: center; gap: 12px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--surface); border-bottom: 1px solid var(--rule); }
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--accent-soft); }
.who { flex: 1; min-width: 0; }
.name { font-family: "Instrument Serif", Georgia, serif; font-size: 24px; line-height: 1; }
.state { font-size: 13px; color: var(--muted); margin-top: 3px; }
.state.working { color: var(--accent); }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); fill: currentColor; flex: none; }
.icon-btn:hover { background: var(--notice); }
.menu { position: absolute; right: 12px; top: calc(54px + env(safe-area-inset-top)); background: var(--surface); border: 1px solid var(--rule);
  border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.12); padding: 6px; z-index: 5; min-width: 220px; }
.menu button { display: block; width: 100%; text-align: left; padding: 10px 12px; border-radius: 8px; }
.menu button:hover { background: var(--notice); }

.thread { flex: 1; overflow-y: auto; padding: 16px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.older { display: block; margin: 0 auto 12px; font-size: 13px; color: var(--accent); padding: 6px 12px; }
.day { text-align: center; font-size: 12px; color: var(--muted); margin: 18px 0 10px; }
.row { display: flex; margin: 3px 0; }
.row.me { justify-content: flex-end; }
.bubble { max-width: min(82%, 560px); padding: 9px 13px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--theirs); color: var(--theirs-ink); border: 1px solid var(--rule); }
.row.me .bubble { background: var(--mine); color: var(--mine-ink); border-color: transparent; border-bottom-right-radius: 6px; }
.row.agent .bubble { border-bottom-left-radius: 6px; }
.bubble a { color: inherit; text-decoration: underline; }
.bubble code { font-family: ui-monospace, Menlo, monospace; font-size: .9em; }
.meta { font-size: 11px; color: var(--muted); margin: 2px 6px 8px; }
.row.me + .meta { text-align: right; }
.via { opacity: .8; }
.notice { margin: 10px auto; max-width: 92%; background: var(--notice); border: 1px solid var(--rule); border-radius: 12px;
  padding: 9px 12px; font-size: 14px; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.notice::before { content: "Update"; display: block; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 3px; }
.files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.files img { max-width: 220px; max-height: 260px; border-radius: 12px; display: block; }
.files audio { max-width: 240px; }
.file-chip { display: inline-block; padding: 6px 10px; border-radius: 10px; background: rgba(127,127,127,.15); color: inherit; text-decoration: none; font-size: 14px; }

.working { display: flex; align-items: center; gap: 4px; padding: 8px 4px; color: var(--muted); font-size: 13px; }
.working span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: .3; animation: blink 1.2s infinite; }
.working span:nth-child(2) { animation-delay: .2s; } .working span:nth-child(3) { animation-delay: .4s; }
.working em { font-style: normal; margin-left: 8px; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.attachments { display: flex; gap: 8px; padding: 8px 16px 0; overflow-x: auto; background: var(--surface); }
.att { position: relative; flex: none; }
.att img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; display: block; }
.att .file-chip { height: 64px; display: grid; place-items: center; max-width: 160px; overflow: hidden; }
.att button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: var(--bg); font-size: 13px; line-height: 22px; }

.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--rule); }
.composer textarea { flex: 1; resize: none; max-height: 160px; min-height: 40px; padding: 9px 14px; border-radius: 20px;
  border: 1px solid var(--rule); background: var(--bg); color: var(--ink); font: inherit; font-size: 16px; outline: none; }
.composer textarea:focus { border-color: var(--accent); }
.send { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }

.recording { display: flex; align-items: center; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--rule); }
.recording .dot { width: 10px; height: 10px; border-radius: 50%; background: #e0353b; animation: blink 1s infinite; }
.recording .rec-label { flex: 1; color: var(--muted); font-size: 14px; }
.recording button { padding: 8px 14px; border-radius: 18px; }
.recording .primary { background: var(--accent); color: var(--accent-ink); }

.signed-out { height: 100dvh; display: grid; place-content: center; text-align: center; padding: 24px; }
.signed-out img { border-radius: 50%; margin: 0 auto 12px; }
.signed-out h1 { font-family: "Instrument Serif", Georgia, serif; font-weight: 400; font-size: 40px; margin: 0 0 6px; }
.muted { color: var(--muted); }

@media (max-width: 420px) { .bubble { max-width: 88%; } .files img { max-width: 180px; } }

/* ───── views + tab bar ───── */
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view[hidden] { display: none !important; }
.composer { padding-bottom: 8px; }
.recording { padding-bottom: 12px; }
.tabs { display: flex; background: var(--surface); border-top: 1px solid var(--rule); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
.tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; color: var(--muted); font-size: 11px; position: relative; }
.tabs button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--accent); }
.tabs .badge { position: absolute; top: 2px; left: calc(50% + 8px); min-width: 16px; height: 16px; border-radius: 8px; background: #e0353b; color: #fff;
  font-size: 10px; font-style: normal; line-height: 16px; padding: 0 4px; }

/* ───── dashboards ───── */
.dash { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.dash-inner { padding: 14px 14px 24px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: 16px; padding: 14px 14px 12px; }
.card.inner { border: 0; padding: 4px 0 0; background: none; }
.card h3 { margin: 0 0 10px; font-family: "Instrument Serif", Georgia, serif; font-weight: 400; font-size: 21px; line-height: 1.15;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card.inner h3 { font-family: "Geist", system-ui, sans-serif; font-size: 13px; font-weight: 600; color: var(--muted); }
.card h3 small { font-family: "Geist", system-ui, sans-serif; font-size: 12px; color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-bottom: 8px; }
.kpi { background: var(--bg); border: 1px solid var(--rule); border-radius: 12px; padding: 10px 12px; }
.kpi .kv { font-family: "Instrument Serif", Georgia, serif; font-size: 30px; line-height: 1.05; }
.kpi .kl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi .ks { font-size: 11.5px; margin-top: 3px; color: var(--muted); }
.kpi.warn .kv { color: #c2410c; }
.up { color: #1d7a4e; } .down { color: #c2410c; }
.chart { width: 100%; height: 90px; display: block; }
.chart rect { fill: var(--accent); }
.chart text { font-size: 4px; fill: var(--muted); font-family: "Geist", system-ui, sans-serif; }
.note, .empty { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }
.rank { list-style: none; margin: 0; padding: 0; }
.rank li { position: relative; display: flex; justify-content: space-between; gap: 10px; padding: 6px 8px; font-size: 14px; border-radius: 8px; overflow: hidden; }
.rank li i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent-soft); z-index: 0; border-radius: 8px; }
.rank li span { position: relative; z-index: 1; } .rank .k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .rank .v { font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; margin-top: 6px; }
.tbl th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 4px; border-bottom: 1px solid var(--rule); }
.tbl td { padding: 8px 4px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.chips span { font-size: 11px; background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 1px 6px; }
.seg { display: flex; background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; padding: 8px 6px; border-radius: 9px; font-size: 13.5px; color: var(--muted); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.stack { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--bg); }
.stack i, .legend i { display: inline-block; } .stack .a, .legend .a { background: var(--accent); } .stack .b, .legend .b { background: #9aa8f5; } .stack .c, .legend .c { background: #c9d0f8; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.legend i { width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; }
.hours { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; } .hours i { height: 26px; border-radius: 3px; background: var(--accent); }
.hlab { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.banner { border-radius: 16px; padding: 14px 16px; border: 1px solid; }
.banner.ok { background: #e3f2ea; border-color: #bfe0cc; color: #14532d; }
.banner.bad { background: #fdecea; border-color: #f5c2bd; color: #7f1d1d; }
.banner ul { margin: 6px 0 0; padding-left: 18px; font-size: 14px; } .banner small { display: block; margin-top: 6px; opacity: .75; font-size: 12px; }
.checks { list-style: none; margin: 0 0 6px; padding: 0; }
.checks li { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--rule); font-size: 14px; }
.checks li:last-child { border-bottom: 0; } .checks li span { margin-left: auto; color: var(--muted); font-size: 13px; text-align: right; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; }
.dot.ok { background: #22a06b; } .dot.bad { background: #e0353b; } .dot.warn { background: #e8a33d; }
.stamp { text-align: center; font-size: 12px; color: var(--muted); display: flex; justify-content: center; align-items: center; gap: 10px; }
.stamp button { color: var(--accent); font-size: 12px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .banner.ok { background: #0f2a1d; border-color: #1d4a33; color: #b7e4c7; }
  :root:not([data-theme="light"]) .banner.bad { background: #2c1214; border-color: #5c2226; color: #fecaca; }
  :root:not([data-theme="light"]) .stack .b, :root:not([data-theme="light"]) .legend .b { background: #4b5bb0; }
  :root:not([data-theme="light"]) .stack .c, :root:not([data-theme="light"]) .legend .c { background: #2c3570; }
}

.axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ───── add-to-home-screen guide (iPhone) ───── */
.guide { position: fixed; inset: 0; z-index: 50; background: rgba(10,12,20,.55); display: flex; align-items: flex-end; justify-content: center; padding: 16px 16px calc(84px + env(safe-area-inset-bottom)); }
.guide-card { background: var(--surface); color: var(--ink); border-radius: 22px; padding: 22px 20px 18px; max-width: 420px; width: 100%; text-align: center; }
.guide-card img { border-radius: 16px; border: 1px solid var(--rule); }
.guide-card h2 { font-family: "Instrument Serif", Georgia, serif; font-weight: 400; font-size: 26px; margin: 10px 0 12px; }
.guide-card ol { list-style: none; padding: 0; margin: 0 0 12px; text-align: left; }
.guide-card li { display: flex; gap: 12px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid var(--rule); font-size: 15px; line-height: 1.4; }
.guide-card li:last-child { border-bottom: 0; }
.guide-card li svg { vertical-align: -4px; color: var(--accent); }
.guide-card .step { flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 13px; display: grid; place-items: center; font-weight: 600; }
.guide-card .warn { background: #fff4e5; color: #8a4b00; border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.guide-card .small { font-size: 12.5px; margin: 0 0 14px; }
.guide-card button.primary { width: 100%; padding: 12px; border-radius: 14px; background: var(--accent); color: var(--accent-ink); font-size: 16px; }
.guide-arrow { position: fixed; bottom: calc(18px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); color: #fff; font-size: 34px; animation: bob 1.2s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, 8px); } }
