:root { --bg: #f5f6f8; --card: #fff; --ink: #1b1d21; --muted: #6b7280; --line: #e3e5e9; --accent: #1f5f8b; --in: #e8f0f6; --out: #f1f1f1; }
@media (prefers-color-scheme: dark) {
  :root { --bg: #15171a; --card: #1e2125; --ink: #e8eaed; --muted: #9aa0a6; --line: #2e3237; --accent: #6aa9d6; --in: #23384a; --out: #2a2d31; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, sans-serif; background: var(--bg); color: var(--ink); }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; width: 100%; }
.card { max-width: 360px; margin: 12vh auto; padding: 28px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; gap: 12px; }
.card h1 { font-size: 18px; margin: 0 0 6px; }
.card label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.card button, .reply button { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 9px; font-weight: 600; }
.err { color: #d33; min-height: 1em; margin: 0; }
.muted { color: var(--muted); }
header { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
header nav { display: flex; gap: 4px; flex: 1; }
.tab { background: none; border: 1px solid transparent; border-radius: 6px; padding: 5px 10px; color: var(--muted); }
.tab.active { border-color: var(--line); color: var(--ink); background: var(--bg); }
.link { background: none; border: 0; color: var(--accent); }
main { display: grid; grid-template-columns: 340px 1fr; height: calc(100vh - 52px); }
#list { border-right: 1px solid var(--line); overflow: auto; background: var(--card); }
.item { display: block; width: 100%; text-align: left; padding: 10px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; color: inherit; }
.item.sel { background: var(--bg); }
.item .top { display: flex; justify-content: space-between; gap: 8px; }
.item .pv { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
#detail { display: flex; flex-direction: column; overflow: hidden; }
.dh { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.msgs { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.m { max-width: 70%; padding: 8px 12px; border-radius: 10px; white-space: pre-wrap; word-wrap: break-word; }
.m.inbound { align-self: flex-start; background: var(--out); }
.m.outbound { align-self: flex-end; background: var(--in); }
.m small { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; }
.reply { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.reply textarea { min-height: 44px; resize: vertical; }
table { border-collapse: collapse; width: 100%; }
td, th { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); }
@media (max-width: 760px) {
  main { grid-template-columns: 1fr; height: auto; }
  #list { max-height: 40vh; border-right: 0; border-bottom: 1px solid var(--line); }
  #detail { min-height: 60vh; }
}
.pad { padding: 14px; }

/* launch additions */
#app:not([hidden]) { display: flex; flex-direction: column; height: 100vh; }
#app > header { flex: none; }
#view { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
#view > .split { flex: 1; min-height: 0; height: auto; }
#view > .filters { flex: none; }
.split { display: grid; grid-template-columns: 340px 1fr; height: calc(100% - 54px); }
.split > aside { border-right: 1px solid var(--line); overflow: auto; background: var(--card); }
.split > article { display: flex; flex-direction: column; overflow: auto; }
.filters { display: flex; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.filters input[type=search] { flex: 1; min-width: 200px; width: auto; }
.filters select { width: auto; }
.inline { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.inline input[type=checkbox] { width: auto; }
.inline input[type=number] { width: 80px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row select, .row input { width: auto; }
.stack { display: flex; flex-direction: column; gap: 10px; max-width: 640px; }
.stack.wide { max-width: none; }
.stack label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.stack label.inline { flex-direction: row; color: var(--ink); }
button[type=submit], .danger { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 8px 14px; font-weight: 600; }
.danger { background: #c0392b; }
.item.unread strong { font-weight: 800; }
.item.unread { border-left: 3px solid var(--accent); }
.badge { background: #c0392b; color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; margin-left: 4px; }
.chip.count { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip.good { color: #1e7e34; border-color: #1e7e34; }
.chip.bad { color: #c0392b; border-color: #c0392b; }
.warn { background: #fff6e0; color: #6b4d00; padding: 8px 10px; border-radius: 6px; }
@media (prefers-color-scheme: dark) { .warn { background: #3a2f12; color: #f3d98b; } }
.small { font-size: 12px; }
.code, code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; word-break: break-all; }
pre.code { padding: 10px; white-space: pre-wrap; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.panel .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.panel h3 { margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; align-items: end; }
.grid label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.flash { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--card); padding: 10px 16px; border-radius: 8px; z-index: 10; }
.flash.err { background: #c0392b; color: #fff; }
td.small { max-width: 360px; }
@media (max-width: 760px) {
  .split { grid-template-columns: 1fr; height: auto; }
  #app:not([hidden]) { height: auto; min-height: 100vh; }
  #view { overflow: visible; }
  .split > aside { max-height: 45vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .split > article { min-height: 55vh; }
  header nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  table { display: block; overflow-x: auto; }
}

/* SaaS additions */
.banner { background: #fff6e0; color: #6b4d00; padding: 8px 16px; border-bottom: 1px solid var(--line); flex: none; }
@media (prefers-color-scheme: dark) { .banner { background: #3a2f12; color: #f3d98b; } }
.meter { max-width: 420px; }
.meter .top { display: flex; justify-content: space-between; }
.meter .bar { height: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; margin-top: 4px; }
.meter .fill { height: 100%; background: var(--accent); width: 0; }
.meter .fill.high { background: #d68910; }
.meter .fill.full { background: #c0392b; }
.signup { max-width: 920px; margin: 0 auto; padding: 32px 16px; }
.signup .card { margin: 24px 0; max-width: 480px; }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--bg); }
