/* ==========================================================
   AiServe Shared WhatsApp Inbox - app.css
   Single-file stylesheet, no framework dependency.
   ========================================================== */

:root {
  --c-bg:        #f4f6f8;
  --c-card:      #ffffff;
  --c-text:      #1a2330;
  --c-muted:     #6b7785;
  --c-border:    #e2e6ec;
  --c-primary:   #25D366;     /* WhatsApp green */
  --c-primary-d: #128C7E;
  --c-accent:    #075E54;
  --c-danger:    #d9534f;
  --c-warn:      #f0ad4e;
  --c-info:      #4a90e2;
  --shadow-sm:   0 1px 2px rgba(0,0,0,0.05);
  --shadow-md:   0 4px 12px rgba(0,0,0,0.08);
  --radius:      8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
               Cantarell, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--c-text);
  background: var(--c-bg);
}
a { color: var(--c-primary-d); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #f0f2f5; padding: 0 4px; border-radius: 4px; font-size: 12.5px; }
small.muted, .muted.small { font-size: 12px; }
.muted { color: var(--c-muted); }

/* -------- App shell -------- */
.app-shell { display: flex; min-height: 100vh; }
.app-main  { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.app-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 24px; background: var(--c-card); border-bottom: 1px solid var(--c-border);
}
.app-title { margin: 0; font-size: 18px; }
.app-content { padding: 20px 24px; flex: 1; }

/* -------- Sidebar -------- */
.sidebar {
  width: 240px;
  background: #1f2933;
  color: #d9e0e8;
  display: flex; flex-direction: column;
  flex-shrink: 0;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px; border-bottom: 1px solid #2c3744;
  font-weight: 600;
}
.brand-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; }
.brand-text { font-size: 15px; }
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.sidebar-nav a {
  display: block; padding: 10px 20px; color: #c4cdd9; text-decoration: none;
  border-left: 3px solid transparent; font-size: 14px;
}
.sidebar-nav a:hover  { background: #2c3744; color: #fff; }
.sidebar-nav a.active { background: #2c3744; color: #fff; border-left-color: var(--c-primary); }
.sidebar-section {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: #7d8898; padding: 18px 20px 6px;
}
.sidebar-footer { padding: 14px 20px; border-top: 1px solid #2c3744; }
.user-card { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--c-primary); color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 600;
}
.user-name { font-size: 13px; font-weight: 600; color: #fff; }
.user-role { font-size: 11px; color: #7d8898; }
.btn-logout {
  display: inline-block; padding: 6px 10px; background: #2c3744; color: #d9e0e8;
  border-radius: 4px; font-size: 12px;
}
.btn-logout:hover { background: var(--c-danger); color: #fff; text-decoration: none; }

/* -------- Cards / forms -------- */
.card {
  background: var(--c-card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }

.form-grid { display: grid; grid-template-columns: 1fr; gap: 12px; max-width: 640px; }
.form-grid label { display: flex; flex-direction: column; font-size: 13px; color: var(--c-muted); gap: 4px; }
.form-grid input[type="text"],
.form-grid input[type="email"],
.form-grid input[type="password"],
.form-grid input[type="color"],
.form-grid select,
.form-grid textarea,
.inline-form input[type="text"],
.inline-form input[type="search"],
.inline-form select,
.inbox-search input,
.inbox-search select,
input[type="text"], input[type="email"], input[type="password"], input[type="search"], textarea, select {
  font: inherit; padding: 8px 10px; border: 1px solid var(--c-border); border-radius: 6px;
  background: #fff; color: var(--c-text);
}
textarea { resize: vertical; }

.btn {
  display: inline-block; padding: 8px 14px; border: 1px solid var(--c-border); background: #fff;
  border-radius: 6px; font: inherit; cursor: pointer; color: var(--c-text);
}
.btn:hover { background: #f0f2f5; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-primary { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.btn-primary:hover { background: var(--c-primary-d); border-color: var(--c-primary-d); color: #fff; text-decoration: none; }
.btn-danger { background: var(--c-danger); color: #fff; border-color: var(--c-danger); }
.btn-block { width: 100%; }

.inline-form { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }

/* -------- Alerts -------- */
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; font-size: 13px; }
.alert-success { background: #e8f7ee; color: #1f7a3f; border: 1px solid #b8e3c5; }
.alert-error   { background: #fdecea; color: #b3261e; border: 1px solid #f5c6c2; }
.alert-info    { background: #e9f0fb; color: #1c4587; border: 1px solid #c3d6f1; }

/* -------- Tables -------- */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--c-border); font-size: 13px;
  vertical-align: middle;
}
.data-table th { background: #f9fafb; font-weight: 600; color: var(--c-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
.data-table tr:hover td { background: #fafbfc; }
.data-table .actions { white-space: nowrap; }
.data-table .actions .btn { margin-left: 4px; }

/* -------- Badges -------- */
.badge {
  display: inline-block; padding: 2px 8px; font-size: 11px; border-radius: 999px;
  background: #e2e6ec; color: var(--c-text); font-weight: 500;
}
.badge-open      { background: #e8f7ee; color: #1f7a3f; }
.badge-pending   { background: #fff3e0; color: #b25c00; }
.badge-closed    { background: #e2e6ec; color: #6b7785; }
.badge-escalated { background: #fdecea; color: #b3261e; }
.badge-failed    { background: #fdecea; color: #b3261e; }
.badge-sent      { background: #e7eefa; color: #1c4587; }
.badge-default   { background: #e2e6ec; color: #6b7785; }

/* -------- Login -------- */
.login-body {
  background: linear-gradient(180deg, #f4f6f8 0%, #e7eaef 100%);
  display: flex; align-items: center; justify-content: center; min-height: 100vh; margin: 0;
}
.login-card {
  background: #fff; padding: 32px; border-radius: 12px; box-shadow: var(--shadow-md);
  width: 100%; max-width: 400px;
}
.login-card h1 { margin: 12px 0 4px; font-size: 22px; }
.login-card .login-brand { display: flex; align-items: center; gap: 8px; }
.login-card form { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.login-card label { font-size: 12.5px; color: var(--c-muted); margin-top: 6px; }
.register-card { max-width: 520px; }
.plan-pick { border: 1px solid var(--c-border); border-radius: 8px; padding: 10px; margin-top: 12px; display: grid; gap: 8px; }
.plan-pick legend { font-size: 12.5px; color: var(--c-muted); padding: 0 6px; }
.plan-radio { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--c-border); border-radius: 6px; cursor: pointer; font-size: 13px; }
.plan-radio:has(input:checked) { border-color: var(--c-primary); background: #f6fff9; }

/* -------- Stat cards / reports -------- */
.report-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card {
  background: var(--c-card); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow-sm); text-align: center; color: var(--c-muted); font-size: 12.5px;
}
.stat-card.link { color: var(--c-text); }
.stat-card.link:hover { box-shadow: var(--shadow-md); text-decoration: none; }
.stat-num { font-size: 26px; font-weight: 600; color: var(--c-text); }
.report-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 768px) { .report-row { grid-template-columns: 1fr; } }

.report-filter .filter-row { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; }
.report-filter label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--c-muted); }

.bar-chart { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.bar-chart li { display: grid; grid-template-columns: 64px 1fr 40px; align-items: center; gap: 8px; font-size: 12.5px; }
.bar-track { background: #f0f2f5; border-radius: 999px; height: 10px; overflow: hidden; }
.bar-fill  { display: block; background: var(--c-primary); height: 100%; border-radius: 999px; }
.bar-value { text-align: right; color: var(--c-muted); }
.bar-label { color: var(--c-muted); }

.tag-rank { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.tag-rank li { display: flex; gap: 8px; align-items: center; }

/* -------- Inbox shell -------- */
.inbox-shell {
  display: grid; grid-template-columns: 280px 1fr;
  gap: 16px; height: calc(100vh - 120px); min-height: 480px;
}
.inbox-filters {
  background: var(--c-card); border-radius: var(--radius); padding: 12px;
  box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 12px;
  overflow-y: auto;
}
.inbox-search { display: flex; gap: 6px; flex-wrap: wrap; }
.inbox-search input, .inbox-search select { flex: 1 1 100%; }
.inbox-quickfilters { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 2px; }
.inbox-quickfilters a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; border-radius: 6px; color: var(--c-text); font-size: 13px;
}
.inbox-quickfilters a:hover { background: #f0f2f5; text-decoration: none; }
.inbox-quickfilters a.active { background: var(--c-primary); color: #fff; }
.inbox-quickfilters .count { background: rgba(0,0,0,0.08); padding: 0 8px; border-radius: 999px; font-size: 11px; }
.inbox-quickfilters a.active .count { background: rgba(255,255,255,0.25); color: #fff; }

.inbox-list {
  background: var(--c-card); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  overflow-y: auto;
}
.inbox-row {
  display: flex; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--c-border);
  color: var(--c-text);
}
.inbox-row:hover { background: #fafbfc; text-decoration: none; }
.row-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: #e2e6ec;
  display: flex; align-items: center; justify-content: center; font-weight: 600; color: var(--c-muted);
  flex-shrink: 0;
}
.row-main { flex: 1; min-width: 0; }
.row-top { display: flex; justify-content: space-between; align-items: baseline; }
.row-name { font-weight: 600; font-size: 14px; }
.row-time { font-size: 11.5px; color: var(--c-muted); }
.row-mid { display: flex; justify-content: space-between; align-items: center; margin-top: 2px; }
.row-preview { font-size: 13px; color: var(--c-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-badge {
  background: var(--c-primary); color: #fff; border-radius: 999px; font-size: 11px;
  padding: 1px 8px; min-width: 20px; text-align: center;
}
.row-bot { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.row-meta { font-size: 11.5px; color: var(--c-muted); }

.empty-state { padding: 40px; text-align: center; color: var(--c-muted); }

/* -------- Chat detail -------- */
.chat-shell {
  display: grid; grid-template-columns: 1fr 320px;
  gap: 16px; height: calc(100vh - 120px); min-height: 480px;
}
.chat-main {
  display: flex; flex-direction: column;
  background: var(--c-card); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); overflow: hidden;
}
.chat-header {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 16px; border-bottom: 1px solid var(--c-border); background: #fafbfc;
}
.chat-back { font-size: 13px; }
.chat-title { flex: 1; display: flex; gap: 12px; align-items: baseline; }
.chat-title strong { font-size: 15px; }
.chat-title .muted { font-size: 12.5px; }
.chat-status { display: flex; gap: 6px; }

.chat-stream {
  flex: 1; overflow-y: auto; padding: 18px; background: #ece5dd;
  /* Faux WhatsApp-Web tile look (kept subtle for SaaS). */
  background-image: linear-gradient(180deg, rgba(255,255,255,0.4), rgba(255,255,255,0.4));
}
.msg { display: flex; margin-bottom: 8px; }
.msg-bubble {
  max-width: 70%; padding: 8px 12px; border-radius: 10px; box-shadow: var(--shadow-sm);
  font-size: 13.5px; word-wrap: break-word; white-space: pre-wrap;
}
.msg-in { justify-content: flex-start; }
.msg-in .msg-bubble { background: #fff; color: var(--c-text); border-top-left-radius: 2px; }
.msg-out { justify-content: flex-end; }
.msg-out .msg-bubble { background: #dcf8c6; color: #1a2330; border-top-right-radius: 2px; }
.msg-sender { font-size: 11.5px; color: var(--c-primary-d); font-weight: 600; margin-bottom: 2px; }
.msg-sender-ai { color: #6f42c1; }
.msg-sender-ai::before { content: "🤖 "; }

/* AI handover summary panel in the chat side */
.summary-box {
  margin-top: 8px;
  background: linear-gradient(180deg, #f7f3ff 0%, #efe9ff 100%);
  border: 1px solid #d6c8f5; border-radius: 8px;
  padding: 10px 12px; font-size: 12.5px;
}
.summary-text { white-space: pre-wrap; line-height: 1.5; color: var(--c-text); }
.summary-meta { margin-top: 8px; font-size: 11px; }
.summary-actions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 8px; }

/* AI draft panel above the composer */
.ai-draft {
  background: linear-gradient(180deg, #f7f3ff 0%, #efe9ff 100%);
  border: 1px solid #d6c8f5; border-radius: 8px; padding: 10px 12px;
  margin-bottom: 8px; font-size: 13px;
}
.ai-draft-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.ai-draft-head strong { color: #5a2eaa; font-size: 12.5px; }
.ai-draft-body { white-space: pre-wrap; color: var(--c-text); padding: 6px 0; min-height: 18px; }
.ai-draft-actions { display: flex; gap: 6px; margin-top: 4px; }
.msg-type-tag { font-size: 11px; color: var(--c-muted); margin-bottom: 4px; }
.msg-meta { font-size: 11px; color: var(--c-muted); margin-top: 4px; text-align: right; display: inline-flex; gap: 4px; align-items: center; justify-content: flex-end; width: 100%; }
.msg-error { color: var(--c-danger); cursor: help; }
.msg.status-failed .msg-bubble { background: #fdecea; }
.msg-status { display: inline-flex; align-items: center; }
.tick-icon { display: inline-block; vertical-align: middle; }
.tick-pending   { color: #8ba0ad; }
.tick-sent      { color: #8ba0ad; }
.tick-delivered { color: #8ba0ad; }
.tick-read      { color: #34b7f1; }
.tick-failed    { color: var(--c-danger); }

.chat-composer {
  border-top: 1px solid var(--c-border); padding: 12px 16px; background: #fafbfc;
}
.composer-form { display: flex; flex-direction: column; gap: 8px; }
.composer-form textarea {
  width: 100%; resize: vertical; min-height: 50px; max-height: 200px; font-size: 13.5px;
}
.composer-actions { display: flex; justify-content: space-between; align-items: center; }
.composer-locked {
  background: #fff3e0; border: 1px solid #ffd599; color: #6b3a00;
  padding: 12px; border-radius: 6px; font-size: 13px;
}
.template-list { margin: 8px 0 0; padding-left: 20px; font-size: 12.5px; }
.composer-extras { display: flex; gap: 6px; align-items: center; }
.composer-actions { gap: 8px; }
.template-head { display: flex; justify-content: space-between; align-items: center; }
.template-vars { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.template-vars label { font-size: 12px; color: var(--c-muted); display: flex; flex-direction: column; gap: 4px; }
.template-preview {
  margin-top: 8px; padding: 10px; background: #f4f6f8; border-radius: 6px;
  font-size: 12.5px; white-space: pre-wrap; min-height: 32px;
}
.hidden { display: none !important; }
.media-preview {
  display: flex; gap: 8px; align-items: center; padding: 6px 10px;
  background: #f4f6f8; border-radius: 6px; font-size: 12.5px; margin: 8px 0;
}
.media-preview img { max-height: 60px; border-radius: 4px; }
.media-preview button { margin-left: auto; }
.msg-media img { max-width: 280px; max-height: 220px; border-radius: 6px; display: block; }
.msg-media a { color: var(--c-primary-d); font-size: 12.5px; }

/* -------- Chat side panel -------- */
.chat-side {
  background: var(--c-card); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 0; overflow-y: auto;
}
.side-section { padding: 16px; border-bottom: 1px solid var(--c-border); }
.side-section h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; color: var(--c-muted); letter-spacing: 0.04em; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; margin-bottom: 4px; }
.kv span { color: var(--c-muted); }
.kv strong { font-weight: 500; text-align: right; }
.conv-action-form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.conv-action-form select, .conv-action-form input[type="text"] { flex: 1; min-width: 0; }
.conv-action-form textarea { width: 100%; }

.note-list { list-style: none; padding: 0; margin: 0 0 8px; max-height: 280px; overflow-y: auto; }
.note-list li { padding: 8px 10px; background: #fff8e1; border-left: 3px solid var(--c-warn); border-radius: 4px; margin-bottom: 6px; font-size: 12.5px; }
.note-meta { display: flex; gap: 8px; align-items: baseline; }
.note-body { margin-top: 4px; white-space: pre-wrap; }

.bullet { padding-left: 20px; }
.bullet li { margin-bottom: 4px; }

/* -------- Tag chips -------- */
.tag-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  color: #fff; font-weight: 500; line-height: 1.4;
}
.tag-chip-light {
  background: transparent; color: var(--c-text);
  border: 1px solid var(--c-border); padding: 1px 7px;
}
.tag-chip-x {
  background: transparent; border: none; cursor: pointer; color: inherit;
  font-size: 12px; padding: 0 0 0 2px; opacity: 0.7;
}
.tag-chip-x:hover { opacity: 1; }
.tag-list { display: flex; flex-wrap: wrap; gap: 4px; }
.tag-add-form { display: flex; gap: 4px; margin-top: 6px; }
.tag-add-form select { flex: 1; }

/* -------- Mobile drawer chrome (always defined; hidden until mobile) -------- */
.nav-toggle, .chat-side-toggle, .chat-side-close {
  display: none;
  background: none; border: 0; padding: 6px 10px;
  font-size: 20px; line-height: 1; color: var(--c-text); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chat-side-close { position: absolute; top: 8px; right: 8px; font-size: 24px; color: var(--c-muted); }
.sidebar-overlay {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(15,22,33,0.45);
}

/* -------- Tablet (>= 768px and <= 1024px) -------- */
@media (max-width: 1024px) and (min-width: 768px) {
  .inbox-shell { grid-template-columns: 240px 1fr; height: calc(100vh - 100px); }
  .chat-shell  { grid-template-columns: 1fr 280px; height: calc(100vh - 100px); }
}

/* ==========================================================
   Mobile (< 768px) - WhatsApp-app-style
   - Sidebar -> off-canvas hamburger drawer
   - Inbox -> single full-width list with sticky filters
   - Chat -> full-screen with the side panel as a right slide-in
   ========================================================== */
@media (max-width: 767px) {
  /* Sidebar slides in from the left */
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; width: 270px;
    transform: translateX(-100%); transition: transform 0.22s ease;
    z-index: 100;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay[hidden] { display: none; }

  /* Always-visible hamburger in the app header */
  .nav-toggle { display: inline-flex; align-items: center; }
  .app-header { padding: 10px 12px; gap: 8px; }
  .app-title  { font-size: 16px; flex: 1; min-width: 0;
                white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .app-content { padding: 12px; }

  /* Larger touch targets for everything */
  .btn { padding: 9px 14px; }
  .btn-sm { padding: 7px 12px; }
  input[type="text"], input[type="email"], input[type="password"],
  input[type="search"], textarea, select {
    font-size: 16px;     /* stops iOS Safari from zooming on focus */
  }

  /* Inbox: single column, sticky search + horizontally-scrolling filters */
  .inbox-shell { display: block; height: calc(100vh - 60px); }
  .inbox-filters {
    position: sticky; top: 0; z-index: 5;
    border-radius: 0; box-shadow: none;
    border-bottom: 1px solid var(--c-border);
    padding: 8px 10px; gap: 6px;
  }
  .inbox-search input, .inbox-search select { flex: 1 1 auto; min-width: 0; }
  .inbox-quickfilters {
    flex-direction: row; overflow-x: auto;
    padding-bottom: 2px; -webkit-overflow-scrolling: touch;
  }
  .inbox-quickfilters li { flex-shrink: 0; }
  .inbox-quickfilters a { padding: 6px 12px; font-size: 12.5px; border-radius: 999px; }
  .inbox-list { border-radius: 0; box-shadow: none; }
  .inbox-row { padding: 14px 14px; }
  .row-avatar { width: 44px; height: 44px; font-size: 16px; }
  .row-name { font-size: 15px; }
  .row-time, .row-meta { font-size: 11.5px; }

  /* Chat: full screen, panel becomes drawer */
  .chat-shell { display: block; height: calc(100vh - 60px); }
  .chat-main  {
    border-radius: 0; box-shadow: none; height: 100%;
    display: flex; flex-direction: column;
  }
  .chat-header { padding: 10px 12px; gap: 10px; }
  .chat-back { font-size: 18px; padding: 4px 8px; }
  .chat-title strong { font-size: 15px; }
  .chat-title .muted { display: none; }    /* phone number too long for header */
  .chat-side-toggle { display: inline-flex; }

  /* Stream takes available space; composer sticks to the bottom */
  .chat-stream { flex: 1; padding: 12px; min-height: 0; }
  .msg-bubble  { max-width: 85%; font-size: 14px; }
  .chat-composer { padding: 8px 10px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .composer-form textarea { min-height: 44px; font-size: 15px; }
  .composer-actions { flex-wrap: wrap; gap: 6px; }

  /* Side panel slides in from the right */
  .chat-side {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: 86vw; max-width: 360px;
    transform: translateX(100%); transition: transform 0.22s ease;
    z-index: 100; border-radius: 0;
    box-shadow: -8px 0 24px rgba(0,0,0,0.14);
    padding-top: 44px;   /* room for the close button */
  }
  .chat-side.open { transform: translateX(0); }
  .chat-side-close { display: inline-flex; }

  /* ---- Admin pages polish ---- */
  .card { padding: 14px; margin-bottom: 12px; border-radius: 8px; }
  .card h2 { font-size: 15px; }
  .card-head { flex-wrap: wrap; gap: 8px; }
  .card-head h2 { flex: 1 1 100%; }

  /* Long URLs / tokens in info boxes need to wrap */
  .alert { word-wrap: break-word; }
  .alert code { word-break: break-all; white-space: normal; }

  /* Tables -> auto-wrapped in .table-wrap by JS for horizontal scroll */
  .table-wrap {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    margin: 0 -14px; padding: 0 14px;
    border-bottom: 1px solid var(--c-border);
  }
  .table-wrap .data-table { min-width: 560px; }
  .data-table th, .data-table td { padding: 8px 10px; font-size: 12.5px; white-space: nowrap; }
  .data-table .actions { white-space: nowrap; }
  .data-table .actions form, .data-table .actions a { display: inline-block; margin-bottom: 4px; }

  /* Forms become single-column-wide on phones */
  .form-grid { max-width: 100%; gap: 10px; }

  /* Inline forms (Tags admin, Routing rules, etc) stack their controls */
  .inline-form { gap: 6px; }
  .inline-form input[type="text"],
  .inline-form input[type="search"],
  .inline-form select { flex: 1 1 60%; }

  /* Filter row on the Reports page */
  .report-filter .filter-row { gap: 8px; }
  .report-filter label { flex: 1 1 45%; }

  /* Provider picker cards (Settings page) */
  .provider-radio { padding: 10px; font-size: 13px; }
  .provider-radio small { display: block; margin-top: 2px; }

  /* Webhook log payload pre */
  .webhook-payload { font-size: 11px; max-height: 240px; }

  /* Stat cards (Dashboard + Reports) */
  .report-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-card { padding: 12px; }
  .stat-num { font-size: 22px; }

  /* Legal / static pages */
  .legal-page {
    margin: 0; padding: 20px 16px 40px;
    font-size: 14px; border-radius: 0; border-left: 0; border-right: 0;
    box-shadow: none;
  }
  .legal-page h1 { font-size: 22px; }
  .legal-page h2 { font-size: 16px; margin: 20px 0 6px; padding-top: 6px; }

  /* Login / register card spacing */
  .login-card  { padding: 24px 18px; max-width: 100%; border-radius: 10px; }
  .login-body  { padding: 16px; }

  /* Cookie notice already has its own mobile rules - keep above the
     hamburger drawer so it remains visible while sidebar is open */
}

/* ==========================================================
   Landing page
   ========================================================== */
.landing-body {
  margin: 0;
  background: #ffffff;
  color: var(--c-text);
  scroll-behavior: smooth;
}
.landing-body a { color: var(--c-primary-d); }
.btn-lg { padding: 12px 22px; font-size: 15px; border-radius: 8px; }

.landing-nav {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 32px; border-bottom: 1px solid var(--c-border);
  position: sticky; top: 0; background: rgba(255,255,255,0.92); backdrop-filter: blur(8px);
  z-index: 10;
}
.landing-brand { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--c-text); text-decoration: none; }
.landing-brand .brand-text { font-size: 15px; }
.landing-nav-links { display: flex; gap: 18px; align-items: center; }
.landing-nav-links a { color: var(--c-text); text-decoration: none; font-size: 14px; }
.landing-nav-links a:hover { color: var(--c-primary-d); }
.landing-nav-links .btn { color: #fff; }

.landing-hero {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 48px; align-items: center;
  padding: 64px 48px;
  max-width: 1200px; margin: 0 auto;
}
.landing-eyebrow {
  display: inline-block; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--c-primary-d); background: #e8f7ee; padding: 4px 10px; border-radius: 999px;
  margin-bottom: 16px;
}
.landing-hero h1 {
  margin: 0 0 16px; font-size: 44px; line-height: 1.1; letter-spacing: -0.02em;
}
.landing-lede { font-size: 17px; color: var(--c-muted); line-height: 1.55; max-width: 540px; }
.landing-cta { display: flex; gap: 12px; margin-top: 28px; flex-wrap: wrap; }
.landing-trust {
  list-style: none; padding: 0; margin: 32px 0 0; display: flex; flex-wrap: wrap; gap: 16px;
  font-size: 12.5px; color: var(--c-muted);
}
.landing-trust li::before { content: "✓ "; color: var(--c-primary); font-weight: 700; }

/* Hero mockup */
.landing-hero-mock { display: flex; justify-content: center; }
.mock-window {
  width: 100%; max-width: 520px;
  border-radius: 12px; overflow: hidden; border: 1px solid var(--c-border);
  box-shadow: 0 16px 48px rgba(20,30,50,0.18);
  background: #fff;
}
.mock-titlebar {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; background: #f4f6f8; border-bottom: 1px solid var(--c-border);
}
.mock-dot { width: 10px; height: 10px; border-radius: 50%; }
.dot-r { background: #ff5f57; } .dot-y { background: #ffbd2e; } .dot-g { background: #28c840; }
.mock-url { margin-left: 12px; font-size: 11.5px; color: var(--c-muted); }
.mock-body { display: grid; grid-template-columns: 110px 1fr 1fr; height: 320px; }
.mock-side { padding: 8px; border-right: 1px solid var(--c-border); background: #fafbfc; font-size: 11.5px; }
.mock-side-row {
  display: flex; justify-content: space-between; padding: 8px;
  border-radius: 6px; color: var(--c-muted);
}
.mock-side-row.active { background: var(--c-primary); color: #fff; }
.mock-side-row.active b { color: #fff; }
.mock-side-row b { color: var(--c-text); }
.mock-list { border-right: 1px solid var(--c-border); overflow: hidden; }
.mock-list-row {
  display: flex; gap: 8px; align-items: center; padding: 10px;
  border-bottom: 1px solid var(--c-border);
}
.mock-avatar {
  width: 28px; height: 28px; border-radius: 50%; color: #fff; font-size: 11px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-weight: 600;
}
.mock-avatar.a1 { background: #4a90e2; }
.mock-avatar.a2 { background: #f0ad4e; }
.mock-avatar.a3 { background: #d9534f; }
.mock-avatar.a4 { background: #5cb85c; }
.mock-list-text { flex: 1; min-width: 0; font-size: 11.5px; line-height: 1.3; }
.mock-list-text b { display: block; color: var(--c-text); font-size: 12px; }
.mock-list-text span { display: block; color: var(--c-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mock-list-row .badge { font-size: 10px; padding: 1px 6px; }

.mock-chat { background: #ece5dd; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.mock-msg { display: flex; }
.mock-msg span {
  max-width: 80%; padding: 6px 10px; border-radius: 8px;
  font-size: 11.5px; line-height: 1.3; box-shadow: var(--shadow-sm);
}
.mock-msg.in span  { background: #fff;     border-top-left-radius: 2px; }
.mock-msg.out     { justify-content: flex-end; }
.mock-msg.out span { background: #dcf8c6; border-top-right-radius: 2px; }
.mock-composer {
  margin-top: auto; padding: 8px 10px; background: #fafbfc;
  border-radius: 6px; font-size: 11.5px; color: var(--c-muted);
}

/* AI draft panel inside the hero mock */
.mock-ai-draft {
  background: linear-gradient(180deg, #f7f3ff 0%, #efe9ff 100%);
  border: 1px solid #d6c8f5; border-radius: 6px;
  padding: 6px 8px; margin-top: 4px; font-size: 10.5px; line-height: 1.35;
}
.mock-ai-head { display: flex; justify-content: space-between; gap: 6px; color: #5a2eaa; font-weight: 600; margin-bottom: 3px; }
.mock-ai-meta { color: #6f42c1; font-weight: 400; font-size: 10px; }
.mock-ai-body { color: #2a1657; padding: 3px 0; }
.mock-ai-actions { display: flex; gap: 4px; margin-top: 3px; }
.mock-mini-btn { background: #fff; border: 1px solid #d6c8f5; color: #5a2eaa; border-radius: 4px; padding: 1px 6px; font-size: 9.5px; }

/* Provider cards on the landing */
.provider-card .provider-bullets { list-style: none; padding: 0; margin: 12px 0 0; }
.provider-card .provider-bullets li { padding: 4px 0; font-size: 13px; color: var(--c-text); border-bottom: 1px dashed var(--c-border); }
.provider-card .provider-bullets li:last-child { border-bottom: none; }

/* AI-themed feature cards stand out */
.feature-card.feature-ai {
  background: linear-gradient(180deg, #f9f5ff 0%, #ffffff 60%);
  border-color: #d6c8f5;
}
.feature-card.feature-ai h3 { color: #5a2eaa; }

/* Legal pages (terms / privacy / disclaimer) */
main { display: block; }   /* normalize older browsers */
.legal-page {
  display: block;
  box-sizing: border-box;
  width: 100%;
  max-width: 760px;
  margin: 32px auto;
  padding: 32px 28px 48px;
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  color: var(--c-text);
  line-height: 1.65;
  font-size: 14.5px;
}
.landing-body:has(.legal-page) { background: #f4f6f8; }
.legal-page h1 { font-size: 28px; margin: 0 0 4px; letter-spacing: -0.01em; }
.legal-page h2 { font-size: 18px; margin: 28px 0 8px; padding-top: 8px; border-top: 1px solid var(--c-border); }
.legal-page p, .legal-page ul { margin: 0 0 12px; }
.legal-page ul { padding-left: 22px; }
.legal-page li { margin-bottom: 4px; }
.legal-page a { color: var(--c-primary-d); }
.legal-accept { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--c-border); border-radius: 6px; margin: 8px 0 4px; font-size: 12.5px; }
.legal-accept input { margin-top: 3px; }
.legal-accept span { color: var(--c-muted); }

/* Cookie notice */
.cookie-notice {
  position: fixed; bottom: 16px; right: 16px;
  max-width: 380px; z-index: 9999;
  background: #fff; border: 1px solid var(--c-border); border-radius: 10px;
  padding: 12px 14px; box-shadow: 0 8px 28px rgba(20,30,50,0.14);
  font-size: 13px; line-height: 1.45; color: var(--c-text);
  display: none; gap: 10px; align-items: center;
  transform: translateY(20px); opacity: 0; transition: transform 0.25s ease, opacity 0.25s ease;
}
.cookie-notice.show { display: flex; transform: translateY(0); opacity: 1; }
.cookie-notice-body { flex: 1; }
.cookie-notice-body strong { margin-right: 4px; }
.cookie-notice-body a { color: var(--c-primary-d); }
.cookie-notice-close {
  white-space: nowrap; padding: 6px 12px;
  background: var(--c-primary); color: #fff; border: 0; border-radius: 6px;
  font: inherit; cursor: pointer;
}
.cookie-notice-close:hover { background: var(--c-primary-d); }
@media (max-width: 480px) {
  .cookie-notice { left: 16px; right: 16px; max-width: none; flex-wrap: wrap; }
  .cookie-notice-close { width: 100%; }
}

/* Feature sections */
.landing-section { padding: 72px 48px; max-width: 1200px; margin: 0 auto; }
.landing-section.landing-alt { background: #f9fafb; max-width: none; padding-left: 0; padding-right: 0; }
.landing-section.landing-alt > * { max-width: 1200px; margin-left: auto; margin-right: auto; padding-left: 48px; padding-right: 48px; }
.landing-h2 { font-size: 28px; margin: 0 0 8px; letter-spacing: -0.01em; }
.landing-sub { font-size: 16px; color: var(--c-muted); margin: 0 0 32px; max-width: 720px; }

.landing-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}
.feature-card {
  background: #fff; border: 1px solid var(--c-border); border-radius: 10px; padding: 22px;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.feature-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.feature-card h3 { margin: 0 0 8px; font-size: 16px; }
.feature-card p { margin: 0; color: var(--c-muted); font-size: 13.5px; line-height: 1.55; }

.landing-steps { display: grid; gap: 24px; grid-template-columns: repeat(3, 1fr); }
.step { background: #fff; border-radius: 10px; padding: 24px; border: 1px solid var(--c-border); }
.step-num {
  width: 32px; height: 32px; border-radius: 50%; background: var(--c-primary); color: #fff;
  font-weight: 700; display: flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
}
.step h3 { margin: 0 0 6px; font-size: 16px; }
.step p { margin: 0; color: var(--c-muted); font-size: 13.5px; line-height: 1.55; }

/* Plans */
.landing-grid.plans { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); align-items: stretch; }
.plan-card {
  position: relative; background: #fff; border: 1px solid var(--c-border); border-radius: 12px;
  padding: 28px; display: flex; flex-direction: column; gap: 12px;
}
.plan-card.highlight { border-color: var(--c-primary); box-shadow: 0 8px 24px rgba(37,211,102,0.18); }
.plan-card h3 { margin: 0; font-size: 22px; }
.plan-card ul { list-style: none; padding: 0; margin: 0; flex: 1; }
.plan-card li { padding: 6px 0; font-size: 14px; color: var(--c-text); border-bottom: 1px dashed var(--c-border); }
.plan-card li:last-child { border-bottom: none; }
.plan-badge {
  position: absolute; top: -10px; right: 16px;
  background: var(--c-primary); color: #fff; font-size: 11px; padding: 4px 10px;
  border-radius: 999px; letter-spacing: 0.04em; text-transform: uppercase;
}

.landing-cta-band {
  background: linear-gradient(135deg, var(--c-primary-d), var(--c-accent));
  color: #fff; text-align: center; padding: 64px 32px;
}
.landing-cta-band h2 { margin: 0 0 8px; font-size: 28px; }
.landing-cta-band p { margin: 0 0 24px; opacity: 0.9; }
.landing-cta-band .btn-primary { background: #fff; color: var(--c-primary-d); border-color: #fff; }
.landing-cta-band .btn-primary:hover { background: #f4f6f8; color: var(--c-accent); }

.landing-footer {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;
  padding: 24px 48px; border-top: 1px solid var(--c-border);
  font-size: 12.5px; color: var(--c-muted); gap: 12px;
}
.landing-footer a { color: var(--c-muted); }
.landing-footer .dot { margin: 0 6px; }

@media (max-width: 960px) {
  .landing-hero { grid-template-columns: 1fr; padding: 40px 24px; }
  .landing-hero h1 { font-size: 34px; }
  .landing-section, .landing-section.landing-alt > * { padding-left: 24px; padding-right: 24px; }
  .landing-section { padding-top: 48px; padding-bottom: 48px; }
  .landing-steps { grid-template-columns: 1fr; }
  .landing-nav { padding: 14px 20px; }
  .landing-nav-links a:not(.btn) { display: none; }
  .mock-body { grid-template-columns: 1fr; height: auto; }
  .mock-side, .mock-list { border-right: none; border-bottom: 1px solid var(--c-border); }
  .landing-footer { padding: 20px 24px; }
}

