:root {
  --bg: #0f1420; --panel: #161d2e; --border: #26304a; --text: #e6e9f2; --muted: #93a0bd;
  --green: #35c26b; --yellow: #e0b23d; --red: #e5555a; --gray: #6b7590; --accent: #5b8def;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: -apple-system, Segoe UI, Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
/* Fixed desktop admin shell: the layout itself never scrolls — sidebar and
   main content each own their own independent scroll region, so a long
   page (e.g. Products & Stock) never carries the sidebar away with it. */
.layout { display: flex; height: 100vh; overflow: hidden; }
nav.sidebar {
  width: 200px; height: 100vh; overflow-y: auto; position: sticky; top: 0;
  background: var(--panel); border-right: 1px solid var(--border); padding: 16px 0; flex-shrink: 0;
}
nav.sidebar .brand { padding: 0 16px 16px; font-weight: 700; font-size: 18px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
nav.sidebar a { display: block; padding: 10px 16px; color: var(--text); }
nav.sidebar a:hover, nav.sidebar a.active { background: var(--border); }
main { flex: 1; height: 100vh; overflow-y: auto; padding: 24px; max-width: 1200px; }
h1 { font-size: 20px; margin-top: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.badge.green { background: rgba(53,194,107,.15); color: var(--green); }
.badge.yellow { background: rgba(224,178,61,.15); color: var(--yellow); }
.badge.red { background: rgba(229,85,90,.15); color: var(--red); }
.badge.gray { background: rgba(107,117,144,.15); color: var(--gray); }
table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 600; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 24px; }
a.card-link { display: block; color: var(--text); transition: border-color .15s, transform .1s; }
a.card-link:hover { border-color: var(--accent); transform: translateY(-1px); }
a.card-link.card-alert { border-color: var(--red); }
a.card-link.card-alert .stat { color: var(--red); }
.stat { font-size: 24px; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 13px; }
.nav-more summary { padding: 12px 16px; cursor: pointer; color: var(--muted); }
.admin-control { margin: 0 0 10px; border: 1px solid var(--border); border-radius: 8px; padding: 10px; background: var(--panel); }
.admin-control > summary, .compact-health summary, .inbox-detail summary, .home-secondary > summary { cursor: pointer; }
.admin-control[open] .availability-bar { margin: 10px 0; }
.compact-health { padding: 10px 12px; }
.compact-health > details { margin-top: 6px; font-size: 13px; }
.compact-health #runtime-health-ai { margin: 0 8px; }
.inbox-search { display: flex; gap: 8px; margin-bottom: 12px; }
.inbox-search input[type=search] { flex: 1; min-width: 0; }
.inbox-search button { margin: 0; min-height: 40px; }
.inbox-filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }
.inbox-filters .btn { margin: 0; display: inline-block; }
.inbox-card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 12px; overflow-wrap: anywhere; }
.inbox-card.inbox-unread { border-left: 3px solid var(--accent); }
.inbox-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.inbox-card-head .friendly-time { flex-shrink: 0; font-size: 12px; }
.inbox-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 8px 0; font-size: 13px; }
.inbox-meta .btn { margin: 0; }
.inbox-preview { margin: 10px 0; }
.inbox-detail { margin-top: 12px; font-size: 13px; }
.context-detail { margin: 10px 0; padding: 8px 0; border-top: 1px solid var(--border); }
.pagination { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 20px 0; }
.arrival-banner { padding: 12px; border: 1px solid var(--accent); border-radius: 8px; margin-bottom: 12px; background: var(--panel); }
.arrival-banner[hidden] { display: none; }
.home-secondary { margin: 14px 0; padding: 12px; border: 1px solid var(--border); border-radius: 8px; }
.home-secondary[open] > summary { margin-bottom: 18px; }
.home-inbox-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border); color: var(--text); }
.home-inbox-row .badge { justify-self: end; }
@media (max-width: 720px) {
  nav.sidebar .nav-more { width: 100%; }
  .nav-more summary { padding: 8px 10px; }
  .primary-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 12px; }
  .primary-cards .card { padding: 10px 6px; margin: 0; }
  .primary-cards .stat { font-size: 22px; }
  .primary-cards .stat-label { font-size: 11px; overflow-wrap: anywhere; }
  .inbox-card { padding: 12px; }
  .inbox-card-head { flex-wrap: wrap; gap: 4px; }
}
button, .btn { background: var(--accent); color: white; border: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; margin-right: 6px; }
button.secondary { background: var(--border); }
button.danger { background: var(--red); }
button.warning { background: var(--yellow); color: #1a1400; }
input, select, textarea { background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 6px 8px; border-radius: 6px; }
form.inline { display: inline; }
.login-box { max-width: 340px; margin: 80px auto; }
.availability-schedule { margin-bottom: 16px; }
.availability-schedule summary { cursor: pointer; min-height: 44px; }
.schedule-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-top: 12px; }
.schedule-form label { display: grid; gap: 6px; }
.schedule-form input, .schedule-form select, .schedule-form button { min-height: 44px; max-width: 100%; }
@media (max-width: 720px) { .login-box { margin: 30px 16px; } .schedule-form label { width: 100%; } }
.msg { padding: 10px; border-radius: 6px; margin-bottom: 12px; }
.msg.error { background: rgba(229,85,90,.15); color: var(--red); }
.msg.success { background: rgba(53,194,107,.15); color: var(--green); }
.muted { color: var(--muted); }
.chat-wrap { position: relative; }
.chat { max-height: 60vh; overflow-y: auto; margin-bottom: 12px; scroll-behavior: auto; }
#new-message-btn { position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%); box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.chat .bubble { padding: 8px 10px; border-radius: 8px; margin-bottom: 6px; max-width: 70%; font-size: 14px; }
.chat .bubble.customer { background: var(--border); }
.chat .bubble.hnin, .chat .bubble.admin { background: var(--accent); margin-left: auto; }
.chat .bubble.failed { background: rgba(229,85,90,.18); border: 1px solid var(--red); margin-left: auto; }
.chat .sender { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.delivery-state { margin-top: 4px; font-size: 12px; }
.delivery-pending { color: var(--muted); font-style: italic; }
.delivery-sent { color: var(--green); }
.delivery-failed { color: var(--red); font-weight: 600; display: block; margin-bottom: 4px; }
.retry-btn { font-size: 12px; padding: 3px 10px; }
#reply-send-btn:disabled { opacity: .6; cursor: default; }

/* Mobile Access URLs (spec section 9/10) — user-select: all makes a single
   tap-and-hold on mobile select the whole URL at once instead of a word. */
code.copyable { user-select: all; -webkit-user-select: all; word-break: break-all; }
.copy-msg { color: var(--red); font-size: 12px; margin-left: 6px; }

.save-indicator { display: inline-block; margin-left: 6px; font-size: 12px; min-width: 60px;
                  max-width: 260px; vertical-align: middle; }
/* Products & Stock duration cell: number + unit + Save must stay on one
   readable line instead of collapsing into an unreadable cluster. */
td form.ajax-inline-save { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
td form.ajax-inline-save select { min-width: 110px; }
td form.ajax-inline-save input[type=number] { min-width: 72px; }
.save-indicator.save-ok { color: var(--green); }
.save-indicator.save-fail { color: var(--red); }

tr.inbox-unread { background: rgba(91,141,239,.08); }
tr.inbox-unread td:first-child { border-left: 3px solid var(--accent); }
/* Owner handoff view (2026-09-28) */
tr.handoff-urgent td:first-child { border-left: 3px solid var(--red); }
.handoff-table .interest + .interest { margin-top: 6px; }
.handoff-table .exchange { max-width: 320px; font-size: 13px; }
.action-urgent { color: var(--red); font-weight: 600; }
.action-owner { font-weight: 600; }
.action-wait, .action-none { color: var(--gray); }
.handoff-summary dt { font-weight: 600; margin-top: 6px; }
.handoff-summary dd { margin: 2px 0 0 0; }
/* Phones: each conversation becomes a card; labels come from data-label. */
@media (max-width: 720px) {
  table.handoff-table { display: block; white-space: normal; overflow-x: visible; }
  .handoff-table tbody, .handoff-table tr, .handoff-table td { display: block; width: auto; }
  .handoff-table tr.handoff-head { display: none; }
  .handoff-table tr { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; padding: 6px 8px; }
  .handoff-table td { border-bottom: none; padding: 4px 2px; white-space: normal; overflow-wrap: anywhere; }
  .handoff-table td[data-label]:not([data-label=""])::before { content: attr(data-label); display: block; font-size: 11px; color: var(--gray); }
  .handoff-table .exchange { max-width: none; }
}

.bubble.learning-flagged { border: 1px solid var(--yellow); }
.learning-tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; margin-bottom: 4px; }
.learning-tag-unanswered { background: rgba(229,85,90,.2); color: var(--red); }
.learning-tag-fallback { background: rgba(224,178,61,.2); color: var(--yellow); }

/* Admin availability bar — plenty of width/height for Burmese text, which
   wraps taller than Latin text at the same font size (spec section 9). */
.availability-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 20px; }
.availability-bar button { margin-right: 0; font-size: 13px; line-height: 1.4; padding: 8px 14px; min-height: 36px; white-space: normal; max-width: 260px; }
button.availability-active { background: var(--green); font-weight: 700; }

/* Mobile / phone access (spec section 19/24) — sidebar collapses to a top
   bar, tables scroll horizontally instead of overflowing the viewport. */
@media (max-width: 720px) {
  /* The fixed-shell/independent-scroll pattern is a desktop concern — on a
     phone the sidebar folds into a top bar and the page should scroll
     normally as one document, so undo the height/overflow constraints. */
  html, body { height: auto; }
  .layout { flex-direction: column; height: auto; overflow: visible; }
  nav.sidebar { width: 100%; height: auto; overflow-y: visible; position: static; display: flex; flex-wrap: wrap; padding: 8px; }
  nav.sidebar .brand { width: 100%; border-bottom: none; margin-bottom: 4px; padding: 4px 8px; }
  nav.sidebar a { padding: 6px 10px; font-size: 13px; }
  main { height: auto; overflow: visible; padding: 12px; max-width: 100%; }
  table { display: block; overflow-x: auto; white-space: nowrap; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  /* Long product names in a <select> (Today's Focus) widened /sales past a
     phone screen (audit 2026-09-28). */
  select { max-width: 100%; }
}

/* Catalog editor (2026-09-27). Built phone-first: every form stacks into one
   column, controls wrap, long customer previews wrap instead of scrolling. */
.catalog-list { display: grid; gap: 10px; }
.catalog-row { padding: 12px 14px; margin-bottom: 0; }
.catalog-row-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 6px; }
.catalog-plans { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; }
.catalog-plan.is-hidden, .plan-card.is-hidden { opacity: .6; }
.catalog-status { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.catalog-actions { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.plan-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.plan-head h2, .card h2 { font-size: 16px; margin: 0 0 8px; }
.card h3 { font-size: 14px; margin: 14px 0 6px; color: var(--muted); }
.fact-form { display: grid; gap: 6px; max-width: 560px; margin-top: 8px; }
.fact-form label { display: grid; gap: 4px; font-size: 13px; }
.fact-form input, .fact-form select, .fact-form textarea { width: 100%; font-size: 15px; }
.fact-form button { justify-self: start; margin-top: 6px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.field-help { color: var(--muted); font-size: 12px; margin: -2px 0 6px; }
.draft-note { font-size: 12px; color: var(--yellow); margin-bottom: 6px; }
.controls .control-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 6px 0; }
.confirm-box { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.conflict-list { margin: 0; padding-left: 18px; }
.conflict-list li { margin-bottom: 6px; font-size: 14px; }
.preview-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
pre.customer-text { white-space: pre-wrap; word-break: break-word; background: var(--bg); border: 1px solid var(--border);
                    border-radius: 8px; padding: 10px; font-family: inherit; font-size: 14px; margin: 0 0 8px; }
pre.customer-text.draft { border-color: var(--yellow); }
.table-scroll { overflow-x: auto; }
@media (max-width: 720px) {
  .preview-grid, .field-row { grid-template-columns: 1fr; }
  .fact-form { max-width: 100%; }
  .controls .control-row button, .catalog-actions button { min-height: 40px; }
}

/* Keep the three daily totals on one row after the general mobile card rules. */
.topbar h1 { margin: 0; }
.topbar { margin-bottom: 12px; }
.compact-health > details:not([open]) { display: inline; margin: 0 0 0 8px; }
.compact-health > details:not([open]) > summary { display: inline-block; }
@media (max-width: 720px) {
  .cards.primary-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
