/* Shmangus web. The same palette as the app (lib/theme.tsx) — this is the same
   product on a bigger screen, and it should read that way at a glance. */
:root {
  --bg: #F7F6F3;
  --surface: #FFFFFF;
  --raised: #FFFFFF;
  --ink: #191813;
  --ink-muted: #6E6C63;
  --ink-faint: #A8A69C;
  --accent: #1F5B4E;
  --accent-soft: #E7EFEC;
  --danger: #B3402E;
  --success: #2E7D4F;
  --border: #E9E7E1;
  --bubble-user: #191813;
  --bubble-user-ink: #F7F6F3;
}
[data-theme="dark"] {
  --bg: #141412;
  --surface: #1E1E1B;
  --raised: #252522;
  --ink: #F1F0EB;
  --ink-muted: #A5A399;
  --ink-faint: #6E6C63;
  --accent: #6FB3A1;
  --accent-soft: #22332F;
  --danger: #D96A56;
  --success: #5CB884;
  --border: #2C2C28;
  --bubble-user: #F1F0EB;
  --bubble-user-ink: #141412;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--ink); }
a { color: var(--accent); }

/* ---- shell ---- */
#app { display: flex; height: 100vh; height: 100dvh; }
.sidebar {
  width: 220px; flex: none; display: flex; flex-direction: column;
  border-right: 1px solid var(--border); background: var(--surface); padding: 14px 10px;
  overflow-y: auto;
}
.wordmark { font-size: 19px; font-weight: 800; letter-spacing: -0.3px; padding: 6px 12px 14px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; border-radius: 10px; color: var(--ink-muted);
  font-weight: 600; font-size: 14px; text-align: left;
}
.nav-item:hover { background: var(--bg); color: var(--ink); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item .icon { width: 20px; text-align: center; font-size: 15px; }
.nav-item .badge {
  margin-left: auto; background: var(--accent); color: #fff; border-radius: 9px;
  font-size: 11px; font-weight: 700; padding: 1px 7px;
}
.sidebar .spacer { flex: 1; }
.sidebar .account { padding: 8px 12px; font-size: 12px; color: var(--ink-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.content { flex: 1; overflow-y: auto; padding: 22px clamp(14px, 4vw, 40px); }
.content > .inner { max-width: 860px; margin: 0 auto; }

/* ---- shared pieces ---- */
.page-title { font-size: 21px; font-weight: 800; margin-bottom: 14px; letter-spacing: -0.3px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px 16px; margin-bottom: 12px;
}
.row { display: flex; align-items: center; gap: 10px; }
.muted { color: var(--ink-muted); }
.faint { color: var(--ink-faint); }
.small { font-size: 12.5px; }
.grow { flex: 1; min-width: 0; }
.right { margin-left: auto; }

.btn {
  background: var(--ink); color: var(--bg); border-radius: 11px;
  padding: 9px 16px; font-weight: 700; font-size: 14px;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--ink-muted); border: 1px solid var(--border); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--border); }
.btn.sm { padding: 5px 11px; font-size: 12.5px; border-radius: 9px; }

.input, textarea.input {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: 11px; padding: 9px 13px; outline: none;
}
.input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 70px; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  padding: 7px 14px; border-radius: 10px; font-weight: 600; font-size: 13.5px;
  color: var(--ink-muted); background: var(--surface); border: 1px solid var(--border);
}
.tab.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.empty { text-align: center; color: var(--ink-faint); padding: 48px 0 32px; }
.spin {
  width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 12px;
  font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity 0.25s; z-index: 50; max-width: 90vw;
}
#toast.show { opacity: 1; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 40;
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 20px; width: 100%; max-width: 460px; max-height: 88vh; overflow-y: auto;
}
.modal h3 { font-size: 16px; margin-bottom: 12px; }
.modal .field { margin-bottom: 10px; }
.modal .field label { display: block; font-size: 12px; font-weight: 700; color: var(--ink-muted); margin-bottom: 4px; }

/* ---- chat ---- */
.chat-layout { display: flex; height: 100%; min-height: 0; }
.chat-list {
  width: 250px; flex: none; border-right: 1px solid var(--border);
  overflow-y: auto; padding: 10px;
}
.chat-list-item {
  display: block; width: 100%; text-align: left; padding: 10px 12px;
  border-radius: 10px; margin-bottom: 2px;
}
.chat-list-item:hover { background: var(--bg); }
.chat-list-item.active { background: var(--accent-soft); }
.chat-list-item .t { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list-item .p { font-size: 12px; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 20px clamp(12px, 3vw, 32px); }
.chat-scroll .inner { max-width: 760px; margin: 0 auto; }
.msg { margin-bottom: 14px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  background: var(--bubble-user); color: var(--bubble-user-ink);
  border-radius: 16px; border-bottom-right-radius: 5px; padding: 9px 14px; max-width: 85%;
  white-space: pre-wrap; overflow-wrap: break-word;
}
.msg.assistant .md { max-width: 100%; }
.composer { border-top: 1px solid var(--border); padding: 12px clamp(12px, 3vw, 32px); }
.composer .inner { max-width: 760px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: 13px;
  padding: 10px 14px; outline: none; resize: none; max-height: 160px;
}
.composer textarea:focus { border-color: var(--accent); }

/* markdown */
.md p { margin: 0 0 8px; }
.md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { margin: 12px 0 6px; line-height: 1.3; }
.md h1 { font-size: 19px; } .md h2 { font-size: 17px; } .md h3 { font-size: 15.5px; }
.md ul, .md ol { margin: 0 0 8px; padding-left: 22px; }
.md li { margin-bottom: 3px; }
.md code {
  background: var(--accent-soft); color: var(--accent); border-radius: 5px;
  padding: 1px 5px; font-family: ui-monospace, Menlo, monospace; font-size: 13px;
}
.md pre {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 13px; overflow-x: auto; margin: 0 0 8px;
}
.md pre code { background: none; color: var(--ink); padding: 0; }
.md table { border-collapse: collapse; margin: 0 0 8px; width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; font-size: 13.5px; }
.md th { background: var(--bg); }
.md blockquote { border-left: 3px solid var(--border); padding-left: 12px; color: var(--ink-muted); margin: 0 0 8px; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.notes-toggle { color: var(--ink-faint); font-size: 12.5px; font-weight: 700; margin-top: 6px; }
.notes-body { border-top: 1px solid var(--border); margin-top: 8px; padding-top: 8px; color: var(--ink-muted); font-size: 14px; }

/* ---- lists ---- */
.rem {
  display: flex; align-items: flex-start; gap: 10px; padding: 11px 4px;
  border-bottom: 1px solid var(--border);
}
.rem:last-child { border-bottom: none; }
.rem .tick {
  width: 22px; height: 22px; flex: none; margin-top: 1px;
  border: 2px solid var(--ink-faint); border-radius: 50%;
}
.rem .tick:hover { border-color: var(--success); }
.rem .title { font-weight: 600; }
.rem .when { font-size: 12.5px; color: var(--ink-muted); }
.rem .when.overdue { color: var(--danger); font-weight: 700; }
.rem .when.out { color: var(--accent); }

/* calendar */
.cal-head { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 11px; font-weight: 700; color: var(--ink-faint); margin-bottom: 4px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-day {
  min-height: 74px; border: 1px solid var(--border); border-radius: 9px;
  padding: 4px 6px; font-size: 12px; background: var(--surface); text-align: left;
}
.cal-day.other { opacity: 0.4; }
.cal-day.today { border-color: var(--accent); border-width: 2px; }
.cal-day .n { font-weight: 700; font-size: 11px; color: var(--ink-muted); }
.cal-day .ev {
  background: var(--accent-soft); color: var(--accent); border-radius: 5px;
  padding: 1px 5px; margin-top: 3px; font-size: 11px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* spending */
.stat-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.stat { flex: 1; min-width: 130px; }
.stat .v { font-size: 22px; font-weight: 800; letter-spacing: -0.5px; }
.stat .l { font-size: 12px; color: var(--ink-muted); font-weight: 600; }
.bar { height: 7px; background: var(--bg); border-radius: 4px; overflow: hidden; margin-top: 5px; }
.bar > div { height: 100%; background: var(--accent); border-radius: 4px; }
.bar.over > div { background: var(--danger); }
.tx { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--border); }
.tx:last-child { border-bottom: none; }
.tx .amt { font-weight: 700; white-space: nowrap; }
.tx .amt.reimb { color: var(--success); text-decoration: line-through; }

/* mail */
.mail-row { display: flex; gap: 10px; padding: 11px 4px; border-bottom: 1px solid var(--border); align-items: baseline; cursor: pointer; }
.mail-row:last-child { border-bottom: none; }
.mail-row.unseen .from, .mail-row.unseen .subj { font-weight: 800; }
.mail-row .from { width: 180px; flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-row .subj { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-body { white-space: pre-wrap; overflow-wrap: break-word; padding-top: 10px; }
.alias-badge { font-size: 11px; font-weight: 700; background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 2px 7px; }

/* drive */
.file-row { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.file-row:last-child { border-bottom: none; }

/* messages */
.thread-bubble { max-width: 75%; border-radius: 14px; padding: 8px 13px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--border); }
.thread-bubble.mine { margin-left: auto; background: var(--bubble-user); color: var(--bubble-user-ink); border: none; }

/* auth */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .wordmark { text-align: center; font-size: 26px; padding: 0 0 18px; }

/* ---- narrow screens: the sidebar becomes a top bar ---- */
@media (max-width: 720px) {
  #app { flex-direction: column; }
  .sidebar {
    width: 100%; flex-direction: row; align-items: center; overflow-x: auto; overflow-y: hidden;
    border-right: none; border-bottom: 1px solid var(--border); padding: 8px 10px; gap: 2px;
  }
  .wordmark { display: none; }
  .sidebar .spacer, .sidebar .account { display: none; }
  .nav-item { width: auto; flex: none; padding: 7px 11px; }
  .nav-item .label { display: none; }
  .nav-item .icon { width: auto; font-size: 17px; }
  .chat-list { width: 100%; position: absolute; inset: 0; z-index: 10; background: var(--surface); display: none; }
  .chat-list.open { display: block; }
  .mail-row .from { width: 110px; }
}
