/* ===== Themes (ElevenLabs-inspired: monochrome, flat, restrained) ===== */
:root {
  --r-sm: 6px; --r-md: 8px; --r-lg: 10px;
  --accent: #5b6cff;
  --accent-soft: rgba(91,108,255,.12);
  --green: #16a34a; --amber: #d97706; --violet: #7c5cff; --red: #e5484d; --blue: #3b82f6;
  --shadow: 0 8px 30px rgba(0,0,0,.18);
  --ff: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
:root, :root[data-theme="dark"] {
  --bg: #0a0a0b; --surface: #131315; --elevated: #1a1a1d; --raise: #202024;
  --border: #262629; --border-strong: #34343a;
  --text: #f4f4f5; --text-dim: #a1a1aa; --text-muted: #71717a;
  --btn-fg: #ededf0; --btn-bg: #1f1f23; --btn-border: #34343a;
  --primary-bg: #fafafa; --primary-fg: #0a0a0b;
  --client-bubble: #1c1c20; --manager-bubble: #4f5bd5; --manager-fg: #ffffff;
  --chat-bg: #0c0c0e;
}
:root[data-theme="light"] {
  --bg: #ffffff; --surface: #fafafa; --elevated: #ffffff; --raise: #f4f4f5;
  --border: #e8e8eb; --border-strong: #d4d4d8;
  --text: #09090b; --text-dim: #52525b; --text-muted: #a1a1aa;
  --btn-fg: #18181b; --btn-bg: #ffffff; --btn-border: #e0e0e4;
  --primary-bg: #09090b; --primary-fg: #ffffff;
  --client-bubble: #f1f1f3; --manager-bubble: #4f5bd5; --manager-fg: #ffffff;
  --chat-bg: #ffffff;
  --shadow: 0 8px 30px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--ff); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
svg { display: block; }
.icon { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.6; }

/* ===== Shell ===== */
.app { display: grid; grid-template-columns: 240px 1fr; height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 16px 12px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; }
.brand .logo { width: 30px; height: 30px; border-radius: var(--r-sm); background: var(--primary-bg); color: var(--primary-fg); display: grid; place-items: center; font-weight: 700; font-size: 15px; }
.brand b { font-size: 14px; font-weight: 600; letter-spacing: -.01em; }
.brand small { display: block; color: var(--text-muted); font-size: 11px; font-weight: 400; }

.nav { display: flex; flex-direction: column; gap: 1px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: var(--r-md); color: var(--text-dim); font-weight: 500; font-size: 13.5px; transition: background .1s, color .1s; }
.nav a:hover { background: var(--elevated); color: var(--text); }
.nav a.active { background: var(--elevated); color: var(--text); }
.nav .badge { margin-left: auto; background: var(--accent); color: #fff; font-size: 11px; font-weight: 600; border-radius: 20px; padding: 0 7px; min-width: 18px; text-align: center; }
.sidebar .spacer { flex: 1; }
.side-foot { display: flex; align-items: center; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.me { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--elevated); border: 1px solid var(--border); display: grid; place-items: center; font-weight: 600; font-size: 12px; color: var(--text-dim); flex-shrink: 0; }
.me .name { font-weight: 600; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me .role { color: var(--text-muted); font-size: 11px; }
.icon-btn { background: transparent; border: 1px solid transparent; border-radius: var(--r-sm); padding: 6px; color: var(--text-muted); cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: var(--elevated); color: var(--text); }

.main { overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 56px; border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 20px; gap: 12px; background: var(--bg); flex-shrink: 0; }
.topbar h1 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
.topbar .sub { color: var(--text-muted); font-size: 12.5px; }
.topbar .right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.content { flex: 1; overflow: auto; padding: 22px; }

/* ===== Inbox ===== */
.inbox { display: grid; grid-template-columns: 340px 1fr; height: 100%; overflow: hidden; }
.conv-col { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.conv-tabs { display: flex; gap: 2px; padding: 12px 12px 8px; }
.conv-tabs a { flex: 1; text-align: center; padding: 7px 6px; border-radius: var(--r-md); color: var(--text-dim); font-weight: 500; font-size: 13px; }
.conv-tabs a.active { background: var(--elevated); color: var(--text); }
.conv-tabs a .cnt { color: var(--text-muted); font-weight: 600; margin-left: 3px; }
.conv-list { overflow-y: auto; flex: 1; padding: 4px 8px 12px; }
.conv-item { display: block; padding: 11px 12px; border-radius: var(--r-md); margin-bottom: 2px; border: 1px solid transparent; cursor: pointer; }
.conv-item:hover { background: var(--elevated); }
.conv-item.active { background: var(--elevated); border-color: var(--border); }
.conv-item .row1 { display: flex; align-items: center; gap: 8px; }
.conv-item .cname { font-weight: 600; font-size: 13.5px; }
.conv-item .ctime { margin-left: auto; color: var(--text-muted); font-size: 11px; }
.conv-item .preview { color: var(--text-dim); font-size: 13px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .row3 { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.unread-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.empty-list { color: var(--text-muted); text-align: center; padding: 40px 20px; font-size: 13px; }

/* ===== Status pills ===== */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: var(--r-sm); }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.new { color: var(--blue); background: rgba(59,130,246,.12); }
.pill.in_progress { color: var(--amber); background: rgba(217,119,6,.14); }
.pill.waiting_client { color: var(--violet); background: rgba(124,92,255,.14); }
.pill.closed { color: var(--text-muted); background: rgba(113,113,122,.14); }

/* ===== Chat detail ===== */
.detail { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.detail-head { padding: 12px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; background: var(--bg); }
.detail-head .who b { font-size: 14px; font-weight: 600; }
.detail-head .who small { display: block; color: var(--text-muted); font-size: 12px; }
.detail-head .actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.chat { flex: 1; overflow-y: auto; padding: 20px 22px; display: flex; flex-direction: column; gap: 8px; background: var(--chat-bg); }
.msg { max-width: 62%; padding: 8px 12px; border-radius: var(--r-lg); font-size: 13.5px; word-wrap: break-word; }
.msg .t { font-size: 10px; color: var(--text-muted); margin-top: 3px; text-align: right; }
.msg.client { align-self: flex-start; background: var(--client-bubble); border-bottom-left-radius: 3px; }
.msg.manager { align-self: flex-end; background: var(--manager-bubble); color: var(--manager-fg); border-bottom-right-radius: 3px; }
.msg.manager .t { color: rgba(255,255,255,.72); }
.msg.bot { align-self: center; background: transparent; border: 1px solid var(--border); color: var(--text-muted); font-size: 12px; max-width: 78%; text-align: center; }
.msg .sender { font-size: 11px; font-weight: 600; opacity: .85; margin-bottom: 2px; }

/* ===== Media in chat ===== */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 4px; margin: 4px 0; max-width: 320px; }
.media-grid.single { grid-template-columns: 1fr; max-width: 260px; }
.media-thumb { position: relative; aspect-ratio: 1/1; border-radius: var(--r-sm); overflow: hidden; cursor: pointer; background: var(--raise); }
.media-grid.single .media-thumb { aspect-ratio: auto; max-height: 280px; }
.media-thumb img, .media-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-grid.single .media-thumb img { object-fit: contain; }
.media-thumb .play { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; background: rgba(0,0,0,.25); }
.file-chip { display: inline-flex; align-items: center; gap: 9px; padding: 8px 11px; border-radius: var(--r-md); background: rgba(0,0,0,.14); margin: 3px 0; max-width: 260px; }
.msg.manager .file-chip { background: rgba(255,255,255,.16); }
.file-chip .fi { width: 30px; height: 30px; border-radius: var(--r-sm); background: rgba(0,0,0,.2); display: grid; place-items: center; flex-shrink: 0; }
.msg.manager .file-chip .fi { background: rgba(255,255,255,.2); }
.file-chip .fn { font-size: 12.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .fs { font-size: 11px; opacity: .7; }
audio { height: 34px; max-width: 240px; margin-top: 4px; }

/* ===== Lightbox ===== */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.88); display: none; align-items: center; justify-content: center; z-index: 100; }
.lightbox.open { display: flex; }
.lightbox img, .lightbox video { max-width: 90vw; max-height: 90vh; border-radius: var(--r-md); }
.lightbox .lb-close { position: absolute; top: 20px; right: 24px; color: #fff; cursor: pointer; background: rgba(255,255,255,.1); border: none; border-radius: var(--r-sm); padding: 8px; }

/* ===== Composer ===== */
.composer { border-top: 1px solid var(--border); padding: 10px 14px 12px; background: var(--bg); }
.qr-bar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.qr-chip { font-size: 12px; padding: 4px 10px; border-radius: var(--r-md); background: var(--elevated); border: 1px solid var(--border); color: var(--text-dim); cursor: pointer; }
.qr-chip:hover { color: var(--text); border-color: var(--border-strong); }
.composer form { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 10px 12px; min-height: 42px; max-height: 140px; outline: none; }
.composer textarea:focus { border-color: var(--border-strong); }
.attach-previews { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.attach-previews:empty { display: none; }
.att-prev { display: inline-flex; align-items: center; gap: 7px; background: var(--elevated); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 4px 8px; font-size: 12px; }
.att-prev img { width: 26px; height: 26px; object-fit: cover; border-radius: 4px; }
.att-prev .rm { cursor: pointer; color: var(--text-muted); }
.att-prev .rm:hover { color: var(--red); }

.detail-empty { display: grid; place-items: center; height: 100%; color: var(--text-muted); text-align: center; }
.detail-empty .dico { color: var(--border-strong); margin-bottom: 12px; }

/* ===== Buttons / forms ===== */
.btn { display: inline-flex; align-items: center; gap: 7px; justify-content: center; padding: 8px 14px; border-radius: var(--r-md); border: 1px solid var(--btn-border); background: var(--btn-bg); color: var(--btn-fg); font-weight: 500; font-size: 13px; cursor: pointer; transition: .1s; }
.btn:hover { border-color: var(--border-strong); }
.btn.primary { background: var(--primary-bg); border-color: var(--primary-bg); color: var(--primary-fg); font-weight: 600; }
.btn.primary:hover { opacity: .9; }
.btn.sm { padding: 6px 11px; font-size: 12px; }
.btn.ghost { background: transparent; }
.btn.danger:hover { border-color: var(--red); color: var(--red); }
select.status-select { padding: 7px 11px; border-radius: var(--r-md); background: var(--btn-bg); border: 1px solid var(--btn-border); font-weight: 500; font-size: 13px; cursor: pointer; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 13px; }
.field label { font-size: 12px; color: var(--text-dim); font-weight: 500; }
.field input, .field textarea, .field select { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 9px 12px; outline: none; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--border-strong); }

/* ===== Cards / grids ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 18px; }
.card h3 { margin: 0 0 14px; font-size: 13.5px; font-weight: 600; letter-spacing: -.01em; }
.grid { display: grid; gap: 14px; }
.kpi-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 15px 17px; }
.kpi .label { color: var(--text-dim); font-size: 12px; font-weight: 500; }
.kpi .value { font-size: 25px; font-weight: 650; margin-top: 6px; letter-spacing: -.02em; }
.kpi .value.small { font-size: 19px; }
.kpi .foot { color: var(--text-muted); font-size: 11px; margin-top: 4px; }
.kpi .value .u { font-size: 14px; color: var(--text-dim); font-weight: 500; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-size: 11.5px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: none; }
.muted { color: var(--text-muted); }
.tag { display: inline-block; background: var(--elevated); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 1px 7px; font-size: 12px; color: var(--text-dim); }

/* ===== Login ===== */
.login-wrap { height: 100vh; display: grid; place-items: center; background: var(--bg); }
.login-card { width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 30px; box-shadow: var(--shadow); }
.login-card .brand { justify-content: center; padding-bottom: 20px; }
.login-card h2 { margin: 0 0 4px; text-align: center; font-size: 18px; font-weight: 600; }
.login-card .hint { text-align: center; color: var(--text-muted); font-size: 12.5px; margin-bottom: 22px; }
.login-card .err { background: rgba(229,72,77,.1); color: var(--red); padding: 9px 12px; border-radius: var(--r-md); font-size: 13px; margin-bottom: 14px; text-align: center; }
.login-card .btn { width: 100%; margin-top: 6px; }
.demo-creds { margin-top: 16px; font-size: 12px; color: var(--text-muted); text-align: center; border-top: 1px solid var(--border); padding-top: 14px; line-height: 1.7; }
.demo-creds code { color: var(--text-dim); }

.page-head { display: flex; align-items: center; margin-bottom: 18px; gap: 12px; }
.page-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.page-head .btn { margin-left: auto; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; border: 2px solid var(--surface); }
::-webkit-scrollbar-track { background: transparent; }
