/* ═══════════════════════════════════════════════════
   AlleAsystent Chat UI
   ═══════════════════════════════════════════════════ */

/* Dark is the default theme; the light one below is opted into by
   <html data-theme="light">, set from localStorage before first paint
   (see the inline script in index.html) and toggled in Settings.
   Every colour the UI paints must come from a variable defined in BOTH
   blocks — a hardcoded hex here is a spot that stays dark in light mode. */
:root {
  color-scheme: dark;
  --bg:        #0f0f1a;
  --bg2:       #16162a;
  --bg3:       #1e1e36;
  --card:      #1a1a30;
  --border:    #2a2a50;
  --primary:   #6366f1;
  --primary-d: #4f46e5;
  --accent:    #818cf8;
  --text:      #e2e8f0;
  --muted:     #64748b;
  --text-muted: #64748b;   /* alias used by inline styles in index.html */
  --user-bg:   #1e3a5f;
  --user-bd:   #2a4a70;
  --bot-bg:    #1a1a30;
  --success:   #10b981;
  --danger:    #ef4444;
  --warning:   #f59e0b;
  --strong:    #c7d2fe;
  --em:        #a5b4fc;
  --code-bg:   #0d1117;
  --code-inline-bg: rgba(99,102,241,.2);
  --code-inline-bd: rgba(99,102,241,.3);
  --row-alt:   rgba(255,255,255,.03);
  --row-alt-2: rgba(255,255,255,.025);
  --row-hover: rgba(99,102,241,.07);
  --overlay:   rgba(0,0,0,.6);
  --shadow:    rgba(0,0,0,.5);
  --error-bg:  rgba(239,68,68,.1);
  --error-bd:  rgba(239,68,68,.3);
  --error-tx:  #fca5a5;
  --on-primary: #fff;
  /* Chart.js reads these through getComputedStyle (see _chartConfig) */
  --chart-grid: rgba(148,163,184,.12);
  --chart-palette: #818cf8,#6366f1,#10b981,#f59e0b,#ef4444,#06b6d4,#ec4899,#84cc16;
  --sidebar-w: 260px;
  --top-h:     56px;
  --radius:    12px;
  --radius-sm: 8px;
}

/* ── LIGHT THEME ─────────────────────────────────── */
:root[data-theme="light"] {
  color-scheme: light;
  --bg:        #f6f7fb;
  --bg2:       #ffffff;
  --bg3:       #eceff7;
  --card:      #ffffff;
  --border:    #dde1ec;
  --primary:   #4f46e5;
  --primary-d: #4338ca;
  --accent:    #4338ca;
  --text:      #1a1d29;
  --muted:     #667085;
  --text-muted: #667085;
  --user-bg:   #e0e7ff;
  --user-bd:   #c3ccf7;
  --bot-bg:    #ffffff;
  --success:   #047857;
  --danger:    #dc2626;
  --warning:   #b45309;
  --strong:    #3730a3;
  --em:        #4f46e5;
  --code-bg:   #f4f5fa;
  --code-inline-bg: rgba(79,70,229,.1);
  --code-inline-bd: rgba(79,70,229,.22);
  --row-alt:   rgba(15,23,42,.035);
  --row-alt-2: rgba(15,23,42,.03);
  --row-hover: rgba(79,70,229,.08);
  --overlay:   rgba(15,23,42,.35);
  --shadow:    rgba(15,23,42,.18);
  --error-bg:  rgba(220,38,38,.08);
  --error-bd:  rgba(220,38,38,.35);
  --error-tx:  #b42318;
  --on-primary: #fff;
  --chart-grid: rgba(71,85,105,.16);
  --chart-palette: #4f46e5,#6366f1,#059669,#d97706,#dc2626,#0891b2,#db2777,#65a30d;
}

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

html, body {
  height: 100%; background: var(--bg); color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 15px; line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

/* ── UTILS ──────────────────────────────────────── */
.hidden    { display: none !important; }
.muted     { color: var(--muted); font-size: .82rem; }
.w-full    { width: 100%; }
.mt-sm     { margin-top: .5rem; }
.link-small { color: var(--accent); font-size: .82rem; text-decoration: none; }
.link-small:hover { text-decoration: underline; }

/* ── OVERLAY ─────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; background: var(--overlay);
  z-index: 40; backdrop-filter: blur(2px);
}

/* ── SETTINGS PANEL ──────────────────────────────── */
.settings-panel {
  position: fixed; top: 0; right: 0;
  width: min(400px, 100vw);
  height: 100dvh; height: 100vh;
  background: var(--bg2); border-left: 1px solid var(--border);
  z-index: 50; display: flex; flex-direction: column;
  transform: translateX(0); transition: transform .25s ease;
}
.settings-panel.hidden { transform: translateX(100%); display: flex !important; }

.settings-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 1.25rem 1rem; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.settings-header h2 { font-size: 1.1rem; font-weight: 700; }

.settings-body { flex: 1; overflow-y: auto; padding: 1.25rem; display: flex; flex-direction: column; gap: .75rem; }
.settings-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); text-align: center; }
.version-info { font-size: .78rem; color: var(--text); opacity: .85; margin-top: .5rem; font-family: 'SFMono-Regular', Consolas, monospace; }
.settings-divider { border: none; border-top: 1px solid var(--border); margin: .5rem 0; }

/* ── FORMS ───────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group label { font-size: .78rem; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.form-group input,
.form-group select {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  padding: .6rem .75rem; font-size: 16px; outline: none;
  transition: border-color .2s;
}
.form-group input:focus,
.form-group select:focus { border-color: var(--primary); }
select option { background: var(--bg2); }

/* ── TOGGLE SWITCH ───────────────────────────────── */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; padding: .4rem 0; font-size: .92rem;
}
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 999px; transition: background .2s, border-color .2s;
}
.switch .slider::before {
  content: ''; position: absolute; height: 18px; width: 18px;
  left: 2px; top: 2px; border-radius: 50%;
  background: var(--muted); transition: transform .2s, background .2s;
}
.switch input:checked + .slider { background: var(--primary); border-color: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }
.input-eye { position: relative; display: flex; }
.input-eye input { flex: 1; padding-right: 2.5rem; }
.btn-eye {
  position: absolute; right: .5rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem;
}

/* ── BUTTONS ─────────────────────────────────────── */
.btn {
  border: none; border-radius: var(--radius-sm);
  padding: .65rem 1.1rem; font-size: .9rem; font-weight: 600;
  cursor: pointer; transition: all .15s;
}
.btn-primary  { background: var(--primary);  color: #fff; }
.btn-primary:hover  { background: var(--primary-d); }
.btn-outline  { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover  { border-color: var(--accent); color: var(--accent); }
.btn-danger   { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn-danger:hover   { background: var(--danger); color: #fff; }
.btn-icon {
  background: none; border: none; color: var(--muted);
  font-size: 1.2rem; cursor: pointer; padding: .3rem .5rem;
  border-radius: var(--radius-sm); transition: all .15s;
}
.btn-icon:hover { color: var(--text); background: var(--bg3); }

/* ── APP LAYOUT ──────────────────────────────────── */
.app {
  display: flex;
  position: fixed;
  top: var(--vv-top, 0px);   /* follows visualViewport.offsetTop (iOS page scroll) */
  left: 0; right: 0;
  height: var(--vv-h, 100dvh); /* follows visualViewport.height (keyboard shrinks this) */
  overflow: hidden;
}

/* ── SIDEBAR ─────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: transform .25s ease;
}

.sidebar-top { padding: 1rem; border-bottom: 1px solid var(--border); }

.logo {
  display: flex; align-items: center; gap: .5rem;
  margin-bottom: .75rem;
}
.logo-icon { font-size: 1.4rem; }
.logo-text { font-size: 1rem; font-weight: 800; color: var(--accent); letter-spacing: .5px; }

.btn-new-chat {
  width: 100%; background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius-sm); padding: .6rem;
  font-size: .9rem; font-weight: 600; cursor: pointer; transition: background .15s;
}
.btn-new-chat:hover { background: var(--primary-d); }

.sidebar-sections { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.sidebar-tabs {
  display: flex; gap: .25rem; flex-shrink: 0;
  padding: .75rem .75rem .5rem;
}
/* Three tabs in a 260px sidebar: the labels are what people read, so they get
   the whole pill — no room left for a decorative icon beside them. */
.sidebar-tab {
  flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); border: 1px solid var(--border); border-radius: 999px;
  padding: .45rem .35rem; cursor: pointer; transition: all .15s;
  font-family: inherit; font-size: .74rem; font-weight: 600; color: var(--muted);
  white-space: nowrap;
}
.sidebar-tab:hover { color: var(--text); border-color: var(--accent); }
.sidebar-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.stab-label { line-height: 1; overflow: hidden; text-overflow: ellipsis; }

.sidebar-section-list {
  flex: 1; overflow-y: auto; min-height: 0; padding: .25rem .5rem .5rem;
  display: flex; flex-direction: column; gap: .15rem;
}

.sidebar-list-item {
  display: flex; align-items: center; gap: .5rem; width: 100%;
  background: none; border: none; text-align: left;
  padding: .5rem .6rem; border-radius: var(--radius-sm);
  cursor: pointer; transition: background .15s;
  font-size: .82rem; color: var(--muted);
}
.sidebar-list-item:hover { background: var(--bg3); color: var(--text); }
.sli-icon { flex-shrink: 0; font-size: .9rem; }
.sli-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sli-count {
  flex-shrink: 0; font-size: .7rem; color: var(--muted);
  background: var(--bg3); border-radius: 999px; padding: .05rem .4rem;
}
.sidebar-list-item:hover .sli-count { background: var(--bg); }

/* Conversation rows carry two actions (rename, delete). They sit at low
   opacity instead of hidden-until-hover, because a phone has no hover. */
.conv-item.active { background: var(--bg3); color: var(--text); }
.sli-when { flex-shrink: 0; font-size: .7rem; color: var(--muted); }
.sli-act {
  flex-shrink: 0; background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: .8rem; line-height: 1; padding: .15rem .2rem;
  opacity: .45; transition: opacity .15s, color .15s;
}
.sli-act:hover { opacity: 1; color: var(--text); }
.sli-del:hover { color: var(--danger); }
.conv-item:hover .sli-act { opacity: .8; }
.conv-item:hover .sli-when { display: none; }

.sidebar-empty { padding: .5rem .6rem; font-size: .78rem; color: var(--muted); line-height: 1.4; }

.sidebar-bottom { padding: .75rem; border-top: 1px solid var(--border); }
.sidebar-btn {
  width: 100%; display: flex; align-items: center; gap: .5rem;
  background: none; border: none; color: var(--muted);
  padding: .5rem .75rem; border-radius: var(--radius-sm);
  cursor: pointer; font-size: .88rem; transition: all .15s;
}
.sidebar-btn:hover { background: var(--bg3); color: var(--text); }

/* ── MAIN CHAT ───────────────────────────────────── */
.chat-main {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0; overflow: hidden;
}

/* ── TOPBAR (mobile) ─────────────────────────────── */
.topbar {
  height: var(--top-h); background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: none; align-items: center; gap: .5rem;
  padding: 0 .75rem; flex-shrink: 0;
}
.topbar-center { flex: 1; display: flex; align-items: center; gap: .4rem; justify-content: center; font-weight: 700; }

/* ── MESSAGES ────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: scroll;              /* 'scroll' not 'auto' — more reliable on iOS */
  -webkit-overflow-scrolling: touch; /* smooth momentum scroll on older iOS */
  touch-action: pan-y;             /* ensure vertical swipe is recognized as scroll */
  padding: 1.5rem 1rem;
  display: flex; flex-direction: column;
  gap: .75rem;
}

/* WELCOME */
.welcome {
  margin: auto; text-align: center; max-width: 500px; padding: 2rem 1rem;
}
.welcome-icon { font-size: 3.5rem; margin-bottom: .75rem; }
.welcome h1 { font-size: 1.8rem; font-weight: 800; color: var(--accent); margin-bottom: .35rem; }
.welcome-sub { color: var(--muted); margin-bottom: 1.5rem; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.suggestion {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .65rem .75rem;
  font-size: .82rem; color: var(--text); cursor: pointer;
  text-align: left; transition: all .15s; line-height: 1.4;
}
.suggestion:hover { border-color: var(--primary); background: var(--bg3); }

/* MESSAGE BUBBLES */
.msg { display: flex; gap: .75rem; max-width: 100%; animation: msg-in .2s ease; }
@keyframes msg-in { from { opacity:0; transform: translateY(6px); } to { opacity:1; transform:translateY(0); } }

.msg-user { flex-direction: row-reverse; }

.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; flex-shrink: 0; margin-top: .15rem;
}
.msg-user .msg-avatar { background: var(--primary); color: #fff; }
.msg-bot  .msg-avatar { background: var(--bg3); border: 1px solid var(--border); }

.msg-content { max-width: 80%; display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.msg-user .msg-content { align-items: flex-end; }

.msg-bubble {
  padding: .75rem 1rem; border-radius: var(--radius);
  font-size: .95rem; line-height: 1.65; word-wrap: break-word;
  position: relative;
}
.msg-user .msg-bubble {
  background: var(--user-bg); border: 1px solid var(--user-bd);
  border-bottom-right-radius: 4px;
}
.msg-bot .msg-bubble {
  background: var(--bot-bg); border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* MARKDOWN inside bot bubble */
.msg-bubble h1,.msg-bubble h2,.msg-bubble h3 { color: var(--accent); margin: .75rem 0 .35rem; font-size: 1rem; }
.msg-bubble h1 { font-size: 1.1rem; }
.msg-bubble p  { margin: .4rem 0; }
.msg-bubble p:first-child { margin-top: 0; }
.msg-bubble p:last-child  { margin-bottom: 0; }
.msg-bubble ul,.msg-bubble ol { padding-left: 1.4rem; margin: .4rem 0; }
.msg-bubble li { margin: .2rem 0; }
.msg-bubble strong { color: var(--strong); }
.msg-bubble em     { color: var(--em); }
.msg-bubble a      { color: var(--accent); }
.msg-bubble blockquote {
  border-left: 3px solid var(--primary); margin: .5rem 0;
  padding: .3rem .75rem; background: var(--bg3); border-radius: 0 4px 4px 0;
  color: var(--muted);
}
.msg-bubble table {
  display: block; width: 100%; border-collapse: collapse; margin: .5rem 0; font-size: .88rem;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.msg-bubble th,.msg-bubble td { border: 1px solid var(--border); padding: .4rem .65rem; text-align: left; white-space: nowrap; }
.msg-bubble th { background: var(--bg3); color: var(--accent); font-weight: 600; }
.msg-bubble tr:nth-child(even) td { background: var(--row-alt); }
.msg-bubble pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin: .5rem 0; overflow-x: auto;
}
.msg-bubble pre code { padding: .75rem 1rem; display: block; font-size: .85rem; font-family: 'Cascadia Code', 'Fira Code', monospace; }
.msg-bubble code:not(pre code) {
  background: var(--code-inline-bg); border: 1px solid var(--code-inline-bd);
  border-radius: 4px; padding: .1rem .35rem; font-size: .87rem;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
}
.msg-bubble hr { border: none; border-top: 1px solid var(--border); margin: .75rem 0; }

/* MESSAGE ACTIONS */
.msg-actions {
  display: flex; gap: .3rem; opacity: 0; transition: opacity .15s;
}
.msg:hover .msg-actions { opacity: 1; }
.msg-user .msg-actions { flex-direction: row-reverse; }
.msg-act-btn {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; padding: .2rem .45rem;
  font-size: .75rem; color: var(--muted); cursor: pointer;
  transition: all .15s;
}
.msg-act-btn:hover { color: var(--text); border-color: var(--accent); }

/* TIMESTAMP */
.msg-time { font-size: .72rem; color: var(--muted); }

/* LOADING DOTS */
.typing-dots {
  display: inline-flex; gap: 4px; align-items: center; padding: .2rem 0;
}
.typing-dots span {
  width: 6px; height: 6px; background: var(--muted);
  border-radius: 50%; animation: dot-bounce .9s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes dot-bounce { 0%,80%,100% { transform: scale(.7); opacity:.5; } 40% { transform: scale(1); opacity:1; } }

/* ERROR BUBBLE */
.msg-error {
  background: var(--error-bg); border-color: var(--error-bd);
  color: var(--error-tx);
}

/* ── INPUT AREA ──────────────────────────────────── */
.input-area {
  padding: .75rem 1rem 1rem;
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrap {
  display: flex; align-items: center; gap: .5rem;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .6rem .75rem;
  transition: border-color .2s;
}
.input-wrap:focus-within { border-color: var(--primary); }

#user-input {
  flex: 1; background: none; border: none; color: var(--text);
  font-size: 16px; resize: none; outline: none;
  max-height: 180px; overflow-y: auto; line-height: 1.5;
  font-family: inherit;
}
#user-input::placeholder { color: var(--muted); }

.btn-send {
  background: var(--primary); border: none; border-radius: var(--radius-sm);
  color: #fff; width: 36px; height: 36px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all .15s;
}
.btn-send:hover:not(:disabled) { background: var(--primary-d); }
.btn-send:disabled { background: var(--border); color: var(--muted); cursor: default; }

.input-hint {
  font-size: .72rem; color: var(--muted); margin-top: .4rem; text-align: center;
}
#model-badge {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 20px; padding: .05rem .45rem;
  font-size: .7rem; color: var(--accent);
}

/* ── TOAST ───────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 20px; padding: .5rem 1.2rem;
  font-size: .88rem; z-index: 100; white-space: nowrap;
  animation: fade-up .25s ease;
}
@keyframes fade-up {
  from { opacity:0; transform: translateX(-50%) translateY(8px); }
  to   { opacity:1; transform: translateX(-50%) translateY(0); }
}

/* ── SCROLLBAR ───────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── MOBILE ──────────────────────────────────────── */
@media (max-width: 768px) {
  .topbar { display: flex; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 30;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px var(--shadow); }
  .suggestions { grid-template-columns: 1fr; }
  .msg-content { max-width: 90%; }
  .messages { padding: 1rem .75rem; }
}

@media (min-width: 769px) {
  .topbar { display: none; }
}

/* ── ORDER MONITORING ─────────────────────────── */
.btn-monitoring {
  display: inline-flex; align-items: center; gap: .4rem;
  background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius-sm);
  padding: .5rem 1rem; font-size: .88rem; font-weight: 600;
  cursor: pointer; margin-top: .5rem; transition: background .15s;
}
.btn-monitoring:hover { background: var(--primary-d); }

.monitoring-badge {
  display: inline-flex; align-items: center; gap: .35rem;
  background: rgba(16,185,129,.15); border: 1px solid rgba(16,185,129,.4);
  color: var(--success); border-radius: var(--radius-sm);
  padding: .35rem .75rem; font-size: .82rem; font-weight: 600; margin-top: .5rem;
}

.notif-badge {
  position: absolute; top: -2px; right: -2px;
  min-width: 16px; height: 16px; padding: 0 4px;
  display: flex; align-items: center; justify-content: center;
  background: var(--danger); color: #fff;
  border-radius: 999px; font-size: .65rem; font-weight: 700;
  line-height: 1;
}
.sidebar-btn .notif-badge { top: .3rem; right: .5rem; }

.notif-item {
  border-bottom: 1px solid var(--border);
  padding: .75rem 0;
}
.notif-item:last-child { border-bottom: none; }
.notif-item.has-action { cursor: pointer; margin: 0 -.5rem; padding: .75rem .5rem; border-radius: 6px; }
.notif-item.has-action:hover { background: var(--bg3); }
.notif-item.unread .notif-title::before {
  content: ''; display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; background: var(--primary); margin-right: .4rem;
}
.notif-title { font-weight: 600; font-size: .92rem; }
/* Monitor bodies are multi-line (value / delivery / invoice on their own
   lines, as the OS notification shows them), so keep the breaks. */
.notif-body { font-size: .85rem; color: var(--muted); margin-top: .2rem; white-space: pre-line; }
.notif-time { font-size: .75rem; color: var(--muted); opacity: .7; margin-top: .3rem; }
.notif-empty { text-align: center; padding: 2rem 0; }

.btn-message-monitoring {
  display: inline-flex; align-items: center; gap: .4rem;
  background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius-sm);
  padding: .5rem 1rem; font-size: .88rem; font-weight: 600;
  cursor: pointer; margin-top: .5rem; transition: filter .15s;
}
.btn-message-monitoring:hover { filter: brightness(1.12); }

.btn-returns-monitoring {
  display: inline-flex; align-items: center; gap: .4rem;
  background: var(--danger); color: #fff;
  border: none; border-radius: 999px; padding: .5rem 1rem;
  font-size: .88rem; font-weight: 600;
  cursor: pointer; margin-top: .5rem; transition: filter .15s;
}
.btn-returns-monitoring:hover { filter: brightness(1.12); }

.btn-invoice-reminder {
  display: inline-flex; align-items: center; gap: .4rem;
  background: var(--warning); color: #fff;
  border: none; border-radius: var(--radius-sm);
  padding: .5rem 1rem; font-size: .88rem; font-weight: 600;
  cursor: pointer; margin-top: .5rem; transition: filter .15s;
}
.btn-invoice-reminder:hover { filter: brightness(1.12); }

/* ── DOCUMENT VIEWER ─────────────────────────────── */
.doc-viewer {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg);
  display: flex; flex-direction: column;
}
.doc-viewer.hidden { display: none !important; }

.doc-tabbar {
  display: flex; align-items: center; gap: 2px;
  padding: 0 .5rem;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  height: var(--top-h); flex-shrink: 0;
  overflow-x: auto; scrollbar-width: none;
}
.doc-tabbar::-webkit-scrollbar { display: none; }

.doc-back-btn {
  flex-shrink: 0;
  background: none; border: none; color: var(--accent);
  font-size: .88rem; font-weight: 600; cursor: pointer;
  padding: .4rem .85rem; border-radius: var(--radius-sm);
  transition: background .15s; white-space: nowrap;
}
.doc-back-btn:hover { background: var(--bg3); }

.doc-tab-list {
  display: flex; gap: 2px; flex: 1;
  overflow-x: auto; align-items: center;
  scrollbar-width: none;
}
.doc-tab-list::-webkit-scrollbar { display: none; }

.doc-tab {
  display: flex; align-items: center; gap: 5px;
  background: none; border: 1px solid transparent;
  color: var(--muted); padding: .35rem .7rem;
  border-radius: var(--radius-sm); cursor: pointer;
  font-size: .82rem; white-space: nowrap;
  transition: all .15s; max-width: 220px;
}
.doc-tab:hover { background: var(--bg3); color: var(--text); }
.doc-tab.active {
  background: var(--bg3); color: var(--text);
  border-color: var(--border);
}
.doc-tab-name {
  overflow: hidden; text-overflow: ellipsis; max-width: 170px;
}
.doc-tab-x {
  flex-shrink: 0; font-size: .7rem; opacity: .45;
  background: none; border: none; cursor: pointer;
  color: inherit; padding: 1px 3px; border-radius: 3px;
  line-height: 1;
}
.doc-tab-x:hover { opacity: 1; background: var(--danger); color: #fff; }

.doc-copy-btn {
  flex-shrink: 0; background: none; border: none;
  cursor: pointer; font-size: 1rem; padding: .35rem .6rem;
  border-radius: var(--radius-sm); transition: background .15s;
  color: var(--muted);
}
.doc-copy-btn:hover { background: var(--bg3); color: var(--text); }

.doc-body {
  flex: 1; overflow-y: auto; padding: 2.5rem 1.5rem;
}

.doc-content {
  max-width: 860px; margin: 0 auto;
  font-size: 1rem; line-height: 1.8;
}

/* Typography */
.doc-content h1 {
  font-size: 1.7rem; font-weight: 800; margin: 0 0 1rem;
  padding-bottom: .6rem; border-bottom: 2px solid var(--border);
  color: var(--accent);
}
.doc-content h2 {
  font-size: 1.25rem; font-weight: 700; margin: 1.75rem 0 .6rem;
  color: var(--accent);
}
.doc-content h3 {
  font-size: 1.05rem; font-weight: 600; margin: 1.25rem 0 .45rem;
  color: var(--text);
}
.doc-content p { margin: 0 0 .9rem; }
.doc-content p:last-child { margin-bottom: 0; }
.doc-content ul, .doc-content ol { margin: 0 0 .9rem 1.5rem; }
.doc-content li { margin-bottom: .35rem; }
.doc-content strong { color: var(--strong); }
.doc-content em { color: var(--em); }
.doc-content a { color: var(--accent); }
.doc-content hr { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }
.doc-content blockquote {
  border-left: 3px solid var(--primary); margin: .75rem 0;
  padding: .5rem 1rem; background: var(--bg2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--muted);
}
.doc-content code {
  background: var(--code-inline-bg); border: 1px solid var(--code-inline-bd);
  border-radius: 4px; padding: .1em .4em;
  font-size: .88em; font-family: 'Cascadia Code','Fira Code',monospace;
}
.doc-content pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin: .75rem 0; overflow-x: auto;
}
.doc-content pre code {
  background: none; border: none; padding: .9rem 1.1rem;
  display: block; font-size: .88rem;
}

/* Tables */
.doc-content table {
  width: 100%; border-collapse: collapse;
  margin: .75rem 0 1.25rem; font-size: .92rem;
  overflow-x: auto; display: block;
}
.doc-content thead th {
  background: var(--bg3); text-align: left;
  padding: .6rem .85rem; font-weight: 700;
  border-bottom: 2px solid var(--border);
  color: var(--accent); white-space: nowrap;
}
.doc-content tbody td {
  padding: .5rem .85rem; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.doc-content tbody tr:last-child td { border-bottom: none; }
.doc-content tbody tr:nth-child(even) { background: var(--row-alt-2); }

/* Table-format replies: wider canvas, sticky header for long lists */
.doc-content[data-kind="table"] { max-width: 1200px; }
.doc-content[data-kind="table"] thead th { position: sticky; top: 0; z-index: 1; }

/* Dashboard-format replies: group each ## section into a distinct card.
   Sized down to match the main chat bubble (.95rem) — the generic .doc-content
   sizing below is tuned for long-form documents/tables, not these compact
   report cards. */
.doc-content[data-kind="dashboard"] {
  font-size: .95rem; line-height: 1.65;
}
.doc-content[data-kind="dashboard"] .dash-section {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1.4rem; margin: 0 0 1rem;
}
.doc-content[data-kind="dashboard"] .dash-section:last-child { margin-bottom: 0; }
.doc-content[data-kind="dashboard"] h1 { font-size: 1.15rem; }
.doc-content[data-kind="dashboard"] h2 { font-size: 1.05rem; margin: 1.1rem 0 .5rem; }
.doc-content[data-kind="dashboard"] h3 { font-size: 1rem; }
.doc-content[data-kind="dashboard"] .dash-section h1,
.doc-content[data-kind="dashboard"] .dash-section h2 {
  margin-top: 0; border-bottom: none; padding-bottom: 0;
}
.doc-content[data-kind="dashboard"] .dash-section strong {
  font-size: 1em; color: var(--accent);
}
.doc-content tbody tr:hover { background: var(--row-hover); }

/* Charts embedded in dashboard-format replies (see DocViewer._renderCharts) */
.chart-wrap {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.25rem 1.25rem;
  margin: .75rem 0 1.25rem;
}
.chart-title {
  font-size: .85rem; font-weight: 700; color: var(--accent);
  text-transform: uppercase; letter-spacing: .4px; margin-bottom: .75rem;
}
.chart-canvas-box { position: relative; height: 280px; width: 100%; }
@media (max-width: 768px) {
  .chart-canvas-box { height: 220px; }
}

/* Button in chat bubble to open doc viewer */
.msg-act-doc { color: var(--accent) !important; border-color: var(--code-inline-bd) !important; }
.msg-act-doc:hover { background: var(--code-inline-bg) !important; border-color: var(--accent) !important; }

@media (max-width: 768px) {
  .doc-body { padding: 1.5rem .75rem; }
  .doc-content h1 { font-size: 1.35rem; }
  .doc-content h2 { font-size: 1.1rem; }
}
