:root {
  --ink: #1d232b; --muted: #6b7480; --line: #dfe3e8; --bg: #f5f6f8; --card: #fff;
  --accent: #e47911; --accent-dark: #b85f0a; --ok: #1f7a4d; --warn: #9a6400; --bad: #b3261e;
}
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
header { display: flex; align-items: center; gap: 24px; padding: 10px 24px; background: #232f3e; color: #fff; }
.brand { font-size: 18px; letter-spacing: .3px; }
nav { display: flex; align-items: center; gap: 4px; flex: 1; flex-wrap: wrap; }
nav a { color: #dfe6ee; text-decoration: none; padding: 6px 10px; border-radius: 6px; }
nav a.on, nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.who { margin-left: auto; color: #b9c3cf; display: flex; align-items: center; gap: 6px; }
.who button.link { color: #fff; }
.badge { background: var(--accent); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; }
main { padding: 20px 24px 60px; max-width: 1400px; margin: 0 auto; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 6px; }
section { margin-bottom: 26px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; align-items: start; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.card.narrow { max-width: 420px; }
table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #fafbfc; font-weight: 600; font-size: 13px; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
dl { display: grid; grid-template-columns: 170px 1fr; gap: 4px 12px; margin: 0 0 12px; }
dt { color: var(--muted); }
dd { margin: 0; }
label { display: block; margin: 0 0 10px; font-size: 13px; color: var(--muted); }
label.check { display: flex; gap: 8px; align-items: center; color: var(--ink); }
label.cur { display: inline-block; margin-right: 10px; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid #c9cfd6; border-radius: 6px; background: #fff; color: var(--ink); }
label > input, label > select, label > textarea { display: block; width: 100%; margin-top: 3px; }
label.cur input { width: 160px; display: inline-block; }
textarea { min-height: 70px; width: 100%; }
button { font: inherit; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--accent-dark); background: var(--accent); color: #fff; cursor: pointer; }
button:hover { background: var(--accent-dark); }
button.secondary { background: #fff; color: var(--ink); border-color: #c9cfd6; }
button.secondary:hover { background: #f0f2f4; }
button.danger { background: var(--bad); border-color: var(--bad); }
button.link { background: none; border: 0; color: var(--accent-dark); padding: 0 4px; text-decoration: underline; }
form.inline { display: inline; }
form.row { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
form.search { display: flex; gap: 6px; margin-bottom: 12px; }
form.search input { flex: 1; max-width: 420px; }
.muted { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 10px 0; }
.flash { background: #fff7e6; border: 1px solid #f0c36d; padding: 9px 12px; border-radius: 8px; margin-bottom: 14px; }
.warn { color: var(--warn); }
.error { color: var(--bad); }
.st { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; background: #eceff2; color: var(--ink); white-space: nowrap; }
.st-searcher { background: #e2efff; color: #144f8f; }
.st-submitted { background: #fff1db; color: #8a5300; }
.st-processing { background: #e2efff; color: #144f8f; }
.st-problem, .st-needs_customer { background: #fde7e5; color: var(--bad); }
.st-placed, .st-active, .st-done, .st-label_sent { background: #e2f4ea; color: var(--ok); }
.st-failed, .st-cancelled, .st-blocked { background: #eceff2; color: var(--muted); }
.account { border-top: 1px solid var(--line); padding: 10px 0; }
.account ul { margin: 4px 0; padding-left: 18px; }
.msg { border: 1px solid var(--line); border-left-width: 3px; border-radius: 6px; padding: 14px; margin: 18px 0; }
.msg.to_customer { border-color: var(--accent); }
.msg.from_customer { border-color: #144f8f; background: #fff; }
.msg p { margin: 2px 0 6px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }
audio { height: 32px; max-width: 100%; }
@media (max-width: 700px) { .grid { grid-template-columns: 1fr; } dl { grid-template-columns: 1fr; } header { flex-wrap: wrap; } }

.titlebar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.titlebar h2 { margin: 0; }
[hidden] { display: none !important; }
details.account > summary { cursor: pointer; padding: 2px 0; }
details.account h3 { font-size: 14px; margin: 6px 0; }
.alert-listen { background: #FFD400; color: #202124; padding: 6px 10px; border-radius: 6px; font-weight: 600; }
.ok { color: var(--ok); }

/* Keep action groups distinct and checkbox hit areas next to their labels. */
.card > h2:not(:first-child) { margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--line); }
label.check { width: fit-content; max-width: 100%; padding: 9px 12px; border: 1px solid #c9cfd6; border-radius: 6px; background: #f5f6f8; cursor: pointer; }
label.check:hover { background: #e9edf1; }
label.check > input { display: inline-block; width: auto; flex: 0 0 auto; margin: 0; cursor: pointer; }
.grid > *, dl > dd { min-width: 0; overflow-wrap: anywhere; }
th, td { overflow-wrap: normal; }
th.num, td.num { white-space: nowrap; }
.recording audio, .msg audio { display: block; width: 100%; max-width: 340px; margin: 8px 0; }
.transcript { white-space: normal; margin-bottom: 8px; }
.disclosure > summary { font-size: 16px; font-weight: 600; cursor: pointer; }
.disclosure[open] > summary { margin-bottom: 14px; }
button:focus-visible, summary:focus-visible, label.check:focus-within { outline: 2px solid #144f8f; outline-offset: 3px; }
button:disabled { opacity: .55; cursor: not-allowed; }
@media (max-width: 700px) {
  main { padding: 16px 12px 40px; }
  header { padding: 10px 12px; gap: 12px; }
  table { display: block; overflow-x: auto; }
  form.row > input, form.row > select { min-width: 0; max-width: 100%; }
}

.account h4 { font-size: 14px; margin: 16px 0 6px; }
.account-entries { list-style: none; padding: 0; margin: 0 0 14px; }
.account-entry { display: flex; align-items: baseline; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.account-entry > span { min-width: 0; overflow-wrap: anywhere; }
.account-entry > form.inline { display: inline-flex; flex: 0 0 auto; margin: 0; }
.account-entry button { white-space: nowrap; }

form.row:has(.completion-note) { align-items: end; gap: 10px; }
.completion-note { flex: 1 1 190px; min-width: 0; margin: 0; }
.completion-note > span { color: var(--accent-dark); font-size: 12px; font-weight: 600; }
.completion-note > small { display: block; margin: 2px 0 5px; color: var(--muted); font-size: 12px; }

.conversation { margin-block: 16px; padding: 16px; border: 1px solid var(--line, #ccd2da); border-radius: 6px; }
.conversation-entry { padding-block: 12px; border-bottom: 1px solid var(--line, #ccd2da); overflow-wrap: anywhere; }
.staff-messages { margin-top: 32px; }
.conversation audio { display: block; max-width: 100%; margin-block: 8px; }
.staff-compose { max-width: 70ch; }

/* Secondary customer detail stays on the same baseline where space permits. */
a.customer-phone { display: inline-block; color: var(--ink); font-size: 13px; line-height: inherit; text-decoration: none; white-space: nowrap; margin-inline-start: 6px; vertical-align: baseline; }
a.customer-phone:hover { text-decoration: underline; }
