/* Sales Assistant admin: design tokens, light + dark */
:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e4e7ec;
  --border-strong: #d2d7df;
  --text: #171a1f;
  --muted: #68707d;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0ff;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --sidebar: #14161c;
  --sidebar-text: #c9cdd6;
  --sidebar-active: #252833;
  --bubble-in: #eef0f4;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --shadow-lg: 0 12px 32px rgb(16 24 40 / 14%);
  /* lightness pairs used by hue-based chips and avatars */
  --tint-bg: 94%;
  --tint-fg: 32%;
  --radius: 12px;
  color-scheme: light;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #171a20;
    --surface-2: #1c2027;
    --border: #272c35;
    --border-strong: #363c47;
    --text: #e7e9ee;
    --muted: #949cab;
    --accent: #6d68f5;
    --accent-hover: #807cf7;
    --accent-soft: #23234a;
    --sidebar: #0a0b0e;
    --sidebar-active: #1c1f27;
    --bubble-in: #232831;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-lg: 0 12px 32px rgb(0 0 0 / 50%);
    --tint-bg: 20%;
    --tint-fg: 80%;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4, p { margin: 0; }
h2 { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
h4 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1.2em; font-size: 13px; }
svg { width: 18px; height: 18px; display: block; flex: none; }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 550; padding: 7px 12px; border-radius: 8px; cursor: pointer;
  background: var(--surface); color: var(--text); border: 1px solid var(--border-strong);
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.icon-only { padding: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { background: transparent; border: 0; color: inherit; padding: 6px; border-radius: 8px; cursor: pointer; opacity: .75; }
.icon-btn:hover { opacity: 1; background: rgb(255 255 255 / 8%); }
input, select, textarea {
  font: inherit; width: 100%; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .nav-item:focus-visible, .chip:focus-visible {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
label { display: grid; gap: 5px; font-size: 12px; font-weight: 550; color: var(--muted); }
label input, label select, label textarea { font-size: 14px; font-weight: 400; }
hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 50% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent), var(--bg); }
.login-card { width: min(380px, 100%); display: grid; gap: 14px; padding: 28px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); }
.login-card h1 { font-size: 22px; letter-spacing: -0.02em; }
.logo-mark { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.logo-mark svg { width: 22px; height: 22px; }
.logo-mark.sm { width: 32px; height: 32px; border-radius: 9px; }
.logo-mark.sm svg { width: 17px; height: 17px; }

/* ---------- Shell ---------- */
.app { display: grid; grid-template-columns: 220px minmax(0, 1fr); height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; padding: 14px 10px; gap: 18px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px; color: #fff; font-weight: 650; letter-spacing: -0.01em; }
.nav { display: grid; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 8px;
  background: transparent; color: inherit; font: inherit; font-weight: 550; cursor: pointer; text-align: left; }
.nav-item:hover { background: var(--sidebar-active); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-item.active svg { color: #a5b4fc; }
.nav-label { flex: 1; }
.count { min-width: 20px; padding: 1px 6px; border-radius: 999px; background: #ef4444; color: #fff; font-size: 11px; font-weight: 700; text-align: center; }
.sidebar-foot { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 10px 6px 2px; border-top: 1px solid rgb(255 255 255 / 8%); }
.me { min-width: 0; flex: 1; }
.me-name { color: #fff; font-weight: 600; font-size: 13px; }
.me-email { font-size: 11px; opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.content { min-width: 0; height: 100vh; overflow: hidden; }
.tab-panel { height: 100%; }
.page { padding: 24px 28px; overflow-y: auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }

/* ---------- Avatar & chips (hue driven) ---------- */
.avatar { --h: 230; width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 650; font-size: 13px; position: relative;
  background: hsl(var(--h) 70% var(--tint-bg)); color: hsl(var(--h) 60% var(--tint-fg)); }
.avatar.sm { width: 30px; height: 30px; font-size: 11px; }
.avatar.lg { width: 44px; height: 44px; font-size: 15px; }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.platform { position: absolute; right: -3px; bottom: -3px; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--surface); display: grid; place-items: center; color: #fff; }
.platform svg { width: 9px; height: 9px; }
.platform.messenger { background: #0084ff; }
.platform.instagram { background: linear-gradient(45deg, #f09433, #dc2743 55%, #bc1888); }

.status { --h: 220; display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 7px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: hsl(var(--h) 85% var(--tint-bg)); color: hsl(var(--h) 70% var(--tint-fg)); }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.NEW_MESSAGE { --h: 42; }
.status.AI_HANDLING { --h: 230; }
.status.COLLECTING_ORDER { --h: 265; }
.status.AWAITING_CONFIRMATION { --h: 195; }
.status.HUMAN_NEEDED { --h: 0; }
.status.HUMAN_HANDLING { --h: 24; }
.status.ORDER_CONFIRMED { --h: 145; }
.status.CLOSED { --h: 220; filter: saturate(.25); }
.status.confirmed { --h: 230; } .status.processing { --h: 42; } .status.shipped { --h: 195; }
.status.delivered { --h: 145; } .status.cancelled { --h: 0; }

/* ---------- Tickets ---------- */
.tickets { display: grid; grid-template-columns: 360px minmax(0, 1fr); }
.list-pane { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.pane-head { padding: 18px 16px 12px; display: grid; gap: 12px; border-bottom: 1px solid var(--border); }
.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; }
.search input { padding-left: 32px; background: var(--surface-2); }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); font: inherit; font-size: 12.5px; font-weight: 550; cursor: pointer; }
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.ticket-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.ticket { display: flex; gap: 11px; padding: 11px 10px; border-radius: 10px; cursor: pointer; }
.ticket:hover { background: var(--surface-2); }
.ticket.active { background: var(--accent-soft); }
.ticket-body { min-width: 0; flex: 1; display: grid; gap: 3px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.name { font-weight: 620; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.time { font-size: 11.5px; color: var(--muted); flex: none; }
.preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ticket-meta { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.detail-pane { display: grid; grid-template-columns: minmax(0, 1fr) 320px; min-height: 0; height: 100%; }
.detail-pane > .empty { grid-column: 1 / -1; }
.conversation { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.conv-header { display: flex; align-items: center; gap: 12px; padding: 12px 18px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.conv-title { min-width: 0; flex: 1; }
.conv-title .name { font-size: 15px; }
.conv-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.banner { display: flex; align-items: center; gap: 8px; padding: 8px 18px; font-size: 12.5px; font-weight: 550;
  background: hsl(0 85% var(--tint-bg)); color: hsl(0 70% var(--tint-fg)); border-bottom: 1px solid var(--border); }
.banner.info { background: var(--accent-soft); color: var(--accent); }
.banner svg { width: 15px; height: 15px; }

/* ---------- Chat ---------- */
.chat { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 3px; }
.day { align-self: center; margin: 10px 0 6px; padding: 2px 10px; border-radius: 999px; font-size: 11px; font-weight: 600;
  color: var(--muted); background: var(--surface); border: 1px solid var(--border); }
.msg { display: flex; flex-direction: column; max-width: min(74%, 560px); }
.msg.inbound { align-self: flex-start; align-items: flex-start; }
.msg.outbound { align-self: flex-end; align-items: flex-end; }
.msg + .msg.first { margin-top: 10px; }
.who { font-size: 11px; font-weight: 600; color: var(--muted); margin: 0 4px 3px; display: flex; align-items: center; gap: 5px; }
.who svg { width: 12px; height: 12px; }
.bubble { padding: 8px 12px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; box-shadow: var(--shadow); }
.inbound .bubble { background: var(--surface); border-bottom-left-radius: 6px; }
.outbound .bubble { border-bottom-right-radius: 6px; }
.outbound.ai .bubble { background: var(--accent); color: #fff; }
.outbound.agent .bubble { background: hsl(150 55% var(--tint-bg)); color: hsl(150 60% var(--tint-fg)); }
.outbound.system .bubble { background: hsl(42 90% var(--tint-bg)); color: hsl(42 80% var(--tint-fg)); }
.meta { font-size: 10.5px; color: var(--muted); margin: 3px 5px 0; }
.meta.failed { color: var(--danger); font-weight: 600; }
.composer { display: flex; gap: 8px; padding: 12px 16px; background: var(--surface); border-top: 1px solid var(--border); }
.composer input { border-radius: 999px; padding: 9px 16px; background: var(--surface-2); }
.composer .btn { border-radius: 999px; }

/* ---------- Side panel ---------- */
.side { overflow-y: auto; padding: 16px; display: grid; gap: 14px; align-content: start; background: var(--surface); border-left: 1px solid var(--border); }
.side-card { display: grid; gap: 8px; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.profile { display: flex; align-items: center; gap: 12px; }
.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 5px 12px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.lines { display: grid; gap: 4px; font-size: 13px; }
.line { display: flex; justify-content: space-between; gap: 10px; }
.line.total { font-weight: 650; padding-top: 6px; border-top: 1px dashed var(--border-strong); }
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 12px; }
.events li { display: grid; grid-template-columns: 8px 1fr; gap: 8px; align-items: baseline; }
.events li::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--border-strong); transform: translateY(-1px); }
.note { font-size: 13px; padding: 8px 10px; border-radius: 8px; background: hsl(0 85% var(--tint-bg)); color: hsl(0 70% var(--tint-fg)); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  padding: 11px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table select { width: auto; padding: 4px 26px 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.strong { font-weight: 620; }

/* ---------- Empty states ---------- */
.empty { display: grid; place-items: center; align-content: center; gap: 10px; padding: 48px 16px; color: var(--muted); text-align: center; height: 100%; }
.empty svg { width: 34px; height: 34px; opacity: .5; }
li.empty { height: auto; list-style: none; }

/* ---------- Simulator ---------- */
.sim { display: grid; grid-template-columns: 300px minmax(0, 400px); gap: 24px; justify-content: center; align-items: start; }
.sim-controls { padding: 16px; display: grid; gap: 12px; }
.sim-ticket { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; min-height: 22px; }
.phone { background: var(--surface); border: 1px solid var(--border); border-radius: 28px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; height: min(680px, calc(100vh - 150px)); overflow: hidden; }
.phone-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.phone-avatar { background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; }
.phone-avatar svg { width: 15px; height: 15px; }
.phone .chat { background: var(--surface); }
/* In the simulator the viewer is the customer: their messages go right. */
.phone .msg.inbound { align-self: flex-end; align-items: flex-end; }
.phone .msg.outbound { align-self: flex-start; align-items: flex-start; }
.phone .inbound .bubble { background: var(--accent); color: #fff; border-radius: 16px 16px 6px 16px; box-shadow: none; }
.phone .outbound .bubble { background: var(--bubble-in); color: var(--text); border-radius: 16px 16px 16px 6px; box-shadow: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .detail-pane { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .sidebar { flex-direction: row; align-items: center; padding: 8px 12px; gap: 8px; }
  .brand-name, .me, .nav-label { display: none; }
  .nav { display: flex; flex: 1; gap: 4px; }
  .nav-item { width: auto; padding: 8px 10px; }
  .sidebar-foot { margin: 0; padding: 0; border: 0; }
  .content { height: auto; overflow: visible; }
  .tickets { grid-template-columns: 1fr; height: auto; }
  .list-pane { max-height: 45vh; border-right: 0; border-bottom: 1px solid var(--border); }
  .detail-pane { height: 70vh; }
  .page { padding: 16px; }
  .sim { grid-template-columns: 1fr; }
  .msg { max-width: 88%; }
}

/* ---------- Catalog & settings ---------- */
h3 { font-size: 15px; font-weight: 650; margin: 0; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.brand-select { width: auto; min-width: 180px; font-weight: 600; }
.stack { display: grid; gap: 14px; }
.form-card { padding: 18px; display: grid; gap: 14px; align-content: start; }
.settings-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
textarea { resize: vertical; min-height: 72px; line-height: 1.45; }
textarea.tall { min-height: 220px; }
.hint { font-weight: 400; color: var(--muted); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; align-items: center; }

.product { overflow: hidden; }
.product-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; flex-wrap: wrap; }
.product-title { min-width: 0; flex: 1; }
.product-title .name { font-size: 15px; white-space: normal; }
.product-details { padding: 0 16px 14px; display: grid; gap: 12px; }
.thumb { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; flex: none; background: var(--surface-2); border: 1px solid var(--border); }
.variants td, .variants th { padding: 8px 16px; }
.variants input[type="number"] { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
.variants .soldout { color: var(--danger); font-weight: 600; font-size: 12px; }
.link { color: var(--accent); text-decoration: none; font-size: 12.5px; }
.link:hover { text-decoration: underline; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 12.5px; font-weight: 550; color: var(--muted); }
.switch input { appearance: none; width: 34px; height: 20px; padding: 0; border-radius: 999px; border: 0; background: var(--border-strong); position: relative; cursor: pointer; transition: background .15s; flex: none; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgb(0 0 0 / 30%); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(14px); }

.faq-item { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.faq-item textarea { min-height: 60px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); padding: 9px 16px; border-radius: 999px; font-weight: 600; font-size: 13px;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); z-index: 50; }
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 1100px) { .settings-grid { grid-template-columns: 1fr; } }
@media (max-width: 820px) { .grid-2, .grid-4 { grid-template-columns: 1fr; } .variants input[type="number"] { width: 84px; } }
