:root {
  --primary: #287da7;
  --primary-hover: #206b92;
  --primary-ink: #236c91;
  --on-primary: #ffffff;
  --primary-soft: #eaf3f8;
  --text: #202428;
  --secondary: #5f6b73;
  --secondary-strong: #5f6b73;
  --border: #e9ebed;
  --control-border: #85929a;
  --hover: #f1f1f1;
  --font: 'Segoe UI', Roboto, Arial, sans-serif;
  --wallpaper: #ceddb4;
  --bubble: #efffdf;
}
html[data-theme='dark'] {
  color-scheme: dark;
  --app-bg: #17212b;
  --sidebar-bg: #17212b;
  --content-bg: #17212b;
  --secondary-bg: #232e3c;
  --primary: #64b5ef;
  --primary-hover: #7fc5f6;
  --primary-ink: #79c4f8;
  --on-primary: #122330;
  --primary-soft: #253d50;
  --text: #edf3f7;
  --secondary: #97a8b6;
  --secondary-strong: #b0bcc7;
  --border: #283544;
  --control-border: #627889;
  --hover: #243342;
  --wallpaper: #172c32;
  --bubble: #294a42;
  --warn-bg: #493c28;
  --warn-text: #f2c880;
  --ok-bg: #284338;
  --ok-text: #9ddbb0;
  --danger-soft: #482d36;
  --danger: #f38b8b;
}
body { font-size: 15px; line-height: 1.45; }
a, .link-btn, .export-btn { color: var(--primary-ink); }
.conversation-list { flex: 0 0 340px; width: 340px; min-width: 0; background: var(--sidebar-bg); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.list-head { height: 66px; flex-shrink: 0; padding: 11px 13px; display: flex; align-items: center; gap: 10px; }
.account-menu { width: 40px; height: 40px; }
.list-head input[type='search'] { width: 100%; height: 44px; min-width: 0; border: 0; border-radius: 24px; background: var(--secondary-bg); padding: 0 17px; font-size: 15px; }
.conversation-items { flex: 1; overflow-y: auto; }
.conversation-item { width: 100%; padding: 13px 12px; display: flex; align-items: center; gap: 12px; border: 0; background: transparent; text-align: left; color: var(--text); cursor: pointer; }
.conversation-item:hover { background: var(--hover); }
.conversation-item[hidden], .conversation-item[data-search-hidden] { display: none; }
.mobile-nav-label { display: none; }
.conversation-item.is-active { background: var(--primary); color: white; }
.conversation-item .avatar { width: 54px; height: 54px; background: #3986b0; }
.conversation-item[data-view='grup'] .avatar, .conversation-item[data-view='autoreply'] .avatar { background: #478653; }
.conversation-item[data-view='kelola'] .avatar, .conversation-item[data-view='autoreply-log'] .avatar { background: #7162b0; }
.conversation-item .avatar svg { width: 27px; height: 27px; }
.conversation-copy { display: flex; flex: 1; min-width: 0; flex-direction: column; gap: 5px; }
.conversation-copy .nav-label { font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-copy small { color: var(--secondary-strong); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-item.is-active small { color: var(--on-primary); }
.conversation-item.is-active .nav-badge { background: var(--app-bg); color: var(--primary-ink); }
.list-footer { padding: 14px 16px; color: var(--secondary); font-size: 13px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }
.connection-status { color: var(--text); }
.connection-notice { flex-shrink: 0; margin: 0; padding: 10px 16px; font-size: 14px; color: var(--warn-text); background: var(--warn-bg); }
.connection-notice[hidden] { display: none; }
.list-empty { padding: 24px 16px; color: var(--secondary); }
.drawer-backdrop { position: fixed; inset: 0; z-index: 40; background: #0008; border: 0; cursor: default; }
.drawer-backdrop[hidden] { display: none; }
.sidebar { position: fixed; top: 0; left: 0; z-index: 41; width: 342px; min-width: 0; max-width: calc(100vw - 36px); height: 100dvh; border: 0; visibility: hidden; transform: translateX(-100%); transition: transform 180ms ease, visibility 180ms; box-shadow: 3px 0 12px #0002; overflow-y: auto; }
body.drawer-open .sidebar { visibility: visible; transform: translateX(0); }
.profile-block { position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 18px; padding: 25px 32px 18px; min-height: 168px; }
.profile-avatar.avatar { width: 60px; height: 60px; font-size: 25px; background: #39a5cf; }
.profile-text { width: calc(100% - 24px); }
.profile-name { font-size: 16px; font-weight: 600; }
.profile-status-link { font-size: 15px; margin-top: 2px; }
.profile-chevron { position: absolute; right: 20px; bottom: 19px; }
.drawer-close { position: absolute; top: 12px; right: 14px; }
.account-panel { padding: 8px 32px 12px; }
.conversation-list .nav { padding: 0; gap: 0; border: 0; }
.conversation-list .nav-item { border-radius: 0; }
.conversation-list .nav-item svg { color: #ffffff; }
.conversation-list .nav-item.is-active .nav-label { color: var(--on-primary); }
.drawer-setting { display: flex; align-items: center; width: 100%; gap: 23px; padding: 12px 29px; min-height: 49px; font-size: 16px; color: var(--text); background: transparent; border: 0; text-decoration: none; cursor: pointer; }
.drawer-setting:hover { background: var(--hover); color: var(--text); }
.drawer-setting svg { width: 24px; height: 24px; color: var(--secondary-strong); flex-shrink: 0; }
.night-switch { margin-left: auto; width: 37px; height: 20px; border-radius: 12px; background: #a0a3a5; padding: 3px; }
.night-switch::after { content: ''; display: block; width: 14px; height: 14px; background: white; border-radius: 50%; transition: transform 150ms; }
[aria-checked='true'] .night-switch { background: var(--primary); }
[aria-checked='true'] .night-switch::after { transform: translateX(17px); }
.sidebar-foot { margin-top: auto; padding: 8px 8px 12px; }
.app-name { font-size: 14px; padding: 8px 12px 0; }
.app-version { font-size: 13px; padding: 2px 12px 0; }
.main { background-color: var(--wallpaper); background-image: url('/assets/chat-pattern.svg'), linear-gradient(120deg, #98c5b366, #e6e8a277 60%, #a5cc9777); }
html[data-theme='dark'] .main { background-image: url('/assets/chat-pattern.svg'); }
html[data-theme='dark'] .conversation-item.is-active, html[data-theme='dark'] .conversation-item.is-active small { color: #122330; }
.view-body, .conversation-items, .sidebar { scrollbar-width: thin; scrollbar-color: #87929955 transparent; }
.view-header { min-height: 66px; padding: 10px 21px; gap: 12px; }
.view-header > .avatar { display: none; }
.header-text h1 { width: fit-content; max-width: 100%; font-size: 17px; font-weight: 600; }
.header-text p { font-size: 13px; }
.view-body { padding: 22px clamp(16px, 3vw, 48px) 32px; }
.view-body > .toolbar, .summary-filter { background: var(--content-bg); padding: 14px 16px; margin-bottom: 16px; border-radius: 8px; box-shadow: 0 1px 2px #0001; }
.toolbar label { color: var(--secondary-strong); }
input[type='text'], input[type='search'], input[type='password'], input[type='date'], input[type='number'], select { height: 40px; border-radius: 6px; border-color: var(--control-border); }
.stat-overview { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }
.stat-overview > .stat-card { flex-direction: row; justify-content: space-between; align-items: center; padding: 12px 18px; background: var(--content-bg); border-radius: 8px; }
.stat-section { position: relative; padding: 16px 18px; border-radius: 8px; background: var(--content-bg); }
.stat-section h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; color: var(--primary-ink); text-transform: capitalize; }
/* Kolom tetap 4 sama lebar di semua section: baris isi 3 membiarkan sel
   keempat kosong sehingga tepi kiri kolom 1-3 sejajar antar section. */
.stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; background: transparent; border: 0; border-radius: 0; overflow: visible; margin-bottom: 0; }
.stat-card { position: relative; border-radius: 0; padding: 0; box-shadow: none; background: transparent; }
.stat-card.accent-grup, .stat-card.accent-inisial { background: transparent; }
.stat-overview > .stat-card { position: relative; }
.stat-tip { top: 34px; left: 0; right: auto; width: min(320px, calc(100vw - 120px)); max-width: none; }
.stat-grid .stat-card:last-child .stat-tip { left: auto; right: 0; }
@media (max-width: 1100px) {
  .stat-grid .stat-card:nth-child(even) .stat-tip { left: auto; right: 0; }
}
.stat-label { color: var(--secondary-strong); font-size: 14px; }
/* Kunci label setinggi 2 baris agar angka selalu mulai sejajar meski
   panjang label beda-beda. */
.stat-section .stat-label { align-items: flex-start; line-height: 1.45; min-height: 2.9em; }
.stat-value { font-size: 28px; font-weight: 500; margin-top: 5px; }
.stat-overview > .stat-card .stat-value { font-size: 20px; margin-top: 0; }
.kelola-block { padding: 18px; background: var(--content-bg); border-radius: 9px; box-shadow: 0 1px 2px #0001; }
.table-wrap { background: var(--content-bg); border-radius: 8px; }
.data-table thead th { background: var(--secondary-bg); color: var(--secondary-strong); font-weight: 500; }
.data-table td { padding-top: 14px; padding-bottom: 14px; }
.pager { background: var(--content-bg); padding: 10px 12px; border-radius: 0 0 8px 8px; }
.data-card { container-type: inline-size; min-width: 0; background: var(--content-bg); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.data-card > .table-wrap { border: 0; border-radius: 0; }
/* Kartu di dalam kartu (rinci grup, blok kelola) tidak memakai bingkai
   sendiri; bingkai panel luar yang berlaku agar tidak ada garis ganda. */
.kelola-block .data-card, .detail-panel .data-card { border: 0; border-radius: 0; }
.data-card .data-table th, .data-card .data-table td { padding-left: 16px; padding-right: 16px; }
.data-card .empty-row td { height: 120px; padding: 32px 16px; vertical-align: middle; }
.data-card .empty-row:hover td { background: var(--content-bg); }
.data-card > .pager { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 12px; margin: 0; padding: 12px 16px; border-top: 1px solid var(--border); border-radius: 0; }
.data-card > .pager:empty { display: none; }
.data-card .pager-nav { justify-content: center; gap: 6px; white-space: nowrap; }
.data-card .pager select { justify-self: end; width: auto; min-height: 36px; }
.data-card .pager .link-btn:disabled { color: var(--secondary); opacity: .65; }
@container (max-width: 660px) {
  .data-card .data-table:has(tbody > .empty-row:only-child) { min-width: 0; }
  .data-card .data-table:has(tbody > .empty-row:only-child) thead { display: none; }
  .data-card .empty-row td { overflow-wrap: anywhere; }
  .data-card > .pager { grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 12px; }
  .data-card .pager-info { grid-column: 1; grid-row: 1; }
  .data-card .pager select { grid-column: 2; grid-row: 1; min-height: 40px; }
  .data-card .pager-nav { grid-column: 1 / -1; grid-row: 2; justify-content: space-between; }
  .data-card .pager-nav .link-btn { min-height: 40px; }
}
@container (max-width: 320px) {
  .data-card > .pager { grid-template-columns: minmax(0, 1fr); }
  .data-card .pager-info { grid-column: 1; grid-row: 1; }
  .data-card .pager select { grid-column: 1; grid-row: 2; justify-self: start; }
  .data-card .pager-nav { grid-column: 1; grid-row: 3; gap: 2px; font-size: 12px; }
  .data-card .pager-nav .link-btn { padding: 4px; font-size: 12px; }
}
.export-btn { background: transparent; border: 0; font-weight: 500; }
.primary-btn, .summary-btn { height: 40px; }
.view-body > .form-note, .view-body > .master-switch, .view-body > .master-note { background: var(--content-bg); padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; }
/* Halaman login / setup / keamanan: kartu di atas wallpaper yang sama dengan area chat. */
.login-body { background-color: var(--wallpaper); background-image: url('/assets/chat-pattern.svg'), linear-gradient(120deg, #98c5b366, #e6e8a277 60%, #a5cc9777); padding: 32px 20px; }
html[data-theme='dark'] .login-body { background-image: url('/assets/chat-pattern.svg'); }
.login-wrap { max-width: 420px; margin: auto; }
.security-wrap { max-width: 460px; }
.login-card { padding: 32px 32px 28px; border: 0; border-radius: 16px; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 12px 32px rgba(16, 35, 47, 0.16); }
.login-brand { flex-direction: column; gap: 14px; padding-bottom: 6px; }
.login-brand .avatar { width: 84px; height: 84px; font-size: 34px; background: #339bd0; }
.login-brand .avatar svg { width: 66px; height: 66px; margin-left: -4px; }
.login-brand .brand-name { font-size: 24px; font-weight: 600; }
.login-sub { text-align: center; font-size: 15px; margin: 0 0 18px; color: var(--secondary-strong); }
.login-card input { height: 48px; border-radius: 9px; font-size: 16px; }
.login-card label { font-weight: 500; margin-top: 12px; color: var(--secondary-strong); }
.login-card button[type='submit'] { margin-top: 20px; height: 48px; border-radius: 9px; font-size: 16px; font-weight: 600; }
.login-error { min-height: 0; margin: 14px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--danger-soft); font-size: 14px; }
.login-error:empty { display: none; }
.login-error.is-info { background: var(--primary-soft); color: var(--primary-ink); }
.primary-btn, .summary-btn, .login-card button[type='submit'], .inline-form button[type='submit'], .toggle-btn.is-on, .segmented input:checked + span, .nav-badge, .export-btn:hover:not(:disabled), .open-tg-btn:hover { color: var(--on-primary); }
.conversation-item:focus-visible { outline: 2px solid var(--text); outline-offset: -3px; }
.stat-info { flex-shrink: 0; color: var(--secondary-strong); border-color: var(--secondary-strong); }
.stat-info.is-tip-dismissed + .stat-tip { display: none; }
@media (max-width: 1200px) {
  .conversation-list { width: 300px; flex-basis: 300px; }
  .view-body { padding: 16px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .conversation-list { flex: 0 0 80px; width: 80px; background: #293b4b; border: 0; color: #a8b8c5; }
  .conversation-list .list-head { height: 66px; padding: 0; justify-content: center; }
  .conversation-list .account-menu { color: #a8b8c5; }
  .conversation-list .account-menu:hover { background: #1d2c3a; }
  .conversation-list .list-head input, .conversation-list .list-footer, .conversation-list .list-empty, .conversation-copy { display: none; }
  .conversation-items { min-height: 0; }
  .conversation-list .nav-item { position: relative; flex-direction: column; justify-content: center; min-height: 88px; padding: 14px 4px; gap: 9px; color: #a8b8c5; }
  .conversation-list .nav-item:hover { background: #243544; }
  html .conversation-list .nav-item.is-active { background: #1d2c3a; color: #65b9ef; }
  .conversation-list .conversation-item .avatar { width: 30px; height: 30px; background: transparent; color: inherit; }
  .conversation-list .nav-item svg { width: 30px; height: 30px; color: inherit; }
  .mobile-nav-label { display: block; font-size: 12px; line-height: 1.3; text-align: center; }
  .conversation-list .nav-badge { position: absolute; top: 8px; right: 10px; min-width: 20px; background: #287da7; color: #fff; }
  .conversation-list .nav-item:focus-visible, .conversation-list .account-menu:focus-visible { outline: 2px solid #b2ddff; outline-offset: -3px; }
  .main { display: flex; width: auto; }
  .back-btn { display: none; }
  .sidebar { width: 342px; }
  .view-header { padding: 8px; gap: 4px; }
  .header-text h1 { font-size: 16px; }
  .header-actions { gap: 0; }
  .header-actions .export-btn { font-size: 12px; padding: 0 6px; }
  .view-body { padding: 12px; }
  .stat-section { padding: 14px; }
  .stat-grid { grid-template-columns: 1fr; gap: 0; }
  .stat-section .stat-card { display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 18px; padding: 10px 0; border-bottom: 1px solid var(--border); }
  .stat-section .stat-card:last-child { border-bottom: 0; }
  .stat-value { font-size: 23px; margin-top: 0; }
  .stat-label { font-size: 14px; }
  .stat-info { width: 28px; height: 28px; }
  .stat-info { position: relative; }
  .stat-info::before { content: ''; position: absolute; inset: -8px; }
  .kelola-block-head { flex-wrap: wrap; }
  .kelola-block { padding: 12px; }
  .toolbar > input, .toolbar > select { max-width: 100%; min-width: 0; }
  .login-body { padding: 20px 16px; }
  .login-card { padding: 24px 20px 22px; }
  .login-brand .avatar { width: 72px; height: 72px; }
  .login-brand .avatar svg { width: 56px; height: 56px; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, .night-switch::after { transition: none; }
}

/* ---------- Revisi jawaban & tambah knowledge (dialog) ---------- */
.log-actions { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; }
.log-actions .link-btn { padding: 0; font-size: 13px; }
.rev-dialog { width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: var(--radius-modal, 12px); background: var(--app-bg); color: var(--text); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18); }
.rev-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.rev-dialog[open] { display: flex; flex-direction: column; }
.rev-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 16px 8px; border-bottom: 1px solid var(--border); }
.rev-head h2 { margin: 0; font-size: 18px; }
.rev-body { padding: 12px 16px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.rev-body > * { flex-shrink: 0; }
.rev-chat { max-height: 42vh; min-height: 160px; overflow-y: auto; padding: 10px; border-radius: var(--radius-md); background-color: var(--wallpaper); background-image: url('/assets/chat-pattern.svg'); display: flex; flex-direction: column; gap: 6px; }
.rev-more { align-self: center; background: var(--app-bg); border-radius: 14px; padding: 4px 12px; }
.rev-row { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; margin: 3px 0; }
.rev-row.is-out { flex-direction: row-reverse; }
.rev-row input { margin-top: 10px; flex-shrink: 0; }
.rev-bubble { max-width: min(78%, 520px); padding: 6px 10px 4px; border-radius: 12px; background: var(--app-bg); box-shadow: 0 1px 1px rgba(0, 0, 0, 0.12); display: flex; flex-direction: column; gap: 2px; }
.rev-row.is-out .rev-bubble { background: var(--bubble); }
.rev-row.is-target .rev-bubble { outline: 2px solid var(--warn-text, #c98a1b); outline-offset: 1px; }
.rev-row:has(input:checked) .rev-bubble { box-shadow: 0 0 0 2px var(--primary); }
.rev-sender { font-size: 12px; font-weight: 600; color: var(--primary-ink); }
.rev-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.rev-time { align-self: flex-end; font-size: 11px; color: var(--secondary); }
.rev-tabs { display: flex; gap: 4px; padding: 3px; border-radius: 10px; background: var(--secondary-bg); align-self: flex-start; flex-wrap: wrap; }
.rev-tabs button { border: 0; background: transparent; color: var(--secondary-strong); padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.rev-tabs button[aria-selected='true'] { background: var(--app-bg); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.rev-form { display: flex; flex-direction: column; gap: 6px; }
.rev-form[hidden], .rev-body[hidden], [data-kn-pane][hidden] { display: none; }
.rev-form label { font-size: 14px; font-weight: 600; }
.rev-dialog textarea { width: 100%; box-sizing: border-box; font-size: 14px; color: var(--text); background: var(--app-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; resize: vertical; }
.rev-dialog select { width: 100%; }
.rev-qa { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 8px 12px 12px; margin: 0 0 8px; display: flex; flex-direction: column; gap: 4px; }
.rev-qa legend { font-weight: 600; padding: 0 4px; }
.rev-qa legend .link-btn { margin-left: 8px; font-weight: 400; }
.rev-notice { margin: 0; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--ok-bg); color: var(--ok-text); font-size: 14px; }
.rev-knowledge-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rev-knowledge-list li { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 8px 12px; }
.rev-knowledge-list small { color: var(--secondary); }
.rev-knowledge-list p { margin: 2px 0 6px; white-space: pre-wrap; overflow-wrap: anywhere; }
.img-attach { display: flex; flex-direction: column; gap: 4px; }
.img-attach-label { font-size: 14px; font-weight: 600; }
.img-attach .form-note, .img-attach .form-error { margin: 0; }
.img-attach-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.img-attach-grid figure { position: relative; width: 84px; height: 84px; margin: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--secondary-bg); }
.img-attach-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-attach-remove { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 16px; line-height: 22px; cursor: pointer; }
.img-attach-add { width: 84px; height: 84px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; border: 1px dashed var(--border); border-radius: var(--radius-sm); background: none; color: var(--secondary); font: inherit; font-size: 11px; cursor: pointer; }
.img-attach-add:hover:not(:disabled) { color: var(--primary); border-color: var(--primary); }
.rev-photo { font-size: 11px; color: var(--primary-ink); }
@media (max-width: 600px) {
  .rev-dialog { width: calc(100vw - 16px); max-height: calc(100vh - 16px); }
  .rev-bubble { max-width: 85%; }
}
