:root {
  --blue: #0b5cad; --blue-600: #094d92; --blue-50: #eaf2fc; --blue-100: #d3e4f8;
  --ink: #142236; --ink-2: #3c4b60; --muted: #6b7a90; --line: #dde5ef; --bg: #f4f7fb; --card: #fff;
  --green: #12805c; --green-50: #e6f5ef; --amber: #a15c00; --amber-50: #fff4e0; --red: #c0352b; --red-50: #fdeceb;
  --ai: #5b4bc4; --ai-50: #efedfb;
  --radius: 12px; --shadow: 0 1px 2px rgba(20, 34, 54, .06), 0 4px 16px rgba(20, 34, 54, .05);
  --font: "Segoe UI", Tahoma, system-ui, -apple-system, "Noto Sans Arabic", "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1 { font-size: 22px; margin: 0 0 4px; } h2 { font-size: 18px; margin: 0; } h3 { font-size: 15px; margin: 0 0 10px; } h4 { font-size: 13px; margin: 0 0 8px; display: flex; gap: 6px; align-items: center; }
.muted { color: var(--muted); }
.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* boot / login */
.boot { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); text-align: center; padding: 16px; }
.boot img, .login-card img, .brand img { border-radius: 10px; object-fit: cover; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--blue-50), var(--bg) 60%); }
.login-card { width: min(380px, 100%); display: grid; gap: 12px; text-align: center; padding: 28px; }
.login-card label { text-align: start; }
.error { color: var(--red); min-height: 1.2em; margin: 0; }

/* controls */
label { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); font-weight: 500; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; font-weight: 400; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px var(--blue-100); }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
label.check input { width: auto; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 12px; font-weight: 600; white-space: nowrap; width: auto; }
.btn:hover { border-color: var(--blue); color: var(--blue); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-600); color: #fff; }
.btn:disabled { opacity: .6; cursor: default; }
.btn.wide { justify-content: center; width: 100%; padding: 10px; }
select.btn { padding-inline-end: 26px; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 0; background: transparent; color: var(--ink-2); flex: none; }
.icon-btn:hover { background: var(--blue-50); color: var(--blue); }
.link { border: 0; background: none; color: var(--blue); padding: 0; font-weight: 600; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stack { display: grid; gap: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 12px; min-width: 0; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; background: var(--blue-50); color: var(--blue); }
.badge .i { width: 12px; height: 12px; }
.badge.ai { background: var(--ai-50); color: var(--ai); }
.badge.waiting { background: var(--amber-50); color: var(--amber); }
.badge.rep { background: var(--blue-50); color: var(--blue); }
.badge.ok { background: var(--green-50); color: var(--green); }
.badge.closed { background: #eef1f5; color: var(--muted); text-transform: capitalize; }
.tag { font-size: 11px; color: var(--muted); }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: #fff; border-bottom: 1px solid var(--line); height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand div { display: grid; line-height: 1.1; } .brand strong { color: var(--blue); } .brand span { font-size: 12px; color: var(--muted); }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.nav button { display: flex; align-items: center; gap: 6px; border: 0; background: none; padding: 8px 12px; border-radius: 8px; color: var(--ink-2); font-weight: 600; }
.nav button.active { background: var(--blue-50); color: var(--blue); }
.top-actions { display: flex; align-items: center; gap: 8px; }
.agent-switch { display: inline-flex; align-items: center; gap: 6px; border-radius: 99px; padding: 6px 12px; font-weight: 700; border: 1px solid; }
.agent-switch.on { background: var(--green-50); color: var(--green); border-color: #b5e2d0; }
.agent-switch.off { background: var(--red-50); color: var(--red); border-color: #f3c3bf; }
.agent-switch:disabled { cursor: default; }
.me { display: flex; align-items: center; gap: 6px; }
.avatar { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--blue-100); color: var(--blue); font-weight: 700; font-size: 12px; flex: none; }
.avatar.agent { background: var(--ai-50); color: var(--ai); } .avatar.closed { background: #eef1f5; color: var(--muted); }
.offline-bar { background: var(--amber-50); color: var(--amber); text-align: center; padding: 4px; font-weight: 600; font-size: 12px; }

/* inbox layout */
main.inbox { display: grid; grid-template-columns: 340px minmax(0, 1fr) 320px; height: calc(100vh - 56px); height: calc(100dvh - 56px); }
.pane { min-height: 0; background: #fff; }
.list-pane { display: flex; flex-direction: column; border-inline-end: 1px solid var(--line); }
.list-head { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.search { position: relative; } .search .i { position: absolute; inset-inline-start: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-inline-start: 34px; background: var(--bg); border-color: transparent; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 4px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; display: inline-flex; gap: 5px; }
.chip.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.chip b:empty { display: none; } .chip b { font-weight: 700; opacity: .8; }
.conv-list { overflow-y: auto; flex: 1; }
.conv { display: flex; gap: 10px; width: 100%; text-align: start; border: 0; border-bottom: 1px solid #eef2f7; background: #fff; padding: 12px; }
.conv:hover { background: #f8fafd; } .conv.active { background: var(--blue-50); }
.conv-main { display: grid; gap: 2px; min-width: 0; flex: 1; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; } .conv-top strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-top time { font-size: 11px; color: var(--muted); flex: none; }
.conv-preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv.unread .conv-preview { color: var(--ink); font-weight: 600; }
.conv-tags { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.unread-dot { margin-inline-start: auto; background: var(--blue); color: #fff; border-radius: 99px; font-size: 11px; font-weight: 700; min-width: 20px; padding: 1px 6px; text-align: center; }
.empty { color: var(--muted); text-align: center; padding: 32px 16px; }

.chat-pane { display: flex; flex-direction: column; background: #eef3f9; }
.placeholder { margin: auto; text-align: center; max-width: 360px; padding: 24px; color: var(--ink-2); }
.placeholder .i { width: 40px; height: 40px; color: var(--blue); }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--line); min-height: 60px; flex-wrap: wrap; }
.chat-head .back { display: none; }
.chat-title { display: grid; min-width: 0; line-height: 1.2; } .chat-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .chat-title span { font-size: 12px; }
.chat-actions { display: flex; gap: 6px; margin-inline-start: auto; flex-wrap: wrap; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: 11px; color: var(--muted); background: #fff; border-radius: 99px; padding: 2px 10px; margin: 8px 0; box-shadow: var(--shadow); }
.msg { display: flex; flex-direction: column; max-width: min(560px, 82%); }
.msg.customer { align-self: flex-start; } .msg.agent, .msg.rep { align-self: flex-end; align-items: flex-end; }
.bubble { position: relative; padding: 7px 10px 5px; border-radius: 12px; box-shadow: 0 1px 1px rgba(20, 34, 54, .08); background: #fff; min-width: 90px; }
.msg.customer .bubble { border-start-start-radius: 4px; }
.msg.agent .bubble { background: var(--ai-50); border-start-end-radius: 4px; }
.msg.rep .bubble { background: #dcecff; border-start-end-radius: 4px; }
.msg.failed .bubble { outline: 1px solid #f3c3bf; }
.who { display: flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; color: var(--muted); margin-bottom: 2px; }
.msg.agent .who { color: var(--ai); } .msg.rep .who { color: var(--blue); }
.who .i { width: 13px; height: 13px; }
.body { white-space: pre-wrap; overflow-wrap: anywhere; }
.meta { display: flex; justify-content: flex-end; gap: 4px; font-size: 11px; color: var(--muted); margin-top: 2px; }
.st-read { color: #2a8fe6; } .st-failed { color: var(--red); font-weight: 700; }
.reaction { position: absolute; bottom: -12px; inset-inline-end: 8px; background: #fff; border-radius: 99px; padding: 0 5px; box-shadow: var(--shadow); font-size: 13px; }
.fail-row { font-size: 12px; color: var(--red); margin-top: 4px; }
.media-img { display: block; max-width: 100%; max-height: 280px; border-radius: 8px; margin: 2px 0 4px; }
audio { width: 260px; max-width: 100%; } video { max-width: 100%; max-height: 300px; border-radius: 8px; }
.media-text { font-size: 12px; color: var(--ink-2); background: rgba(255, 255, 255, .6); border-radius: 6px; padding: 4px 6px; margin: 4px 0; white-space: pre-wrap; }
.media-wait { font-size: 12px; color: var(--muted); font-style: italic; }
.media-fail { font-size: 12px; color: var(--red); display: flex; gap: 4px; align-items: center; }
.doc { display: inline-flex; gap: 6px; align-items: center; color: var(--blue); font-weight: 600; text-decoration: none; padding: 6px 0; }
.banner { display: flex; gap: 8px; align-items: center; padding: 8px 14px; font-size: 13px; }
.banner.ai { background: var(--ai-50); color: var(--ai); } .banner.warn { background: var(--amber-50); color: var(--amber); }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; background: #fff; border-top: 1px solid var(--line); }
.compose-box { flex: 1; display: grid; gap: 6px; }
.composer textarea { resize: none; max-height: 160px; border-radius: 20px; padding: 9px 14px; }
.composer .send { border-radius: 50%; width: 40px; height: 40px; padding: 0; justify-content: center; }
.attach { cursor: pointer; }
.file-chip { display: inline-flex; gap: 6px; align-items: center; font-size: 12px; background: var(--blue-50); color: var(--blue); border-radius: 99px; padding-block: 3px; padding-inline: 10px 4px; justify-self: start; }
.file-chip[hidden] { display: none; }
.file-chip button { border: 0; background: none; color: inherit; font-size: 16px; line-height: 1; }

.details-pane { border-inline-start: 1px solid var(--line); overflow-y: auto; padding: 12px; display: grid; gap: 12px; align-content: start; background: var(--bg); }
.details-head { display: flex; justify-content: space-between; align-items: center; } .details-head h3 { margin: 0; }
.details-pane .card { padding: 12px; box-shadow: none; }
.card.summary { border-color: #cfc9f3; background: var(--ai-50); } .card.summary p { margin: 0 0 6px; white-space: pre-wrap; }
.card.warn { border-color: #f1d39d; background: var(--amber-50); color: var(--amber); display: flex; gap: 6px; }
.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.checklist li { display: flex; gap: 6px; align-items: center; } .checklist li.done { color: var(--green); } .checklist li.todo { color: var(--muted); }
.checklist .i { width: 15px; height: 15px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 0; font-size: 13px; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; overflow-wrap: anywhere; }
.edit-facts { margin-top: 10px; } .edit-facts summary { cursor: pointer; color: var(--blue); font-weight: 600; font-size: 13px; }
.edit-facts form { margin-top: 10px; }
#notes-form { display: grid; gap: 8px; } #notes-form .btn { justify-self: start; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 12px; color: var(--ink-2); }
.timeline time { color: var(--muted); margin-inline-end: 4px; }

.link.suggest { font-size: 11px; font-weight: 500; color: var(--muted); margin-top: 2px; opacity: 0; transition: opacity .15s; }
.msg:hover .link.suggest, .link.suggest:focus { opacity: 1; }
@media (pointer: coarse) { .link.suggest { opacity: .8; } }
.examples { display: grid; gap: 10px; }
.example { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: grid; gap: 8px; }
.example.disabled { opacity: .55; } .example.pending { border-color: #f1d39d; }
.ex-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; } .ex-head .badge:last-child { margin-inline-start: auto; }
.ex-turn { display: grid; grid-template-columns: 90px 1fr; gap: 8px; font-size: 13px; } .ex-turn span { color: var(--muted); font-size: 12px; } .ex-turn p { margin: 0; }
.ex-turn.reply p { background: var(--ai-50); border-radius: 8px; padding: 4px 8px; justify-self: start; }
.ex-actions { display: flex; gap: 6px; } .ex-actions:empty { display: none; }

/* pages */
main.page { padding: 20px 24px; max-width: 1200px; margin: 0 auto; display: grid; gap: 16px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.page-head p { margin: 0; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 16px; align-items: start; }
.list-card { padding: 6px; display: grid; gap: 2px; max-height: 75vh; overflow-y: auto; }
.row-btn { display: grid; text-align: start; gap: 2px; border: 0; background: none; padding: 10px; border-radius: 8px; }
.row-btn:hover { background: var(--bg); } .row-btn.active { background: var(--blue-50); }
.row-btn .badge { justify-self: start; }
.table { width: 100%; border-collapse: collapse; } .table th, .table td { text-align: start; padding: 8px; border-bottom: 1px solid var(--line); }
.table th { font-size: 12px; color: var(--muted); } .table tr.inactive td { color: var(--muted); } .right { text-align: end; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.settings-grid .wide { grid-column: 1 / -1; } .actions { display: flex; justify-content: flex-end; }
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.metric { display: grid; gap: 4px; } .metric span { color: var(--muted); font-size: 12px; } .metric strong { font-size: 24px; }
.meter { height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--blue); }
.w0 { width: 0 } .w10 { width: 10% } .w20 { width: 20% } .w30 { width: 30% } .w40 { width: 40% } .w50 { width: 50% } .w60 { width: 60% } .w70 { width: 70% } .w80 { width: 80% } .w90 { width: 90% } .w100 { width: 100%; background: var(--red) }
.health { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.health li { padding-inline-start: 18px; position: relative; } .health li::before { content: ""; position: absolute; inset-inline-start: 0; top: 6px; width: 9px; height: 9px; border-radius: 50%; }
.health .good::before { background: var(--green); } .health .warn::before { background: #e3a008; } .health .bad::before { background: var(--red); }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 30px); opacity: 0; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; transition: .2s; pointer-events: none; z-index: 50; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); } #toast.error { background: var(--red); }

/* responsive */
@media (max-width: 1180px) {
  main.inbox { grid-template-columns: 300px minmax(0, 1fr); }
  .details-pane { display: none; position: fixed; inset-inline-end: 0; top: 56px; bottom: 0; width: min(360px, 100%); z-index: 15; box-shadow: -8px 0 24px rgba(20, 34, 54, .12); }
  main.inbox.details-open .details-pane { display: grid; }
}
@media (max-width: 760px) {
  .topbar { gap: 8px; padding: 8px 12px; }
  .brand div, .me-name, .nav button span { display: none; }
  .nav button { padding: 8px; }
  main.inbox { grid-template-columns: 1fr; }
  main.inbox .chat-pane, main.inbox.view-chat .list-pane { display: none; }
  main.inbox.view-chat .chat-pane { display: flex; }
  .chat-head .back { display: inline-grid; }
  .chat-actions { order: 5; width: 100%; margin: 0; }
  .msg { max-width: 90%; }
  .details-pane { top: 0; width: 100%; z-index: 30; }
  main.page { padding: 16px; }
  .split, .settings-grid, .row2 { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: 1fr 1fr; }
}

/* right-to-left & new features */
[dir="rtl"] .back .i, [dir="rtl"] .send .i { transform: scaleX(-1); }
[dir="rtl"] body { letter-spacing: 0; }
.lang-btn { font-weight: 700; font-size: 13px; }
.nav button { white-space: nowrap; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.code-input { font-size: 24px; letter-spacing: 8px; text-align: center; }
.secret { display: inline-block; background: var(--bg); padding: 4px 8px; border-radius: 6px; font-size: 15px; letter-spacing: 1px; margin: 4px 0; user-select: all; }
.steps { margin: 0; padding-inline-start: 20px; display: grid; gap: 8px; color: var(--ink-2); }
.stock-form { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.stock-form .table select, .stock-form .table input { padding: 5px 8px; }
#my-account { margin-bottom: 4px; } #my-account p { margin: 0; }
.tag-chip { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 2px 10px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.tag-chip.on { background: var(--blue-50); border-color: var(--blue-100); color: var(--blue); }
.q-row { display: grid; grid-template-columns: 2fr 1fr 0.8fr 0.8fr 1fr auto; gap: 4px; margin-bottom: 6px; }
.q-row input { padding: 6px; font-size: 13px; }
.q-total { font-weight: 700; font-size: 15px; margin: 0; color: var(--blue); }
.details-pane .q-row { grid-template-columns: 1fr 1fr; } .details-pane .q-row input[name=product] { grid-column: 1 / -1; }
.page-head .actions input[type=search] { width: 220px; }
.alert-bar { display: flex; gap: 8px; align-items: center; padding: 8px 16px; font-size: 13px; font-weight: 600; flex-wrap: wrap; }
.alert-bar.warn { background: var(--amber-50); color: var(--amber); } .alert-bar.bad { background: var(--red-50); color: var(--red); }
.alert-bar span { flex: 1; min-width: 200px; } .alert-bar .btn { padding: 4px 10px; }
main.inbox { height: calc(100dvh - 56px - var(--alerts-h, 0px)); }
.badge.late { background: var(--red-50); color: var(--red); }
.small { font-size: 12px; margin: 8px 0 0; }
.lib-list { display: grid; gap: 6px; }
.lib-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.lib-row .muted { flex: 1; min-width: 160px; font-size: 13px; }
.lib-title { font-weight: 600; display: inline-flex; gap: 6px; align-items: center; color: var(--ink); text-decoration: none; }
.row-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row-form input, .row-form select { flex: 1 1 140px; width: auto; }
.row-form input[type=file] { flex: 2 1 200px; }
.page > section.card { display: grid; gap: 12px; }
.page h3 { display: flex; gap: 6px; align-items: center; }
.days { display: flex; flex-wrap: wrap; gap: 6px 14px; border: 0; padding: 0; }
.days legend { font-size: 13px; color: var(--ink-2); font-weight: 500; margin-bottom: 4px; padding: 0; }
.template-form { flex-wrap: wrap; align-items: stretch; }
.template-form select { flex: 1 1 220px; width: auto; }
.tpl-fields { display: flex; gap: 6px; flex: 1 1 220px; flex-wrap: wrap; } .tpl-fields input { flex: 1 1 120px; width: auto; }
.tpl-preview { flex-basis: 100%; font-size: 13px; color: var(--ink-2); background: var(--bg); border-radius: 8px; padding: 6px 10px; }
.tpl-preview:empty { display: none; }
.split.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.bars li { display: grid; grid-template-columns: minmax(80px, 1fr) 2fr auto; gap: 8px; align-items: center; font-size: 13px; }
.bars i { display: block; height: 8px; border-radius: 99px; background: var(--blue); min-width: 4px; }
.page-head .actions { display: flex; gap: 8px; } .page-head .actions select { width: auto; }
@media (max-width: 1180px) { .metrics { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 760px) { .split.three { grid-template-columns: 1fr; } .lib-row .muted { min-width: 100%; } }

/* company info (FAQ) */
.faq-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) auto; gap: 10px; align-items: end; padding: 10px 0; border-bottom: 1px solid var(--line); }
.faq-row:last-child { border-bottom: 0; }
.link.danger { color: #b42318; padding-bottom: 10px; }
@media (max-width: 760px) { .faq-row { grid-template-columns: 1fr; } }
/* per-size details table scrolls instead of squeezing on phones */
.table-wrap { overflow-x: auto; }
.stock-form .table input[data-colours] { min-width: 130px; }
/* handoff brief */
.brief .brief-row { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; font-size: 13.5px; }
.brief .brief-row > span { color: var(--muted, #667085); font-size: 12.5px; }
.brief q { display: block; quotes: none; background: rgba(255, 255, 255, .7); border-radius: 6px; padding: 4px 8px; margin-top: 2px; }
.brief .brief-row.next b { color: var(--ai); }

/* ---------- phones: bottom tab bar, compact header, roomy touch targets ---------- */
.tabbar, .sheet, .page-title { display: none; }
@media (max-width: 760px) {
  :root { --tabbar-h: calc(58px + env(safe-area-inset-bottom)); }
  body:has(main.inbox.view-chat) { --tabbar-h: 0px; }
  .topbar { height: calc(52px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 10px 0; gap: 6px; }
  .topbar .nav, #lang-btn, #logout, .me { display: none; }
  .brand img { width: 30px; height: 30px; }
  .page-title { display: block; flex: 1; min-width: 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .top-actions { gap: 2px; }
  .agent-switch { padding: 6px 9px; }
  .agent-switch span { display: none; }
  .icon-btn { width: 40px; height: 40px; }

  .tabbar { display: flex; position: fixed; inset-inline: 0; bottom: 0; z-index: 25; background: #fff; border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom); height: var(--tabbar-h); box-shadow: 0 -2px 12px rgba(20, 34, 54, .06); }
  body:has(main.inbox.view-chat) .tabbar { display: none; }
  .tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 0; background: none;
    color: var(--muted); font-size: 11px; font-weight: 600; padding: 6px 2px; min-width: 0; }
  .tabbar button .i { width: 22px; height: 22px; }
  .tabbar button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tabbar button.active { color: var(--blue); }

  .sheet:not([hidden]) { display: flex; position: fixed; inset: 0; z-index: 60; background: rgba(20, 34, 54, .4); align-items: flex-end; }
  .sheet-panel { width: 100%; background: #fff; border-radius: 16px 16px 0 0; padding: 8px 12px calc(12px + env(safe-area-inset-bottom));
    display: grid; gap: 2px; max-height: 80dvh; overflow-y: auto; animation: sheet-up .18s ease-out; }
  @keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
  .sheet-grip { width: 40px; height: 4px; border-radius: 99px; background: var(--line); justify-self: center; margin-bottom: 8px; }
  .sheet-user { display: flex; align-items: center; gap: 10px; padding: 6px 8px 10px; }
  .sheet-item { display: flex; align-items: center; gap: 12px; border: 0; background: none; padding: 13px 10px; border-radius: 10px; font-weight: 600; text-align: start; color: var(--ink); }
  .sheet-item.active { background: var(--blue-50); color: var(--blue); }
  .sheet-item.danger { color: var(--red); }
  .sheet-panel hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; width: 100%; }

  /* content clears the header and tab bar */
  main.inbox { height: calc(100dvh - 52px - env(safe-area-inset-top) - var(--alerts-h, 0px) - var(--tabbar-h)); }
  main.page { padding: 12px 12px calc(var(--tabbar-h) + 16px); gap: 12px; }
  .details-pane { top: 0; bottom: 0; padding-top: calc(12px + env(safe-area-inset-top)); }
  #toast { bottom: calc(var(--tabbar-h) + 12px); }

  /* iOS zooms into inputs below 16px */
  input, select, textarea { font-size: 16px; }
  .btn { padding: 9px 14px; }
  .card { padding: 14px; }
  h1 { font-size: 19px; }
  .page-head { align-items: stretch; }
  .page-head .actions { width: 100%; flex-wrap: wrap; }
  .page-head .actions input[type=search] { width: 100%; flex: 1 1 100%; }
  .list-card { max-height: none; }

  /* inbox */
  .conv { padding: 14px 12px; }
  .chat-head { padding: 6px 8px; min-height: 54px; }
  .messages { padding: 12px 10px; }
  .composer { padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  .msg { max-width: 88%; }

  /* wide tables scroll sideways instead of squeezing */
  .page .card .table { display: block; overflow-x: auto; white-space: nowrap; }
  .page .card .table td input, .page .card .table td select { min-width: 110px; }
  .q-row { grid-template-columns: 1fr 1fr; }
  .q-row input[name=product] { grid-column: 1 / -1; }
  .ex-turn { grid-template-columns: 1fr; gap: 2px; }
  .bars li { grid-template-columns: minmax(70px, 1fr) 1.5fr auto; }
  .row-form > * { flex: 1 1 100%; }
  .row-form .btn { justify-content: center; }
  .alert-bar { padding: 8px 12px; }
  .alert-bar span { min-width: 0; flex-basis: 100%; }
}
@media (max-width: 760px) {
  /* alerts: one compact row each; hidden inside an open chat to leave room for messages */
  .alert-bar { flex-wrap: nowrap; gap: 8px; padding: 6px 10px; font-size: 12px; line-height: 1.35; }
  .alert-bar span { flex: 1 1 auto; flex-basis: auto; min-width: 0; }
  .alert-bar .btn { padding: 5px 9px; font-size: 12px; }
  .alert-bar .i { width: 16px; height: 16px; }
  body:has(main.inbox.view-chat) #alerts { display: none; }
  body:has(main.inbox.view-chat) main.inbox { height: calc(100dvh - 52px - env(safe-area-inset-top)); }
  /* chat actions: one row that scrolls sideways */
  .chat-actions { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 6px; padding-bottom: 2px; }
  .chat-actions::-webkit-scrollbar { display: none; }
  .chat-actions .btn { padding: 6px 10px; font-size: 13px; flex: none; }
  .chat-actions select.btn { font-size: 13px; width: auto; max-width: 150px; }
  .chat-head .badge { font-size: 10px; }
}
@media (max-width: 760px) {
  html, body { overflow-x: hidden; }
  main.inbox > .pane, .chat-pane, .chat-head, .messages { min-width: 0; max-width: 100vw; }
  .chat-actions { min-width: 0; max-width: 100%; }
}
@media (max-width: 760px) { .chat-head #details-btn { order: 4; margin-inline-start: auto; } .chat-head .badge { order: 3; } }
@media (max-width: 760px) { .split > :nth-child(2) { scroll-margin-top: calc(60px + env(safe-area-inset-top)); } }

/* Reports and other pages: a wide table scrolls inside its card instead of stretching the page. */
main.page { grid-template-columns: minmax(0, 1fr); }
main.page > *, .split > *, .metrics > * { min-width: 0; }
.card:has(> .table) { overflow-x: auto; }
.card > .table { min-width: 520px; }
@media (max-width: 760px) {
  .page-head { flex-wrap: wrap; gap: 10px; }
  .page-head .actions { flex-wrap: wrap; }
  .metric strong { font-size: 22px; }
}

/* Reports: every figure opens the conversations behind it. */
.drillable { cursor: pointer; transition: box-shadow .15s, background .15s; }
.card.metric.drillable:hover, .card.metric.drillable:focus-visible { box-shadow: 0 0 0 2px var(--blue-50), 0 2px 10px rgba(11, 92, 173, .12); outline: none; }
.card.metric.drillable strong { color: var(--blue); }
.bars li.drillable { border-radius: 6px; padding: 2px 4px; margin: -2px -4px; }
.bars li.drillable:hover, .bars li.drillable:focus-visible { background: var(--blue-50); outline: none; }
.table .link.num { font-weight: 700; color: var(--blue); padding: 2px 6px; text-decoration: underline; text-underline-offset: 3px; }
.drill { position: fixed; inset: 0; z-index: 80; background: rgba(20, 34, 54, .45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.drill-panel { background: #fff; border-radius: 14px; width: min(560px, 100%); max-height: min(80vh, 720px); display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0, 0, 0, .2); }
.drill-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.drill-head h3 { margin: 0 0 2px; font-size: 16px; }
.drill-head .icon-btn { font-size: 22px; line-height: 1; }
.drill-list { overflow-y: auto; padding: 6px 8px 10px; display: grid; gap: 2px; }
.drill-row { border-bottom: 1px solid var(--line); border-radius: 0; gap: 4px; }
.drill-row:last-child { border-bottom: 0; }
.drill-row .conv-top { display: flex; justify-content: space-between; gap: 8px; }
.drill-row .muted { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drill-row .conv-tags { display: flex; flex-wrap: wrap; gap: 4px; }
@media (max-width: 760px) {
  .drill { align-items: flex-end; padding: 0; }
  .drill-panel { width: 100%; max-height: 85vh; border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom); }
}
