:root {
  --navy: #1b2a4a;
  --blue: #2e5aac;
  --gold: #b8893b;
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1d2433;
  --muted: #667085;
  --line: #e4e8f0;
  --me: #2e5aac;
  --them: #eef1f7;
  --ok: #1f8a52;
  --bad: #c0392b;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(27, 42, 74, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); }
.hidden { display: none !important; }

.view { min-height: 100dvh; }
.center { display: flex; align-items: center; justify-content: center; padding: 24px; }

/* Cards (login / household) */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 32px; width: 100%; max-width: 400px;
}
.brand { font-size: 24px; font-weight: 700; color: var(--navy); }
.tag {
  font-size: 11px; font-weight: 600; color: var(--gold);
  border: 1px solid var(--gold); border-radius: 999px; padding: 2px 8px; vertical-align: middle; margin-left: 6px;
}
.subtitle { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 8px 0 22px; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
input, textarea {
  width: 100%; padding: 12px 14px; font-size: 15px; border: 1px solid var(--line);
  border-radius: 10px; background: #fbfcfe; color: var(--ink); font-family: inherit;
}
input:focus, textarea:focus { outline: none; border-color: var(--blue); background: #fff; }

button { cursor: pointer; font-family: inherit; font-size: 15px; font-weight: 600; border: none; border-radius: 10px; }
button.primary { background: var(--navy); color: #fff; padding: 13px; width: 100%; margin-top: 14px; }
button.primary:hover { background: #16223c; }
button.secondary { background: #fff; color: var(--navy); border: 1.5px solid var(--navy); padding: 11px; width: 100%; margin-top: 10px; }
button.secondary:hover { background: #f3f6fc; }
.link-btn { background: none; color: var(--muted); width: 100%; margin-top: 18px; font-weight: 500; }
.link-btn:hover { color: var(--ink); }

.msg { font-size: 13px; margin-top: 14px; padding: 10px 12px; border-radius: 8px; }
.msg.ok { background: #eaf7ef; color: var(--ok); }
.msg.err { background: #fbecea; color: var(--bad); }
.dev-link { display: inline-block; margin-top: 14px; color: var(--blue); font-size: 13px; word-break: break-all; }

.info-box { background: #f3f6fc; border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-top: 14px; text-align: center; font-size: 13px; color: var(--muted); }
.code { font-size: 28px; font-weight: 700; letter-spacing: 4px; color: var(--navy); margin-top: 8px; }
.divider { display: flex; align-items: center; text-align: center; color: var(--muted); font-size: 12px; margin: 20px 0 14px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.divider span { padding: 0 12px; }

/* Chat */
#view-chat { position: relative; display: flex; flex-direction: column; height: 100dvh; max-width: 720px; margin: 0 auto; background: var(--card); box-shadow: var(--shadow); }
.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--navy); color: #fff; }
.chat-header .title { font-weight: 700; font-size: 17px; }
.chat-header .sub { font-size: 12px; color: #b9c6e0; margin-top: 2px; }
.actions { display: flex; gap: 8px; }
.chip { background: rgba(255,255,255,0.14); color: #fff; padding: 8px 12px; font-size: 13px; }
.chip:hover { background: rgba(255,255,255,0.24); }
.chip.ghost { background: transparent; border: 1px solid rgba(255,255,255,0.35); }

.verify-banner { padding: 10px 18px; font-size: 13px; font-weight: 600; text-align: center; }
.verify-banner.ok { background: #eaf7ef; color: var(--ok); }
.verify-banner.bad { background: #fbecea; color: var(--bad); }
.verify-banner.info { background: #eef2fb; color: var(--navy); letter-spacing: 0.3px; }

.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; background: var(--bg); }
.bubble { max-width: 78%; padding: 10px 14px; border-radius: 16px; font-size: 15px; line-height: 1.4; word-wrap: break-word; white-space: pre-wrap; }
.bubble .meta { font-size: 11px; margin-top: 5px; opacity: 0.75; }
.row { display: flex; }
.row.me { justify-content: flex-end; }
.row.them { justify-content: flex-start; }
.row.me .bubble { background: var(--me); color: #fff; border-bottom-right-radius: 4px; }
.row.them .bubble { background: var(--them); color: var(--ink); border-bottom-left-radius: 4px; }
.empty { color: var(--muted); font-size: 14px; text-align: center; margin: auto; max-width: 280px; line-height: 1.5; }

.composer { display: flex; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); align-items: flex-end; background: var(--card); padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.composer textarea { resize: none; max-height: 140px; }
.send { background: var(--navy); color: #fff; padding: 12px 20px; align-self: stretch; }
.send:hover { background: #16223c; }
.send:disabled { opacity: 0.5; cursor: default; }

.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Quick-reply bar */
.qr-bar { display: flex; gap: 8px; overflow-x: auto; padding: 10px 14px; border-top: 1px solid var(--line); background: var(--card); -webkit-overflow-scrolling: touch; }
.qr-bar::-webkit-scrollbar { height: 0; }
.qr-chip { flex: 0 0 auto; background: #eef2fb; color: var(--navy); border: 1px solid #dce4f3; padding: 8px 13px; border-radius: 999px; font-size: 13.5px; font-weight: 500; white-space: nowrap; }
.qr-chip:hover { background: #e2eaf8; }
.qr-chip.more { background: var(--navy); color: #fff; border-color: var(--navy); font-weight: 600; }
.qr-tag { background: rgba(255,255,255,0.22); border-radius: 6px; padding: 0 5px; font-size: 10px; }
.row.them .qr-tag { background: rgba(27,42,74,0.12); }

/* Quick-reply panel */
.qr-panel { position: absolute; inset: 0; background: rgba(20,28,46,0.45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.qr-panel-card { background: var(--card); width: 100%; max-width: 720px; max-height: 82%; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 18px 18px 24px; box-shadow: 0 -8px 30px rgba(0,0,0,0.2); }
.qr-panel-head { display: flex; align-items: center; justify-content: space-between; font-size: 18px; font-weight: 700; color: var(--navy); }
.qr-done { background: none; color: var(--blue); font-weight: 600; padding: 4px 6px; }
.qr-hint { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin: 6px 0 16px; }
.qr-cat { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--gold); margin: 16px 0 8px; }
.qr-list { display: flex; flex-wrap: wrap; gap: 8px; }
.qr-list .qr-chip { white-space: normal; text-align: left; }
.qr-custom { display: inline-flex; align-items: stretch; }
.qr-custom .qr-chip { border-radius: 999px 0 0 999px; }
.qr-del { background: #f3d9d6; color: var(--bad); border: 1px solid #e9c4c0; border-left: none; border-radius: 0 999px 999px 0; padding: 0 10px; font-size: 12px; }
.qr-del:hover { background: #eec9c5; }
.qr-child-row, .qr-add { margin-top: 16px; }
.qr-inline { display: flex; gap: 8px; margin-top: 6px; }
.qr-inline input { flex: 1; }
.qr-mini { background: #fff; color: var(--navy); border: 1.5px solid var(--navy); padding: 0 16px; border-radius: 10px; font-weight: 600; }
.qr-mini.primary-mini { background: var(--navy); color: #fff; }
.qr-mini:hover { opacity: 0.9; }

/* Tabs + panes */
.tabs { display: flex; gap: 4px; padding: 8px 14px 0; background: var(--card); border-bottom: 1px solid var(--line); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tabs::-webkit-scrollbar { height: 0; }
.tab { flex: 0 0 auto; }
.tab { background: none; color: var(--muted); padding: 9px 16px; font-size: 14px; font-weight: 600; border-bottom: 2px solid transparent; border-radius: 0; }
.tab.active { color: var(--navy); border-bottom-color: var(--gold); }
.pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#pane-calendar { overflow-y: auto; background: var(--bg); padding: 16px; display: block; }

/* System (calendar) note in the thread */
.row.system { justify-content: center; }
.system-note { max-width: 88%; text-align: center; font-size: 12.5px; color: var(--muted); background: #eef2fb; border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px; }
.system-note .meta { font-size: 10px; margin-top: 3px; opacity: 0.8; }

/* Calendar form */
.cal-form { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 16px; }
.cal-row { display: flex; gap: 8px; margin-bottom: 8px; }
.cal-row > * { flex: 1; min-width: 0; }
#cal-type { padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fbfcfe; font-family: inherit; font-size: 15px; color: var(--ink); }
.cal-form input { margin-bottom: 8px; }
.cal-form .cal-row input { margin-bottom: 0; }
.cal-form button.primary { width: 100%; margin-top: 4px; }
.cal-hint { font-size: 12px; color: var(--muted); margin: 10px 0 0; line-height: 1.4; }

/* Agenda list */
.cal-list { display: flex; flex-direction: column; gap: 10px; }
.cal-empty { color: var(--muted); font-size: 14px; text-align: center; padding: 20px; }
.cal-item { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.cal-item.declined { opacity: 0.55; }
.cal-when { font-size: 12px; font-weight: 700; color: var(--blue); text-transform: uppercase; letter-spacing: 0.3px; }
.cal-title { font-size: 15px; font-weight: 600; color: var(--ink); margin: 3px 0; }
.cal-note { font-size: 13px; color: var(--muted); margin: 2px 0 0; }
.cal-meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.cal-type-badge { font-size: 11px; font-weight: 600; color: var(--navy); background: #eef2fb; border-radius: 999px; padding: 2px 9px; }
.cal-status { font-size: 12px; font-weight: 600; }
.cal-status.confirmed { color: var(--ok); }
.cal-status.proposed { color: var(--gold); }
.cal-status.declined { color: var(--bad); }
.cal-actions { margin-left: auto; display: flex; gap: 6px; }
.cal-btn { font-size: 13px; font-weight: 600; padding: 7px 14px; border-radius: 8px; }
.cal-btn.approve { background: var(--ok); color: #fff; }
.cal-btn.decline { background: #fff; color: var(--bad); border: 1px solid #e9c4c0; }

/* Expense receipt file label */
.exp-file-label { display: block; border: 1px dashed var(--line); border-radius: 10px; padding: 11px 12px; font-size: 14px; color: var(--muted); cursor: pointer; margin-bottom: 8px; background: #fbfcfe; }
.exp-file-label:hover { border-color: var(--blue); color: var(--ink); }
#exp-amount { text-align: right; }
.cal-note a { color: var(--blue); text-decoration: none; }
.cal-note a:hover { text-decoration: underline; }
.split-field { display: flex; align-items: center; gap: 6px; }
.split-field input { width: 64px; text-align: right; }
.split-field span { font-size: 13px; color: var(--muted); white-space: nowrap; }
#pane-info select, #info-category, #exp-category { padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fbfcfe; font-family: inherit; font-size: 15px; color: var(--ink); }

/* Composer attach button + chip + message images */
.attach-btn { flex: 0 0 auto; display: flex; align-items: center; justify-content: center; width: 40px; align-self: stretch; background: #eef2fb; color: var(--navy); border-radius: 10px; font-size: 22px; font-weight: 600; cursor: pointer; }
.attach-btn:hover { background: #e2eaf8; }
.attach-chip { margin: 0 14px 8px; font-size: 13px; color: var(--navy); background: #eef2fb; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; display: flex; justify-content: space-between; align-items: center; }
.attach-chip button { background: none; color: var(--bad); font-weight: 700; font-size: 14px; }
.bubble-img { display: block; max-width: 220px; max-height: 220px; border-radius: 10px; margin-bottom: 6px; }
.bubble-img-wrap { display: block; }
.seen-row { text-align: right; font-size: 11px; color: var(--muted); padding: 0 4px 4px; }

/* Journal textarea */
#jrn-text { resize: vertical; }

/* Home dashboard */
#pane-home { overflow-y: auto; background: var(--bg); padding: 16px; display: block; }
.home-wrap { display: flex; flex-direction: column; gap: 14px; }
.home-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.home-card h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--gold); }
.home-hero { background: var(--navy); color: #fff; border-radius: 12px; padding: 18px; }
.home-hero .h-title { font-size: 20px; font-weight: 700; }
.home-hero .h-sub { font-size: 13px; color: #b9c6e0; margin-top: 4px; }
.home-row { display: flex; align-items: flex-start; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; color: var(--ink); cursor: pointer; }
.home-row:first-of-type { border-top: none; }
.home-row .dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); margin-top: 6px; }
.home-row .dot.ok { background: var(--ok); }
.home-empty { color: var(--muted); font-size: 13px; padding: 4px 0; }
.home-link { color: var(--blue); font-size: 13px; font-weight: 600; cursor: pointer; margin-top: 8px; display: inline-block; }
.home-count { background: var(--bad); color: #fff; border-radius: 999px; font-size: 12px; font-weight: 700; padding: 1px 8px; margin-left: 6px; }

/* Tone-check nudge */
.tone-modal { position: absolute; inset: 0; background: rgba(20,28,46,0.5); display: flex; align-items: center; justify-content: center; z-index: 30; padding: 20px; }
.tone-card { background: var(--card); width: 100%; max-width: 440px; border-radius: 18px; padding: 22px; box-shadow: 0 16px 48px rgba(0,0,0,0.28); }
.tone-badge { display: inline-block; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; padding: 4px 12px; border-radius: 999px; }
.tone-badge.caution { background: #fbf2e2; color: var(--gold); }
.tone-badge.heated { background: #fbecea; color: var(--bad); }
.tone-lead { font-size: 15px; line-height: 1.5; color: var(--ink); margin: 12px 0 14px; }
.tone-flags { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.tone-flags li { background: #f7f9fc; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
.tone-flags li b { display: block; font-size: 13.5px; color: var(--navy); }
.tone-flags li span { display: block; font-size: 12.5px; color: var(--muted); margin-top: 2px; line-height: 1.45; }
.tone-biff { font-size: 12.5px; color: var(--muted); line-height: 1.5; background: #eef2fb; border-radius: 10px; padding: 10px 12px; margin: 0 0 16px; }
.tone-biff b { color: var(--navy); }
.tone-actions { display: flex; gap: 10px; }
.tone-actions .primary { margin-top: 0; flex: 1; }
.tone-send-anyway { flex: 0 0 auto; background: #fff; color: var(--muted); border: 1.5px solid var(--line); padding: 13px 16px; }
.tone-send-anyway:hover:not(:disabled) { color: var(--ink); border-color: var(--muted); }
.tone-send-anyway:disabled { opacity: 0.55; cursor: default; }

/* Billing banner (trial countdown / read-only notice) */
.billing-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; font-size: 13px; }
.billing-banner.trial { background: #fbf7ee; color: #7a5a1f; border-bottom: 1px solid #efe3c8; }
.billing-banner.readonly { background: #fbecea; color: #93271b; border-bottom: 1px solid #f0cfca; }
.billing-banner b { font-weight: 700; }
.bill-cta { flex: 0 0 auto; background: var(--navy); color: #fff; padding: 7px 14px; font-size: 13px; border-radius: 8px; }
.bill-cta:hover { background: #16223c; }

/* Plan picker modal */
.plan-modal { position: absolute; inset: 0; background: rgba(20,28,46,0.5); display: flex; align-items: center; justify-content: center; z-index: 30; padding: 20px; }
.plan-card { background: var(--card); width: 100%; max-width: 460px; border-radius: 18px; padding: 22px; box-shadow: 0 16px 48px rgba(0,0,0,0.28); }
.plan-head { display: flex; align-items: center; justify-content: space-between; font-size: 18px; font-weight: 700; color: var(--navy); }
.plan-sub { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 6px 0 16px; }
.plan-opts { display: flex; gap: 12px; }
.plan-opt { flex: 1; position: relative; border: 1px solid var(--line); border-radius: 14px; padding: 18px 14px 16px; text-align: center; }
.plan-opt.recommended { border: 2px solid var(--gold); }
.plan-badge { position: absolute; top: -10px; left: 50%; transform: translateX(-50%); background: var(--gold); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
.plan-amt { font-size: 26px; font-weight: 700; color: var(--navy); }
.plan-per { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.plan-note { font-size: 12px; color: var(--muted); margin: 8px 0 12px; min-height: 30px; line-height: 1.4; }
.plan-opt .primary, .plan-opt .secondary { margin-top: 0; padding: 10px; }
.plan-foot { font-size: 11.5px; color: var(--muted); text-align: center; line-height: 1.5; margin: 16px 0 0; }
.plan-card .msg { text-align: center; }

/* Expense outstanding-balance card */
.bal-card { border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; border: 1px solid var(--line); }
.bal-card.owed-you { background: #eaf7ef; border-color: #cfe9da; }
.bal-card.you-owe { background: #fbf2e2; border-color: #efe0c4; }
.bal-card.settled { background: #eef2fb; border-color: #dce4f3; }
.bal-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.bal-amount { font-size: 17px; color: var(--ink); margin-top: 3px; }
.bal-amount b { color: var(--navy); }
.bal-detail { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.bal-foot { font-size: 11.5px; color: var(--muted); margin-top: 8px; line-height: 1.4; }

/* Thread list + conversation view */
#thread-list-view, #thread-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.thread-list-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; font-weight: 700; color: var(--navy); border-bottom: 1px solid var(--line); }
#thread-list { flex: 1; overflow-y: auto; padding: 12px 14px; }
.thread-item { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; }
.thread-item:hover { border-color: var(--blue); }
.thread-item-top { display: flex; justify-content: space-between; gap: 8px; }
.thread-item-subj { font-weight: 600; color: var(--ink); }
.thread-item-time { font-size: 12px; color: var(--muted); flex: 0 0 auto; }
.thread-item-snippet { font-size: 13px; color: var(--muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-view-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--card); }
.thread-back { background: #eef2fb; color: var(--navy); font-weight: 600; padding: 7px 12px; border-radius: 8px; font-size: 13px; flex: 0 0 auto; }
.thread-subj { font-weight: 700; color: var(--navy); font-size: 16px; }
.thread-subj-input { flex: 1; }
