:root {
  --bg: #f4f3f1; --panel: #ffffff; --panel2: #f8f7f5; --line: #e6e3de; --ink: #1c1b1a; --mute: #74706a;
  --acc: #e0407b; --acc-ink: #fff; --acc-soft: #fbe3ec; --in: #efeeeb; --out: #fadbe6; --note: #fff6d9;
  --ok: #23854f; --warn: #c27c00; --bad: #d23c3c;
  --grey: #8a8780; --blue: #3b7ddd; --orange: #e07a1f; --green: #23854f; --teal: #138a8a; --gold: #b8860b;
  --purple: #7b4fd6; --red: #d23c3c; --brown: #8b5a3c; --pink: #e0407b;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f11; --panel: #17171a; --panel2: #1d1d21; --line: #2a2a30; --ink: #ecebe8; --mute: #9a978f;
    --acc: #f0568f; --acc-soft: #3a1c28; --in: #232328; --out: #4a2234; --note: #3a3320;
    --grey: #9a978f; --blue: #6aa3f5; --orange: #f39a4c; --green: #4cc683; --teal: #3cc6c6; --gold: #e3b341;
    --purple: #a988ff; --red: #ff6b6b; --brown: #c99071; --pink: #f0568f; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0f0f11; --panel: #17171a; --panel2: #1d1d21; --line: #2a2a30; --ink: #ecebe8; --mute: #9a978f;
  --acc: #f0568f; --acc-soft: #3a1c28; --in: #232328; --out: #4a2234; --note: #3a3320;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--acc); outline-offset: -1px; }
button { cursor: pointer; }
a { color: var(--acc); }

.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; white-space: nowrap; }
.btn:hover { border-color: var(--mute); }
.btn.primary { background: var(--acc); border-color: var(--acc); color: var(--acc-ink); font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.ghost { background: none; border-color: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.icon { background: none; border: 0; padding: 6px 8px; border-radius: 8px; font-size: 18px; line-height: 1; }
.icon:hover { background: var(--panel2); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--panel2); border: 1px solid var(--line); white-space: nowrap; }
.badge.obs { background: #fff3d6; color: #8a5a00; border-color: #f0d48a; }
.badge.live { background: #dff5e8; color: #17663b; border-color: #a7e0be; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge.obs { background: #3a2f12; color: #f3c75a; border-color: #5a4a1a; } :root:not([data-theme="light"]) .badge.live { background: #133122; color: #6fdc9d; border-color: #1f5a3a; } }
.mute { color: var(--mute); }
.err { color: var(--bad); min-height: 1em; margin: 6px 0; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px; width: 100%; max-width: 340px; display: grid; gap: 12px; box-shadow: var(--shadow); }
.login-card label { display: grid; gap: 4px; font-size: 13px; color: var(--mute); }
.brand { font-size: 17px; letter-spacing: .2px; }
.brand b { color: var(--acc); }

/* top bar */
#app { height: 100%; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 14px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.top nav { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav { background: none; border: 0; padding: 7px 10px; border-radius: 8px; color: var(--mute); font-weight: 500; white-space: nowrap; }
.nav.on { color: var(--ink); background: var(--panel2); }
.top-right { display: flex; align-items: center; gap: 8px; }

/* inbox: three panes */
.inbox-view { flex: 1; min-height: 0; display: grid; grid-template-columns: 330px minmax(0, 1fr) 340px; }
.list-pane, .chat-pane, .sheet-pane { min-width: 0; }
.list-pane, .sheet-pane { background: var(--panel); min-height: 0; display: flex; flex-direction: column; }
.list-pane { border-right: 1px solid var(--line); }
.sheet-pane { border-left: 1px solid var(--line); overflow-y: auto; }
.chat-pane { min-height: 0; display: flex; flex-direction: column; }
.search { padding: 10px 10px 6px; }
/* every status visible at once, on several lines: no sideways scrolling (a mouse can't do it) */
.tabs { display: flex; flex-wrap: wrap; gap: 5px; padding: 4px 10px 8px; border-bottom: 1px solid var(--line); }
.tab { flex: none; background: var(--panel2); border: 1px solid var(--line); border-radius: 99px; padding: 3px 9px; font-size: 12.5px; color: var(--mute); }
.tab.on { background: var(--acc-soft); border-color: var(--acc); color: var(--acc); font-weight: 600; }
.tab .n { margin-left: 5px; font-size: 11px; opacity: .85; }
.fan-list { overflow-y: auto; flex: 1; }
.fan { display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; position: relative; }
.fan:hover { background: var(--panel2); }
.fan.on { background: var(--acc-soft); }
.fan.on::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--acc); }
.avatar { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--acc-soft); color: var(--acc); font-weight: 700; font-size: 14px; position: relative; }
.avatar .unread { position: absolute; top: -4px; left: -4px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--acc); color: #fff; font-size: 11px; display: grid; place-items: center; padding: 0 5px; }
.avatar .star { position: absolute; bottom: -3px; right: -3px; font-size: 13px; }
.fan-main { flex: 1; min-width: 0; }
.fan-top { display: flex; justify-content: space-between; gap: 8px; }
.fan-top b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fan-top time { color: var(--mute); font-size: 12px; flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 3px 0; }
.chip { font-size: 11px; padding: 1px 7px; border-radius: 99px; border: 1px solid currentColor; white-space: nowrap; line-height: 1.5; }
.chip.tag { background: var(--acc-soft); color: var(--acc); border-color: transparent; }
.chip.money { color: var(--ok); }
.chip.wait { color: var(--warn); }
.chip.wait.late { color: #fff; background: var(--bad); border-color: var(--bad); font-weight: 600; }
.chip.alert { color: #fff; background: var(--bad); border-color: var(--bad); }
.chip.test { color: var(--purple); }
.preview { color: var(--mute); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview.unread { color: var(--ink); font-weight: 600; }
.cat { font-weight: 600; }
.c-grey { color: var(--grey); } .c-blue { color: var(--blue); } .c-orange { color: var(--orange); } .c-green { color: var(--green); }
.c-teal { color: var(--teal); } .c-gold { color: var(--gold); } .c-purple { color: var(--purple); } .c-red { color: var(--red); }
.c-brown { color: var(--brown); } .c-pink { color: var(--pink); }
.list-empty { padding: 30px 16px; color: var(--mute); text-align: center; }

/* chat */
.empty { margin: auto; color: var(--mute); }
.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-head { display: flex; align-items: center; gap: 4px; padding: 8px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.chat-head .who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-head .who b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head small { color: var(--mute); font-size: 12px; }
.chat-head small.typing { color: var(--acc); }
.back { display: none; font-size: 26px; padding: 0 8px; }
.sheet-toggle { display: none; }
.banner { background: #fff3d6; color: #6b4600; padding: 7px 14px; font-size: 13px; border-bottom: 1px solid #f0d48a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .banner { background: #3a2f12; color: #f3c75a; border-color: #5a4a1a; } }
.messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; font-size: 12px; color: var(--mute); background: var(--panel); border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; margin: 8px 0; }
.msg { max-width: min(78%, 560px); align-self: flex-start; position: relative; }
.msg.out { align-self: flex-end; }
.bubble { background: var(--in); padding: 7px 11px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.out .bubble { background: var(--out); }
.msg.flash .bubble { outline: 2px solid var(--acc); }
.msg.deleted .bubble { opacity: .55; text-decoration: line-through; }
.meta { font-size: 11px; color: var(--mute); margin-top: 2px; display: flex; gap: 8px; align-items: center; }
.msg.out .meta { justify-content: flex-end; }
.meta button { background: none; border: 0; color: var(--mute); font-size: 11px; padding: 0; }
.meta button:hover { color: var(--acc); }
.msg.note { align-self: center; max-width: 90%; }
.msg.note .bubble { background: var(--note); font-size: 13px; border-radius: 10px; }
.media-img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin-bottom: 4px; cursor: zoom-in; background: var(--panel2); min-width: 120px; min-height: 80px; }
.media-video { display: block; max-width: 100%; max-height: 360px; border-radius: 10px; margin-bottom: 4px; background: #000; }
.media-video.round { width: 220px; height: 220px; border-radius: 50%; object-fit: cover; }
.media-thumb { position: relative; display: inline-block; cursor: pointer; margin-bottom: 4px; }
.media-thumb img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; min-width: 160px; min-height: 100px; background: #000; }
.media-thumb.round img { width: 220px; height: 220px; border-radius: 50%; object-fit: cover; }
.media-thumb::after { content: "▶"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 34px; text-shadow: 0 2px 8px rgba(0,0,0,.6); }
audio { display: block; width: 260px; max-width: 100%; margin-bottom: 4px; }
.doc { display: inline-flex; gap: 6px; align-items: center; margin-bottom: 4px; }
.older { align-self: center; margin-bottom: 6px; }
.quickbar { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 10px 0; }
.quickbar .btn { font-size: 13px; padding: 5px 10px; }
.quickbar .btn.next { border-color: var(--acc); color: var(--acc); font-weight: 600; }
.composer { display: flex; gap: 6px; align-items: flex-end; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); margin-top: 6px; }
.composer textarea { resize: none; max-height: 160px; border-radius: 18px; padding: 9px 14px; }
.send { border-radius: 50%; width: 40px; height: 40px; padding: 0; flex: none; }

/* sheet */
#sheet { padding: 12px; display: grid; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.sheet-pane .card { background: var(--panel2); }
.card h4 { margin: 0 0 8px; font-size: 11px; letter-spacing: .6px; color: var(--mute); text-transform: uppercase; display: flex; justify-content: space-between; align-items: center; }
.sheet-head { display: flex; gap: 10px; align-items: center; }
.sheet-head .avatar { width: 44px; height: 44px; }
.sheet-head b { display: block; }
.field-row { display: grid; gap: 2px; padding: 7px 0; border-top: 1px solid var(--line); }
.field-row:first-of-type { border-top: 0; }
.field-label { font-size: 11px; letter-spacing: .5px; color: var(--mute); display: flex; justify-content: space-between; gap: 6px; }
.field-label button { background: none; border: 0; color: var(--mute); font-size: 12px; padding: 0 2px; }
.field-label button:hover { color: var(--acc); }
.field-value { overflow-wrap: anywhere; }
.field-value.empty { color: var(--mute); font-style: italic; }
.src { font-size: 12px; color: var(--mute); cursor: pointer; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.src:hover { color: var(--acc); }
.manual { font-size: 11px; color: var(--purple); }
details.section { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel2); padding: 0 12px; }
details.section summary { cursor: pointer; padding: 10px 0; font-weight: 600; display: flex; justify-content: space-between; list-style: none; }
details.section summary::-webkit-details-marker { display: none; }
details.section summary .n { color: var(--mute); font-weight: 500; }
.show-empty { background: none; border: 0; color: var(--acc); font-size: 12px; padding: 4px 0 10px; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 4px 0 2px; }
.bar i { display: block; height: 100%; background: var(--acc); }
.alert-box { border-color: var(--bad); }
.alert-box h4 { color: var(--bad); }
.alert-item { display: flex; gap: 8px; justify-content: space-between; align-items: flex-start; padding: 4px 0; }
.tags-edit { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.tags-edit .chip { cursor: pointer; }
.tags-edit input { flex: 1; min-width: 110px; padding: 4px 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.form-row { display: grid; gap: 4px; margin-bottom: 8px; }
.form-row > span { font-size: 12px; color: var(--mute); }
.sale-row { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-top: 1px solid var(--line); font-size: 13px; }
.sale-row:first-child { border-top: 0; }
.filling { font-size: 12px; color: var(--acc); }
.ai-sugg { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; font-size: 13px; color: var(--mute); }

/* pages */
.page { flex: 1; overflow-y: auto; padding: 16px; }
.page-inner { max-width: 1000px; margin: 0 auto; display: grid; gap: 14px; }
.page h2 { margin: 6px 0 0; font-size: 20px; }
.page h3 { margin: 0 0 10px; font-size: 15px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.stat span { color: var(--mute); font-size: 12px; display: block; }
.stat b { font-size: 22px; font-variant-numeric: tabular-nums; }
table { width: 100%; border-collapse: collapse; }
td, th { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 13px; }
th { color: var(--mute); font-weight: 600; font-size: 12px; }
pre.report { white-space: pre-wrap; font: inherit; margin: 0; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.note-box { background: var(--note); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.pw { font: 600 18px ui-monospace, Menlo, monospace; background: var(--panel2); padding: 8px 10px; border-radius: 8px; user-select: all; }

/* modal + toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-card { background: var(--panel); border-radius: 14px; padding: 18px; width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto; display: grid; gap: 10px; }
.modal-card img, .modal-card video { max-width: 100%; max-height: 50vh; border-radius: 10px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal.viewer .modal-card { max-width: 92vw; background: transparent; padding: 0; }
.modal.viewer img { max-height: 88vh; max-width: 92vw; margin: auto; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 10px; z-index: 60; max-width: calc(100% - 32px); font-size: 13px; }
.toast.bad { background: var(--bad); color: #fff; }

/* tablets: the sheet slides over the chat */
@media (max-width: 1150px) {
  .inbox-view { grid-template-columns: 300px minmax(0, 1fr); }
  .sheet-pane { display: none; }
  .sheet-toggle { display: inline-block; }
  .inbox-view.show-sheet .sheet-pane { display: flex; position: fixed; right: 0; top: 0; bottom: 0; width: min(380px, 100%); z-index: 30; box-shadow: -8px 0 24px rgba(0,0,0,.2); }
  .inbox-view.show-sheet .sheet-pane .back-sheet { display: inline-block; }
}
.back-sheet { display: none; }
/* phones: one pane at a time */
@media (max-width: 760px) {
  .top { padding: 6px 10px; gap: 8px; }
  .top .brand { display: none; }
  .nav { padding: 6px 8px; font-size: 13px; }
  #shift-btn { font-size: 12px; padding: 4px 8px; }
  .inbox-view { grid-template-columns: minmax(0, 1fr); }
  .top-right { gap: 4px; }
  #mode-badge { display: none; }
  .inbox-view .chat-pane { display: none; }
  .inbox-view.show-chat .list-pane { display: none; }
  .inbox-view.show-chat .chat-pane { display: flex; }
  .back { display: inline-block; }
  .msg { max-width: 88%; }
  .page { padding: 12px; }
  .grid2 { grid-template-columns: 1fr; }
}
