:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --line: #e3e6ea;
  --brand: #1f5f99;
  --brand-text: #ffffff;
  --warn-bg: #fff4d6;
  --warn: #8a5a00;
  --danger: #b42318;
  --in: #eef1f5;
  --out: #dcebf9;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --card: #1b2027;
    --text: #e8ebef;
    --muted: #9aa4b2;
    --line: #2c333d;
    --brand: #5aa0e0;
    --brand-text: #0b1520;
    --warn-bg: #3a2e10;
    --warn: #f3c969;
    --danger: #f97066;
    --in: #232a33;
    --out: #1d3550;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
h1 { font-size: 1.15rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); min-height: 1.2em; }
.warn-text { background: var(--warn-bg); color: var(--warn); padding: .5rem .75rem; border-radius: 8px; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: .5rem;
  padding: calc(env(safe-area-inset-top) + .75rem) 16px .75rem;
  background: var(--card); border-bottom: 1px solid var(--line);
}
main { width: 100%; padding: 12px 16px calc(84px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  position: relative; background: none; color: var(--muted); border: 0; border-radius: 0;
  padding: .8rem .2rem; font-size: .8rem;
}
.tabbar button.on { color: var(--brand); font-weight: 600; }
.dot { position: absolute; top: .55rem; right: 22%; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.stack { display: flex; flex-direction: column; gap: .6rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row > label { flex: 1 1 8rem; }
.between { justify-content: space-between; }
.big { font-size: 1.3rem; font-weight: 700; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: .4rem; color: var(--text); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: .6rem; width: 100%;
}
input[type=checkbox] { width: auto; }
textarea { resize: vertical; }
button, .button {
  font: inherit; font-weight: 600; cursor: pointer; text-align: center; text-decoration: none;
  background: var(--brand); color: var(--brand-text); border: 0; border-radius: 8px; padding: .65rem 1rem;
}
button.secondary { background: transparent; color: var(--brand); border: 1px solid var(--brand); }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
button.small { padding: .25rem .6rem; font-size: .85rem; }
button:disabled { opacity: .5; }
fieldset { border: 1px solid var(--line); border-radius: 8px; display: flex; flex-wrap: wrap; gap: .6rem; }
details > summary { cursor: pointer; font-weight: 600; }

.badge { background: var(--brand); color: var(--brand-text); border-radius: 999px; padding: .05rem .5rem; font-size: .75rem; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; margin-bottom: 12px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .6rem;
  display: flex; flex-direction: column; text-decoration: none; color: var(--text);
}
.stat b { font-size: 1.3rem; }
.stat span { font-size: .8rem; color: var(--muted); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list a { display: flex; flex-direction: column; gap: .15rem; padding: .7rem 0; text-decoration: none; color: var(--text); }
ul.list.card { padding: 0 14px; }

.chip { font-size: .75rem; border-radius: 999px; padding: .1rem .55rem; background: var(--in); color: var(--muted); white-space: nowrap; }
.chip.active, .chip.interested { background: var(--out); color: var(--brand); }
.chip.booked { background: #d9f2e3; color: #13653a; }
.chip.opted_out, .chip.not_interested { color: var(--danger); }

.thread { display: flex; flex-direction: column; gap: .5rem; max-height: 55vh; overflow-y: auto; }
.msg { max-width: 85%; padding: .5rem .7rem; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg small { display: block; margin-top: .2rem; color: var(--muted); font-size: .7rem; }
.msg.inbound { align-self: flex-start; background: var(--in); }
.msg.outbound { align-self: flex-end; background: var(--out); }

table.stock { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.stock th, table.stock td { text-align: left; padding: .45rem .3rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.stock tr[data-id] { cursor: pointer; }
td.out { color: var(--danger); font-weight: 700; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(360px, 100%); }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 10;
  margin: 0 auto; max-width: 420px; padding: .7rem 1rem; border-radius: 10px;
  background: var(--text); color: var(--bg); text-align: center;
}
.toast.error { background: var(--danger); color: #fff; }

@media (min-width: 900px) {
  #app { display: grid; grid-template-columns: 200px 1fr; }
  #app.hidden { display: none; }
  .topbar { grid-column: 1 / -1; }
  .tabbar {
    position: sticky; top: 56px; align-self: start; height: calc(100vh - 56px);
    display: flex; flex-direction: column; border-top: 0; border-right: 1px solid var(--line);
    grid-column: 1; grid-row: 2;
  }
  .tabbar button { text-align: left; padding: .9rem 1.2rem; font-size: .95rem; }
  .dot { right: 1rem; top: 1.1rem; }
  main { grid-column: 2; grid-row: 2; padding-bottom: 24px; }
  .toast { bottom: 24px; }
}

.empty { padding: .7rem 0; }
