/* CS Bot Admin — "Warm Bilingual" theme */
:root {
  --bg: #f7f2ec; --surface: #fffdfb; --surface-2: #f1eae2; --surface-3: #e4dbd0; --line: #f1eae2; --line-2: #e4dbd0;
  --text: #2b2520; --muted: #7a6e64; --faint: #a3968b;
  --accent: #c4541b; --accent-600: #9a3f12; --accent-soft: #fde2cf; --accent-soft-2: #fbf0e8;
  --ok: #1f6b35; --ok-bg: #e3f4e6; --warn: #9a5b12; --warn-bg: #fdebd6; --danger: #8a2d4b; --danger-bg: #fbe3ea;
  --note-bg: #fff7e0; --note-line: #f5dc9a; --purple: #4b3a86; --purple-bg: #e8e3f6;
  --radius: 18px; --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .05), 0 6px 20px rgba(60, 40, 20, .06);
  --shadow-lg: 0 10px 40px rgba(60, 40, 20, .18);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14.5px/1.5 "Kantumruy Pro", "Khmer UI", "Segoe UI", system-ui, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; } a:hover { color: var(--accent-600); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 8px; font-weight: 700; }
h1 { font-size: 24px; letter-spacing: -.01em; line-height: 1.1; } h2 { font-size: 17px; } h3 { font-size: 13px; color: var(--faint); font-weight: 600; }
[hidden] { display: none !important; }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
svg.i.sm { width: 16px; height: 16px; }

/* ── Layout ─────────────────────────────── */
#app { display: flex; min-height: 100vh; }
#sidebar { width: 250px; flex-shrink: 0; display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh; background: var(--bg); }
#sidebar .brand { display: flex; align-items: center; gap: 12px; padding: 4px 10px 18px; }
#sidebar .brand .logo { width: 40px; height: 40px; border-radius: 14px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 16px rgba(196, 84, 27, .35); flex-shrink: 0; }
#sidebar .brand b { display: block; font-size: 16px; line-height: 1.2; }
#sidebar .brand small { display: block; font-size: 12.5px; color: var(--faint); }
#sidebar nav { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
#sidebar nav a { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: var(--radius-sm); color: var(--muted); }
#sidebar nav a:hover { background: rgba(255, 253, 251, .7); color: var(--text); }
#sidebar nav a.active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 14px rgba(60, 40, 20, .06); }
#sidebar nav a .en { font-size: 14.5px; font-weight: 600; line-height: 1.15; }
#sidebar nav a .kh { font-size: 12px; opacity: .75; line-height: 1.3; }
#sidebar nav a .cnt { margin-left: auto; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 12px; background: var(--accent); color: #fff; font-size: 12.5px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
#sidebar .user { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); }
#sidebar .user b { display: block; font-size: 14px; }
#sidebar .user small { color: var(--faint); font-size: 12px; }
#sidebar .user button { margin-left: auto; }
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar { display: flex; align-items: center; gap: 16px; padding: 22px 24px 6px 8px; flex-wrap: wrap; }
#topbar .titles { flex: 1; min-width: 160px; }
#page-sub { font-size: 13.5px; color: var(--faint); }
#content { padding: 14px 24px 24px 8px; flex: 1; }
#menu-btn { display: none; }
.pw-warn { margin: 14px 24px 0 8px; background: var(--warn-bg); color: var(--warn); padding: 10px 16px; font-size: 13.5px; border-radius: var(--radius-sm); }
.pw-warn.danger { background: var(--danger-bg); color: var(--danger); }

/* ── Components ─────────────────────────── */
.card { background: var(--surface); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.tight { padding: 0; overflow: hidden; }
.card h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.card h2 .spacer, .row .spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.kpi { background: var(--surface); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .lbl { color: var(--faint); font-size: 13px; font-weight: 600; }
.kpi .val { font-size: 28px; font-weight: 700; margin-top: 2px; line-height: 1.15; }
.kpi .sub { color: var(--faint); font-size: 12.5px; }
.kpi.warn .val { color: var(--warn); } .kpi.ok .val { color: var(--ok); } .kpi.danger .val { color: var(--danger); } .kpi.primary .val { color: var(--accent); }
.btn { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: var(--radius-sm); border: 0; background: var(--surface-2); cursor: pointer; font-weight: 600; font-size: 14px; color: var(--text); white-space: nowrap; }
.btn:hover { background: var(--surface-3); } .btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; } .btn.primary:hover { background: var(--accent-600); }
.btn.danger { background: var(--danger-bg); color: var(--danger); } .btn.danger:hover { background: #f6d3de; }
.btn.ok { background: var(--ok-bg); color: var(--ok); } .btn.ok:hover { background: #d2ecd7; }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn.ghost { background: transparent; } .btn.ghost:hover { background: var(--surface-2); }
.btn.icon { width: 40px; padding: 0; justify-content: center; } .btn.icon.sm { width: 32px; }
.input, select.input, textarea.input { width: 100%; padding: 10px 14px; border: 1.5px solid transparent; border-radius: var(--radius-sm); background: var(--bg); outline: none; }
.card .input, #modal .input { background: var(--bg); }
.input:focus { border-color: var(--accent); background: var(--surface); }
select.input { padding-right: 32px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237a6e64' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; }
textarea.input { min-height: 96px; resize: vertical; }
label.f { display: block; margin-bottom: 14px; } label.f > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.hint { color: var(--faint); font-size: 12.5px; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.6; }
.badge.active { background: var(--ok-bg); color: var(--ok); } .badge.waiting { background: var(--warn-bg); color: var(--warn); }
.badge.ended { background: var(--surface-2); color: var(--faint); } .badge.blocked { background: var(--danger-bg); color: var(--danger); }
.badge.tag { background: var(--accent-soft-2); color: var(--accent); margin-right: 4px; }
.badge.super { background: var(--purple-bg); color: var(--purple); } .badge.agent { background: #e0ecf8; color: #234d7a; }
.badge.pending { background: var(--warn-bg); color: var(--warn); } .badge.sending { background: #e0ecf8; color: #234d7a; }
.badge.done { background: var(--ok-bg); color: var(--ok); } .badge.cancelled { background: var(--surface-2); color: var(--faint); }
.badge.in { background: var(--surface-2); color: var(--muted); } .badge.out { background: var(--accent-soft-2); color: var(--accent); } .badge.note { background: var(--note-bg); color: var(--warn); } .badge.system { background: var(--purple-bg); color: var(--purple); }
.badge.ERROR, .badge.CRITICAL { background: var(--danger-bg); color: var(--danger); } .badge.WARNING { background: var(--warn-bg); color: var(--warn); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { font-size: 12.5px; color: var(--faint); font-weight: 600; background: transparent; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: var(--bg); }
.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .mono, .mono { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.tbl-wrap { overflow-x: auto; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px 14px; color: var(--faint); font-size: 13px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .input { width: auto; min-width: 220px; background: var(--surface); box-shadow: var(--shadow); }
.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 6px 14px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: 13.5px; cursor: pointer; }
.tabs a.active { background: var(--accent); color: #fff; }
.empty { color: var(--faint); text-align: center; padding: 34px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { width: 40px; height: 22px; margin: 0; appearance: none; background: var(--surface-3); border-radius: 11px; position: relative; cursor: pointer; transition: .15s; }
.switch input:checked { background: var(--ok); }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked::after { left: 21px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-600); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex-shrink: 0; }
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.avatar.av1 { background: #e0ecf8; color: #234d7a; } .avatar.av2 { background: #e8e3f6; color: #4b3a86; } .avatar.av3 { background: #dff2ea; color: #1f6b52; }
.avatar.av4 { background: #fbe3ea; color: #8a2d4b; } .avatar.av5 { background: #f1eae2; color: #7a6e64; }
.pill { display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 14px; border-radius: 999px; background: var(--ok-bg); color: var(--ok); font-size: 13.5px; font-weight: 600; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #2f9e4f; } .pill.off { background: var(--danger-bg); color: var(--danger); } .pill.off .dot { background: #c2415f; }
.pill .live { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); margin-left: 2px; opacity: .5; }
.pill .live.on { background: #2f9e4f; opacity: 1; box-shadow: 0 0 0 3px rgba(47, 158, 79, .2); animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 3px rgba(47, 158, 79, .2); } 50% { box-shadow: 0 0 0 6px rgba(47, 158, 79, .05); } }
.typing-tag { font-size: 11.5px; color: var(--accent); font-weight: 600; white-space: nowrap; }
.typing-bar { padding: 6px 18px; font-size: 13px; color: var(--accent); background: var(--accent-soft-2); border-bottom: 1px solid var(--line); }
.new-divider { align-self: stretch; text-align: center; font-size: 11.5px; color: var(--accent); font-weight: 600; margin: 4px 0; display: flex; align-items: center; gap: 10px; }
.new-divider::before, .new-divider::after { content: ""; flex: 1; border-top: 1px dashed var(--accent-soft); }
.jump-new { position: absolute; left: 50%; transform: translateX(-50%); bottom: 130px; box-shadow: var(--shadow-lg); z-index: 3; }
.inbox .thread { position: relative; }
.pre { white-space: pre-wrap; word-break: break-word; }
.media-thumb { max-width: 260px; max-height: 260px; border-radius: 12px; display: block; }
.dropzone { border: 2px dashed var(--line-2); border-radius: 14px; padding: 16px; text-align: center; color: var(--faint); cursor: pointer; }
.dropzone:hover { border-color: var(--accent); color: var(--accent); }
.chart-box { position: relative; height: 240px; }
.kb-phone { background: #17212b; border-radius: 14px; padding: 10px; margin-bottom: 12px; display: flex; flex-direction: column; gap: 6px; }
.kb-input { background: #242f3d; color: #7d8b99; border-radius: 8px; padding: 8px 12px; font-size: 13.5px; margin-bottom: 4px; }
.kb-row { display: flex; gap: 6px; }
.kb-btn { flex: 1; background: #2b3947; color: #fff; text-align: center; padding: 9px 8px; border-radius: 8px; font-size: 14px; font-weight: 600; }
.kb-btn.off { opacity: .35; text-decoration: line-through; }
.search { display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 14px; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); color: var(--faint); }
.search input { flex: 1; border: 0; background: transparent; outline: none; color: var(--text); min-width: 0; }

/* ── Inbox ──────────────────────────────── */
.inbox { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 16px; height: calc(100vh - 118px); }
.inbox .list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; padding: 12px; }
.inbox .list .filters { padding: 0 0 10px; }
.inbox .list .filters .tabs { margin: 0 0 10px; }
.inbox .list .filters .tabs a { padding: 5px 12px; font-size: 13px; }
.inbox .items { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.conv { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 14px; cursor: pointer; }
.conv:hover { background: var(--bg); } .conv.sel { background: var(--accent-soft-2); }
.conv .meta { flex: 1; min-width: 0; }
.conv .name { font-weight: 700; font-size: 15px; display: flex; gap: 8px; align-items: center; }
.conv .name .t { margin-left: auto; font-weight: 400; color: var(--faint); font-size: 12px; }
.conv .prev { color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .unread { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.inbox .thread { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
.thread .head { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.thread .head .info { flex: 1; min-width: 160px; line-height: 1.3; } .thread .head .info b { font-size: 17px; } .thread .head .info small { color: var(--faint); display: block; font-size: 13px; }
.thread .msgs { flex: 1; overflow-y: auto; padding: 20px 22px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 68%; padding: 10px 14px; border-radius: 18px; background: var(--surface-2); font-size: 15px; line-height: 1.5; }
.msg .who { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
.msg .time { font-size: 11.5px; color: var(--faint); text-align: right; margin-top: 3px; }
.msg .reacts:empty { display: none; }
.msg .reacts { display: flex; gap: 4px; margin-top: 4px; }
.msg .react { background: var(--surface); border: 1px solid var(--line-2); border-radius: 999px; padding: 0 7px; font-size: 13px; line-height: 20px; }
.msg.out .react { background: rgba(255, 255, 255, .22); border-color: transparent; }
.msg.in { align-self: flex-start; border-bottom-left-radius: 6px; }
.msg.out { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
.msg.out .who, .msg.out .time { color: rgba(255, 255, 255, .78); } .msg.out a { color: #fff; text-decoration: underline; }
.msg.note { align-self: center; background: var(--note-bg); border: 1px solid var(--note-line); border-radius: 14px; max-width: 80%; font-size: 13.5px; }
.msg.system { align-self: center; background: var(--surface-2); color: var(--faint); font-size: 12px; padding: 3px 12px; border-radius: 999px; }
.thread .compose { border-top: 1px solid var(--line); padding: 14px 18px; display: flex; flex-direction: column; gap: 10px; }
.thread .compose .quick { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.thread .compose .quick .chip { height: 30px; padding: 0 12px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 13px; font-weight: 600; border: 0; cursor: pointer; }
.thread .compose .quick .chip:hover { background: var(--surface-3); color: var(--text); }
.thread .compose .line { display: flex; gap: 10px; align-items: flex-end; }
.thread .compose textarea { flex: 1; min-height: 48px; max-height: 160px; padding: 12px 16px; border-radius: 14px; border: 0; background: var(--bg); outline: none; resize: none; font-size: 15px; }
.thread .compose textarea:focus { box-shadow: 0 0 0 2px var(--accent-soft); }
.thread .compose .send { width: 48px; height: 48px; border-radius: 14px; padding: 0; justify-content: center; }
.thread .compose .send svg.i { width: 20px; height: 20px; }
.thread .empty { margin: auto; }
.attach-preview { display: inline-flex; align-items: center; gap: 8px; background: var(--accent-soft-2); color: var(--accent-600); padding: 4px 12px; border-radius: 999px; font-size: 13px; }

/* ── Modal / toast ──────────────────────── */
#modal-bg { position: fixed; inset: 0; background: rgba(43, 37, 32, .45); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
#modal { background: var(--surface); border-radius: 22px; width: 100%; max-width: 660px; max-height: 92vh; overflow-y: auto; padding: 24px; box-shadow: var(--shadow-lg); }
#modal.wide { max-width: 920px; }
#modal h2 { margin-bottom: 16px; }
#modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
#toasts { position: fixed; right: 18px; bottom: 18px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: #fff; padding: 10px 16px; border-radius: 14px; box-shadow: var(--shadow-lg); font-size: 13.5px; animation: pop .15s ease-out; max-width: 380px; }
.toast.ok { background: var(--ok); } .toast.err { background: var(--danger); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Login ──────────────────────────────── */
#login { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; overflow: hidden; }
#login::before { content: ""; position: absolute; width: 640px; height: 640px; border-radius: 50%; background: radial-gradient(circle, rgba(196, 84, 27, .16), transparent 70%); top: -200px; right: -160px; }
#login form { position: relative; background: var(--surface); padding: 34px 32px; border-radius: 24px; width: 100%; max-width: 380px; box-shadow: var(--shadow-lg); }
#login .logo { width: 56px; height: 56px; border-radius: 18px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; box-shadow: 0 8px 20px rgba(196, 84, 27, .35); }
#login .logo svg.i { width: 28px; height: 28px; }
#login h1 { text-align: center; margin-bottom: 4px; }
#login .sub { text-align: center; color: var(--faint); font-size: 13.5px; margin-bottom: 22px; }
#login .err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; text-align: center; }

/* ── Responsive ─────────────────────────── */
@media (max-width: 1100px) { .grid.c4 { grid-template-columns: repeat(2, 1fr); } .grid.c3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 860px) {
  #sidebar { position: fixed; left: -270px; z-index: 40; transition: left .2s; height: 100vh; background: var(--bg); box-shadow: none; }
  #sidebar.open { left: 0; box-shadow: 0 0 0 100vw rgba(43, 37, 32, .4); }
  #menu-btn { display: inline-flex; }
  #topbar { padding: 16px 16px 4px; } #content { padding: 10px 16px 16px; } .pw-warn { margin: 12px 16px 0; }
  .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; }
  .inbox { grid-template-columns: 1fr; height: auto; }
  .inbox .list { max-height: 48vh; } .inbox .thread { min-height: 65vh; }
  .inbox.threaded .list { display: none; } .inbox:not(.threaded) .thread { display: none; }
  .msg { max-width: 88%; }
}
