/* PaySay merchant workspace: light editorial theme. */
:root {
  --paper: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #fbfaf7;
  --sunken: #efece5;
  --line: #e6e1d7;
  --line-strong: #d6d0c3;

  --ink: #1c1a16;
  --ink-2: #57524a;
  --ink-3: #6f6a5e;

  --accent: #1f3fd1;
  --accent-ink: #ffffff;
  --accent-soft: #e9edfc;

  --ok: #1f7a4d;
  --ok-soft: #e4f3ea;
  --warn: #a35f00;
  --warn-soft: #fbf0dc;
  --bad: #b3261e;
  --bad-soft: #fbe6e4;
  --muted-soft: #eeebe4;

  --font-display: "Iowan Old Style", "Charter", "Palatino Linotype", Georgia, "Noto Serif Thai", serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, "Noto Sans Thai", "Leelawadee UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(28, 26, 22, 0.04), 0 4px 16px rgba(28, 26, 22, 0.04);

  --sidebar-w: 240px;
  --assistant-w: 400px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
[hidden] { display: none !important; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.skip-link {
  position: absolute; left: -999px; top: 12px; z-index: 100;
  background: var(--ink); color: var(--paper);
  padding: 8px 14px; border-radius: var(--radius-sm);
}
.skip-link:focus { left: 12px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.mono { font-family: var(--font-mono); font-size: 0.9em; }

/* ---------- Layout ---------- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--assistant-w);
  height: 100vh;
  height: 100dvh;
}

/* ---------- Sidebar ---------- */

.sidebar {
  display: flex; flex-direction: column; gap: 28px;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: var(--surface-2);
}

.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px; }

.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 3px;
}
.brand-mark i { width: 3px; border-radius: 2px; background: var(--paper); display: block; }
.brand-mark i:nth-child(1) { height: 9px; }
.brand-mark i:nth-child(2) { height: 16px; }
.brand-mark i:nth-child(3) { height: 11px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-family: var(--font-display); font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.brand-sub { font-size: 12px; color: var(--ink-3); }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--ink-2); text-align: left; font-weight: 500;
}
.nav-item:hover { background: var(--sunken); color: var(--ink); }
.nav-item[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.nav-item[aria-current="page"] .icon { color: var(--accent); }

.nav-count {
  margin-left: auto; min-width: 22px; padding: 0 7px;
  border-radius: 999px; background: var(--sunken);
  font-size: 12px; text-align: center; color: var(--ink-2);
}
.nav-count-alert {
  background: var(--bad); color: #ffffff; font-weight: 600;
}

.nav-assistant { display: none; }

.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 4px; }

.field-label { font-size: 12px; color: var(--ink-3); }

.select-wrap {
  position: relative; display: flex; align-items: center;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface);
}
.select-wrap .icon { position: absolute; left: 10px; color: var(--ink-3); pointer-events: none; }
.select-wrap select {
  appearance: none; width: 100%; border: 0; background: transparent;
  padding: 9px 10px 9px 36px; cursor: pointer; font-weight: 500;
}

.mode-badge {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--ink-2); padding: 6px 2px;
}
.mode-badge::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: var(--ink-3);
}
.mode-badge.live::before { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.mode-badge.demo::before { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }

/* ---------- Main workspace ---------- */

.main { overflow-y: auto; padding: 28px 36px 48px; }

.topbar {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  margin-bottom: 24px;
}

.kicker {
  font-size: 13px; color: var(--ink-3); letter-spacing: 0.02em;
  text-transform: lowercase; margin-bottom: 4px;
}

.view-title {
  font-family: var(--font-display); font-weight: 500;
  font-size: 34px; line-height: 1.15; letter-spacing: -0.015em;
}

.topbar-actions { display: flex; gap: 8px; }

.banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; margin-bottom: 16px; border-radius: var(--radius-sm);
  background: var(--bad-soft); color: var(--bad); font-size: 14px;
}

.demo-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 12px 8px 14px; margin-bottom: 20px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2);
  font-size: 13px; line-height: 1.4;
}
.demo-banner-text { flex: 1; }
.demo-banner-close { color: var(--ink-3); flex-shrink: 0; }
.demo-banner-close:hover { color: var(--ink); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px; border-radius: var(--radius-sm);
  font-weight: 500; white-space: nowrap;
  transition: background-color 0.15s, box-shadow 0.15s;
}
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover { background: #33302a; }
.btn-ghost { background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.btn-ghost:hover { box-shadow: inset 0 0 0 1px var(--line-strong); background: var(--surface-2); }
.btn-lg { height: 46px; padding: 0 18px; font-size: 15px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-sm {
  display: inline-flex; align-items: center; gap: 5px;
  height: 28px; padding: 0 10px; border-radius: 7px;
  font-size: 13px; font-weight: 500;
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--line);
}
.btn-sm:hover { box-shadow: inset 0 0 0 1px var(--line-strong); }
.btn-sm .icon { width: 14px; height: 14px; }

.icon-btn {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-2);
}
.icon-btn:hover { background: var(--sunken); color: var(--ink); }
.icon-btn-sm { width: 30px; height: 30px; border-radius: 7px; box-shadow: inset 0 0 0 1px var(--line); background: var(--surface); }
.icon-btn-sm:hover { box-shadow: inset 0 0 0 1px var(--line-strong); }
.icon-btn-sm .icon { width: 15px; height: 15px; }
.icon-btn-solid { background: var(--ink); color: var(--paper); }
.icon-btn-solid:hover { background: #33302a; color: var(--paper); }

.link-btn { color: var(--accent); font-size: 14px; font-weight: 500; }
.link-btn:hover { text-decoration: underline; }

/* ---------- Daily collections check ---------- */

.collections-card {
  background: var(--accent-soft); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 18px;
  display: flex; flex-direction: column; gap: 12px;
}
.collections-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.collections-title {
  font-family: var(--font-display); font-size: 20px; line-height: 1.2;
  letter-spacing: -0.01em; font-weight: 600;
}
.collections-when { font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.collections-summary { font-size: 14px; color: var(--ink-2); }
.collections-card .btn-primary { align-self: flex-start; }

/* ---------- KPIs ---------- */

.kpis {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px;
  margin-bottom: 18px;
}

.kpi {
  display: flex; flex-direction: column; gap: 6px;
  padding: 18px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
}
.kpi-label { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.kpi-value {
  font-family: var(--font-display); font-size: 28px; line-height: 1.1;
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
}
.kpi-hint { font-size: 12px; color: var(--ink-3); min-height: 18px; }
.kpi-bar { height: 6px; border-radius: 999px; background: var(--sunken); overflow: hidden; margin-top: 6px; }
.kpi-bar i { display: block; height: 100%; width: 0; background: var(--ok); border-radius: inherit; transition: width 0.4s; }

/* ---------- Panels ---------- */

.overview-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
@media (min-width: 1600px) {
  .overview-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); }
}

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; min-width: 0;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.panel-title { font-family: var(--font-display); font-weight: 500; font-size: 19px; }

.attention { list-style: none; display: flex; flex-direction: column; }
.attention li {
  display: flex; align-items: center; gap: 14px;
  padding: 11px 0; border-top: 1px solid var(--line);
}
.attention li:first-child { border-top: 0; padding-top: 2px; }
.attention-main { min-width: 0; flex: 1; }
.attention-who { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.attention-what { font-size: 13px; color: var(--ink-3); }
.attention-amount { font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; }
.attention-empty { color: var(--ink-3); padding: 8px 0; border: 0 !important; }

.empty-note { color: var(--ink-3); max-width: 46ch; }

/* ---------- Invoices toolbar ---------- */

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }

.search {
  position: relative; display: flex; align-items: center; flex: 1 1 240px; max-width: 360px;
}
.search .icon { position: absolute; left: 11px; color: var(--ink-3); pointer-events: none; }
.search input {
  width: 100%; height: 38px; padding: 0 12px 0 36px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
}
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--sunken); border-radius: 10px;
}
.segmented button { height: 32px; padding: 0 12px; border-radius: 7px; color: var(--ink-2); font-weight: 500; font-size: 14px; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.toggle input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------- AG Grid ---------- */

.grid { width: 100%; }
.grid-compact { min-height: 120px; }
.grid-full { height: calc(100vh - 210px); height: calc(100dvh - 210px); min-height: 360px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; line-height: 1;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-DRAFT { background: var(--muted-soft); color: var(--ink-2); }
.pill-SENT, .pill-UNPAID, .pill-PARTIALLY_PAID { background: var(--warn-soft); color: var(--warn); }
.pill-PAID { background: var(--ok-soft); color: var(--ok); }
.pill-CANCELLED { background: var(--bad-soft); color: var(--bad); }

.cell-actions-host { display: flex; align-items: center; }
.cell-actions { display: flex; gap: 6px; align-items: center; }
.cell-id { font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-2); }
.cell-amount { font-variant-numeric: tabular-nums; font-weight: 500; }

.grid-empty { color: var(--ink-3); }
.grid .ag-cell.cell-total { text-align: left; }
.grid .ag-floating-bottom .ag-row { background: var(--surface-2); font-weight: 600; }

/* ---------- Timeline (Bryntum Scheduler) ---------- */

.timeline-body {
  display: flex; flex-direction: column; gap: 14px;
  height: calc(100vh - 210px); height: calc(100dvh - 210px); min-height: 360px;
}
.timeline-scheduler {
  flex: 1; min-height: 300px; width: 100%;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); overflow: hidden;
}
.timeline-overdue-chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 12px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--line);
}
.timeline-overdue-chip.has-overdue {
  color: var(--bad); background: var(--bad-soft); border-color: #f5c2c0; font-weight: 600;
}
.timeline-overdue-chip .icon { width: 16px; height: 16px; }

/* Truncate customer column text with ellipsis */
.b-grid-cell[data-column="name"],
.b-grid-cell.b-grid-cell-name {
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

/* Bryntum Scheduler event styling: match status pill palette */
.b-sch-event {
  border-radius: 6px !important; cursor: pointer;
  box-shadow: 0 1px 2px rgba(28, 26, 22, 0.06);
}
.b-sch-event.event-status-DRAFT {
  background: var(--muted-soft) !important; color: var(--ink-2) !important;
  border: 1px solid var(--line-strong) !important;
}
.b-sch-event.event-status-OPEN,
.b-sch-event.event-status-SENT,
.b-sch-event.event-status-UNPAID,
.b-sch-event.event-status-PARTIALLY_PAID {
  background: var(--warn-soft) !important; color: var(--warn) !important;
  border: 1px solid #e6c88b !important;
}
.b-sch-event.event-status-PAID {
  background: var(--ok-soft) !important; color: var(--ok) !important;
  border: 1px solid #a3d9b8 !important;
}
.b-sch-event.event-status-CANCELLED {
  background: var(--bad-soft) !important; color: var(--bad) !important;
  border: 1px solid #f5c2c0 !important;
}
.b-sch-event.event-overdue {
  outline: 2px solid var(--bad) !important; outline-offset: -1px;
}
/* Open invoices with no due date: faded bar + dashed trailing edge */
.b-sch-event.event-no-due {
  border-right: 2px dashed rgba(28, 26, 22, 0.4) !important;
  opacity: 0.78;
}
.b-sch-event {
  container-type: inline-size !important;
}
/*
 * stickyEvents uses position:sticky on .b-sch-event-content with width:auto.
 * Forcing width:100% prevents the content from sliding into view when a bar
 * starts off-screen (Bryntum StickyEvents / styling guide).
 */
.b-sch-event-content {
  width: auto !important;
  max-width: 100%;
  overflow: visible !important;
}
.timeline-bar {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; line-height: 1.2; padding: 0 2px;
  width: max-content; max-width: 100%; height: 100%;
  box-sizing: border-box;
}
.timeline-bar-amount {
  font-weight: 600; font-variant-numeric: tabular-nums;
  white-space: nowrap; flex: 0 0 auto;
}
.timeline-bar-status {
  font-weight: 500; white-space: nowrap;
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 4px;
}
.timeline-bar-sep { opacity: 0.5; flex-shrink: 0; }
/* Only drop status when the bar itself is truly narrow (not a clipped wide bar). */
@container (max-width: 110px) {
  .b-sch-event-narrow .timeline-bar-status {
    display: none !important;
  }
}

/* Narrow bars: hide truncated in-bar text; Bryntum Labels.before shows amount beside.
   Do not blank wide bars — b-sch-event-narrow is absent when the full bar is wide. */
.b-sch-event-narrow .timeline-bar {
  visibility: hidden;
}
.b-sch-event-wrap:not(:has(.b-sch-event-narrow)) > .b-sch-label-before {
  display: none !important;
}
.b-sch-event-wrap > .b-sch-label-before {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  background: var(--surface);
  padding: 1px 4px;
  border-radius: 4px;
  z-index: 5;
}

/* Today: thin line in rows; small pill in the month band (above week labels).
   headerRenderer outputs .timeline-today-pill directly (no <label>).
   The header current-time node sits on the week row, so the pill is shifted
   up by one header-row (~30px) into the month band. */
.b-timeline-sub-grid .b-sch-current-time {
  width: 2px;
}
.b-timeline-sub-grid .b-sch-current-time label,
.b-timeline-sub-grid .b-sch-current-time .timeline-today-pill {
  display: none !important;
}
.b-sch-timeaxiscolumn,
.b-time-ranges-header-canvas,
.b-time-ranges-header-canvas .b-sch-current-time {
  overflow: visible !important;
}
/* Make the week-row marker non-covering at all widths so date labels
   remain fully legible; the Today pill in the month band already labels it. */
.b-time-ranges-header-canvas .b-sch-current-time {
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
  width: 0 !important;
}
.b-time-ranges-header-canvas .b-sch-current-time .timeline-today-pill {
  position: absolute;
  top: -26px; /* one header row up → month band */
  left: 0;
  transform: translateX(5px); /* sit just to the right of the line */
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  letter-spacing: 0.01em;
  color: #fff;
  background: var(--bad);
  padding: 0 6px;
  border-radius: 999px;
  white-space: nowrap;
  z-index: 30;
  pointer-events: none;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85);
}

/* Tooltip */
.timeline-tip {
  font-family: var(--font-ui); font-size: 13px; color: var(--ink);
  display: flex; flex-direction: column; gap: 8px; padding: 2px;
}
.timeline-tip-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.timeline-tip-amount { font-size: 15px; font-weight: 700; }
.timeline-tip-meta {
  display: flex; flex-direction: column; gap: 4px; color: var(--ink-2); font-size: 12px;
}
.timeline-tip-row { display: flex; gap: 6px; }
.timeline-tip-label { color: var(--ink-3); min-width: 60px; }
.timeline-tip-overdue { color: var(--bad); font-weight: 600; }

/* ---------- Activity ---------- */

.activity { list-style: none; display: flex; flex-direction: column; gap: 10px; max-width: 760px; }

/* ---------- Action cards (assistant + activity) ---------- */

.action-card {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
}
.action-icon {
  width: 30px; height: 30px; flex: none; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--ok-soft); color: var(--ok);
}
.action-icon .icon { width: 16px; height: 16px; }
.action-card.error .action-icon { background: var(--bad-soft); color: var(--bad); }
.action-body { min-width: 0; flex: 1; }
.action-title { font-weight: 600; font-size: 14px; }
.action-meta { font-size: 13px; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.action-time { font-size: 12px; color: var(--ink-3); }
.action-card details { margin-top: 6px; }
.action-card summary { font-size: 12px; color: var(--ink-3); cursor: pointer; }
.action-card pre {
  margin-top: 6px; padding: 10px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--line);
  font: 12px/1.5 var(--font-mono); white-space: pre-wrap; word-break: break-word;
  max-height: 220px; overflow: auto;
}

/* ---------- Assistant ---------- */

.assistant {
  display: flex; flex-direction: column; min-height: 0;
  border-left: 1px solid var(--line); background: var(--surface);
}

.assistant-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 20px 20px 14px; border-bottom: 1px solid var(--line);
}
.assistant-title {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-display); font-weight: 500; font-size: 20px;
}
.assistant-title .icon { color: var(--accent); }
.assistant-sub { font-size: 13px; color: var(--ink-3); margin-top: 2px; }
.assistant-head { gap: 8px; }
.assistant-head > div:first-child { flex: 1; min-width: 0; }
.assistant-close, .assistant-locale { display: none; }

.conversation { flex: 1; overflow-y: auto; padding: 20px; }

.welcome { padding: 8px 0 4px; }
.welcome-kicker { font-size: 13px; color: var(--ink-3); text-transform: lowercase; }
.welcome-title {
  font-family: var(--font-display); font-size: 26px; line-height: 1.2;
  margin: 4px 0 18px; letter-spacing: -0.01em;
}
.suggestions { display: flex; flex-direction: column; gap: 8px; }
.suggestion {
  text-align: left; padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--ink-2); line-height: 1.4;
}
.suggestion::before { content: "“"; color: var(--ink-3); }
.suggestion::after { content: "”"; color: var(--ink-3); }
.suggestion:hover { border-color: var(--line-strong); color: var(--ink); background: var(--surface); }

.messages { list-style: none; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; flex-direction: column; gap: 8px; max-width: 100%; }
.msg-user { align-items: flex-end; }
.bubble {
  padding: 11px 14px; border-radius: 14px; line-height: 1.5;
  white-space: pre-wrap; word-wrap: break-word; max-width: 92%;
}
.msg-user .bubble { background: var(--ink); color: var(--paper); border-bottom-right-radius: 4px; }
.msg-assistant .bubble { background: var(--surface-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg-error .bubble { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.msg-actions { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.msg-divider {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  margin: 4px 0;
}
.msg-divider::before,
.msg-divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--line);
}
.msg-divider-text {
  font-size: 12px;
  color: var(--ink-3);
  font-weight: 500;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.confirm-card {
  width: 100%; padding: 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
}
.confirm-title { font-family: var(--font-display); font-size: 18px; margin-bottom: 10px; }
.confirm-details { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.confirm-details div { display: flex; justify-content: space-between; gap: 12px; }
.confirm-details dt { color: var(--ink-2); min-width: 0; overflow-wrap: anywhere; }
.confirm-details dd { font-weight: 500; font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }
.confirm-details .mono-row dd { font-family: var(--font-mono); font-size: 13px; }
.confirm-details .confirm-total { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 2px; }
.confirm-details .confirm-total dt, .confirm-details .confirm-total dd { font-weight: 600; color: var(--ink); }
.confirm-note { font-size: 12.5px; color: var(--ink-3); margin-bottom: 12px; }
.confirm-buttons { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.confirm-result { font-size: 13px; color: var(--ink-3); padding: 4px 2px; }
.confirm-result.error { color: var(--bad); }

.chat-invoices {
  list-style: none; width: 100%; display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
}
.chat-invoice { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--line); }
.chat-invoices-head {
  padding: 8px 12px; font-size: 12px; color: var(--ink-3);
  background: var(--surface-2); border-radius: var(--radius) var(--radius) 0 0;
}
.chat-invoice-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.chat-invoice-who { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-invoice-amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chat-invoice-meta { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-3); }
.chat-invoice .pill { height: 22px; font-size: 12px; }
.chat-invoice-more { padding: 10px 12px; text-align: left; border-top: 1px solid var(--line); }

.typing { display: inline-flex; gap: 4px; padding: 14px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.composer-wrap {
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px 20px 18px; border-top: 1px solid var(--line); background: var(--surface);
}

.quick-replies { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.mic {
  display: flex; align-items: center; gap: 14px;
  width: 100%; padding: 10px 16px 10px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 16px;
  transition: background-color 0.15s;
}
.mic:hover { background: #dfe5fb; }
.mic-orb {
  width: 52px; height: 52px; flex: none; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-ink);
}
.mic-orb .icon { width: 24px; height: 24px; }
.mic[aria-pressed="true"] { background: var(--bad-soft); color: var(--bad); }
.mic[aria-pressed="true"] .mic-orb { background: var(--bad); animation: pulse 1.4s infinite; }
.mic:disabled { background: var(--sunken); color: var(--ink-3); cursor: default; }
.mic:disabled .mic-orb { background: var(--line-strong); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(179, 38, 30, 0.35); }
  70% { box-shadow: 0 0 0 12px rgba(179, 38, 30, 0); }
  100% { box-shadow: 0 0 0 0 rgba(179, 38, 30, 0); }
}

.composer { display: flex; gap: 8px; }
.composer input {
  flex: 1; min-width: 0; height: 40px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2);
}
.composer input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }
.composer .icon-btn { width: 40px; height: 40px; }

.status { font-size: 13px; color: var(--ink-3); min-height: 18px; }
.status.error { color: var(--bad); }

/* ---------- QR modal ---------- */

.modal {
  margin: auto; width: min(400px, calc(100vw - 32px));
  border: 1px solid var(--line); border-radius: 16px;
  padding: 22px; background: var(--surface); color: var(--ink);
  box-shadow: 0 24px 64px rgba(28, 26, 22, 0.18);
}
.modal::backdrop { background: rgba(28, 26, 22, 0.35); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.modal-title { font-family: var(--font-display); font-weight: 500; font-size: 24px; }
.qr-image {
  display: flex; align-items: center; justify-content: center;
  aspect-ratio: 1; border-radius: var(--radius); background: var(--surface-2);
  border: 1px solid var(--line); color: var(--ink-3); margin-bottom: 16px;
}
.qr-image img { width: 82%; height: auto; image-rendering: pixelated; }
.qr-meta { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.qr-meta div { display: flex; justify-content: space-between; gap: 12px; }
.qr-meta dt { color: var(--ink-3); }
.qr-meta dd { font-weight: 600; }
.qr-note { font-size: 13px; color: var(--ink-2); margin-bottom: 14px; }

/* ---------- Responsive ---------- */

/* Laptop: sidebar collapses to icons. */
@media (max-width: 1240px) {
  :root { --sidebar-w: 72px; --assistant-w: 360px; }
  .sidebar { padding: 20px 12px; align-items: center; }
  .brand { padding: 0; }
  .brand-text, .nav-item span, .field-label, .mode-badge { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .nav-item[aria-current="page"] .nav-count { display: none; }
  .sidebar-footer { padding: 0; }
  .sidebar .select-wrap { width: 44px; height: 40px; overflow: hidden; }
  .sidebar .select-wrap .icon { left: 12px; }
  .sidebar .select-wrap select { position: absolute; inset: 0; opacity: 0; }
  .main { padding: 24px 24px 40px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Phone: bottom tab bar, assistant opens as a full-screen sheet. */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }

  .sidebar {
    grid-row: 2; flex-direction: row; align-items: center; gap: 0;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--line);
  }
  .brand, .sidebar-footer { display: none; }
  .nav { flex-direction: row; width: 100%; justify-content: space-around; }
  .nav-item { flex-direction: column; gap: 3px; padding: 6px 8px; font-size: 11px; flex: 1; }
  .nav-item span { display: block; }
  .nav-item .nav-count { display: none; }
  .nav-item[aria-current="page"] { box-shadow: none; background: transparent; }
  .nav-assistant { display: flex; }
  .nav-assistant .icon {
    width: 44px; height: 44px; padding: 11px; margin-top: -22px; border-radius: 50%;
    background: var(--accent); color: var(--accent-ink);
    box-shadow: 0 8px 20px rgba(31, 63, 209, 0.3), 0 0 0 4px var(--surface-2);
  }
  .nav-assistant span { color: var(--accent); font-weight: 600; }

  .main { grid-row: 1; padding: 18px 16px 32px; }
  .topbar { flex-direction: column; align-items: stretch; gap: 12px; }
  .topbar-actions .btn { flex: 1; }
  .view-title { font-size: 28px; }
  .kpi { padding: 14px; }
  .kpi-value { font-size: 22px; }
  .grid-full, .timeline-body { height: calc(100dvh - 330px); }

  /* Narrow customer column on phones to ~120px */
  .timeline-scheduler .b-grid-subgrid-locked {
    width: 120px !important;
    max-width: 120px !important;
  }
  .timeline-scheduler .b-grid-header[data-column="name"],
  .timeline-scheduler .b-grid-cell[data-column="name"] {
    width: 120px !important;
    max-width: 120px !important;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
  }

  /* Make the week-row marker non-covering at phone width so date labels
     remain fully legible; the Today pill in the month band already labels it. */
  .b-time-ranges-header-canvas .b-sch-current-time {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    width: 0 !important;
  }

  .assistant {
    position: fixed; inset: 0; z-index: 50; border: 0;
    transform: translateY(100%); transition: transform 0.25s ease;
  }
  .assistant.open { transform: none; }
  .assistant-head { align-items: center; gap: 8px; }
  .assistant-head > div:first-child { flex: 1; min-width: 0; }
  .assistant-close { display: inline-flex; }
  .assistant-locale { display: flex; width: auto; }
  .assistant-locale select { padding-right: 12px; }
  .assistant-head { padding: 16px; }
  .conversation { padding: 16px; }
  .composer-wrap { padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
