/* Helpdesk WhatsApp — gaya dasar tanpa framework/build step. */
:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --text: #1f2933;
    --muted: #6b7785;
    --border: #dde2e8;
    --primary: #128c7e;
    --primary-text: #ffffff;
    --danger: #c62828;
    --warning-bg: #fff6e0;
    --warning-text: #7a5300;
    --error-bg: #fdecec;
    --error-text: #8a1c1c;
    --success-bg: #e6f6ee;
    --success-text: #135c37;
    --info-bg: #e8f1fd;
    --info-text: #1d4f91;
    --bubble-in: #ffffff;
    --bubble-out: #d9fdd3;
    --bubble-note: #fff4c2;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1419;
        --surface: #182028;
        --surface-2: #202a33;
        --text: #e6ebef;
        --muted: #93a1ad;
        --border: #2d3a45;
        --primary: #25a18e;
        --warning-bg: #3a2e10;
        --warning-text: #f3d48b;
        --error-bg: #3b1717;
        --error-text: #f4b4b4;
        --success-bg: #12301f;
        --success-text: #9fe0bb;
        --info-bg: #13263f;
        --info-text: #a9c9f5;
        --bubble-in: #202c33;
        --bubble-out: #005c4b;
        --bubble-note: #4a3f12;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--primary); }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; word-break: break-all; }
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pre { white-space: pre-wrap; }
.is-hidden { display: none !important; }
.inline { display: inline; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Topbar */
.topbar {
    display: flex; align-items: center; gap: 16px; padding: 8px 16px;
    background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); white-space: nowrap; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav__link { padding: 6px 10px; border-radius: 6px; text-decoration: none; color: var(--muted); }
.nav__link:hover, .nav__link.is-active { background: var(--surface-2); color: var(--text); }
.topbar__user { display: flex; gap: 8px; align-items: center; }

.main { padding: 16px; max-width: 1400px; margin: 0 auto; }
.main--full { max-width: none; padding: 0; height: calc(100vh - 53px); display: flex; flex-direction: column; }
.page { max-width: 1200px; margin: 0 auto; }

/* Komponen */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; overflow-x: auto; }
.card--narrow { max-width: 420px; margin: 8vh auto; }
.card--wide { max-width: 760px; margin: 4vh auto; }
.auth { padding: 16px; }
.grid-main { display: grid; grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr); gap: 16px; align-items: start; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 900px) {
    .grid-main, .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); cursor: pointer; font: inherit; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn--primary:hover { filter: brightness(1.08); background: var(--primary); }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--ghost { background: transparent; }
.btn--sm { padding: 4px 10px; font-size: 13px; }
.btn--block { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font: inherit; }
.link--danger { color: var(--danger); }

.alert { padding: 10px 14px; border-radius: 6px; margin: 0 0 12px; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.alert--success { background: var(--success-bg); color: var(--success-text); }
.alert--error { background: var(--error-bg); color: var(--error-text); }
.alert--warning { background: var(--warning-bg); color: var(--warning-text); }
.alert--info { background: var(--info-bg); color: var(--info-text); }
.main--full > .alert { margin: 8px 12px 0; }

.form { display: flex; flex-direction: column; gap: 12px; }
.form--compact { gap: 8px; }
.form--inline { flex-direction: row; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
.form label.check, label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; display: flex; flex-direction: column; gap: 12px; }
legend { font-weight: 600; padding: 0 6px; }
input, select, textarea {
    font: inherit; color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; width: 100%;
}
input[type="checkbox"], input[type="radio"] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
textarea { resize: vertical; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; }
.table--compact th, .table--compact td { padding: 5px 6px; }
.is-muted { opacity: 0.55; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge--resmi { background: var(--success-bg); color: var(--success-text); }
.badge--gratis { background: var(--warning-bg); color: var(--warning-text); }
.badge--danger { background: var(--error-bg); color: var(--error-text); }
.badge--warning { background: var(--warning-bg); color: var(--warning-text); }
.status--connected { color: var(--success-text); font-weight: 600; }
.status--disconnected, .status--needs_scan { color: var(--danger); font-weight: 600; }
.tag { display: inline-block; padding: 1px 8px; margin: 0 4px 4px 0; border-radius: 999px; background: var(--info-bg); color: var(--info-text); font-size: 11px; }
.qr { width: 260px; height: 260px; background: #fff; padding: 8px; border-radius: 8px; image-rendering: pixelated; }
.pairing { font-size: 28px; font-weight: 700; letter-spacing: 0.15em; }
.impact ul { padding-left: 18px; margin: 0; }
.impact li { margin-bottom: 6px; }
.sticky-actions { position: sticky; bottom: 0; padding: 12px 0; background: var(--bg); }

/* Inbox */
.inbox { display: grid; grid-template-columns: 320px minmax(0, 1fr) 300px; flex: 1; min-height: 0; }
.inbox__list, .inbox__side { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.inbox__side { border-right: 0; border-left: 1px solid var(--border); overflow-y: auto; padding: 12px; }
.inbox__chat { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
@media (max-width: 1100px) {
    .inbox { grid-template-columns: 280px minmax(0, 1fr); }
    .inbox__side { display: none; }
}
@media (max-width: 720px) {
    .main--full { height: auto; min-height: calc(100vh - 53px); }
    .inbox { grid-template-columns: 1fr; }
    .inbox__list { max-height: 45vh; }
}
.presence { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.presence label { white-space: nowrap; color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 2px; padding: 8px; flex-wrap: wrap; }
.tab { flex: 1; border: 0; background: transparent; padding: 6px 4px; border-radius: 6px; color: var(--muted); cursor: pointer; font: inherit; font-size: 12px; }
.tab.is-active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.search { margin: 0 8px 8px; width: calc(100% - 16px); }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv { padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.conv:hover { background: var(--surface-2); }
.conv.is-active { background: var(--info-bg); }
.conv__top { display: flex; justify-content: space-between; gap: 8px; }
.conv__name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv__time { color: var(--muted); font-size: 11px; white-space: nowrap; }
.conv__preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv__meta { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; align-items: center; }
.unread { background: var(--primary); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 11px; font-weight: 700; }
.priority--high, .priority--urgent { background: var(--error-bg); color: var(--error-text); }
.conv-empty { padding: 20px; text-align: center; color: var(--muted); }

.empty { margin: auto; color: var(--muted); }
.chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat__header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.chat__actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.chat__actions select { width: auto; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
#load-older { align-self: center; }
.msg { max-width: 72%; padding: 6px 10px 4px; border-radius: 8px; box-shadow: var(--shadow); white-space: pre-wrap; word-wrap: break-word; }
.msg--in { align-self: flex-start; background: var(--bubble-in); }
.msg--out { align-self: flex-end; background: var(--bubble-out); }
.msg--note { align-self: center; background: var(--bubble-note); max-width: 85%; }
.msg--system { align-self: center; background: transparent; box-shadow: none; color: var(--muted); font-size: 12px; text-align: center; }
.msg__meta { display: flex; justify-content: flex-end; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 2px; }
.msg__author { font-size: 11px; font-weight: 600; color: var(--muted); }
.msg__media img, .msg__media video { max-width: 260px; max-height: 260px; border-radius: 6px; display: block; }
.msg__media audio { max-width: 260px; }
.msg__error { color: var(--danger); font-size: 12px; }
.msg__options { margin: 4px 0 0; padding-left: 18px; font-size: 12px; }
.tick--read { color: #34b7f1; }
.tick--failed { color: var(--danger); }

.composer { background: var(--surface); border-top: 1px solid var(--border); padding: 8px 12px; position: relative; }
.composer__notice { padding: 6px 10px; margin-bottom: 6px; border-radius: 6px; background: var(--warning-bg); color: var(--warning-text); font-size: 13px; }
.composer__modes { display: flex; gap: 16px; align-items: center; margin-bottom: 6px; font-size: 13px; flex-wrap: wrap; }
.composer__form { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }
.composer__buttons { display: flex; gap: 6px; }
.composer--note textarea { background: var(--bubble-note); }
.suggestions { list-style: none; margin: 0 0 6px; padding: 0; border: 1px solid var(--border); border-radius: 6px; max-height: 180px; overflow-y: auto; background: var(--surface); }
.suggestions li { padding: 6px 10px; cursor: pointer; }
.suggestions li.is-active, .suggestions li:hover { background: var(--surface-2); }
.template-panel { display: flex; flex-direction: column; gap: 6px; padding: 8px; margin-bottom: 6px; border: 1px dashed var(--border); border-radius: 6px; }

.side__block { margin-bottom: 18px; }
.side__block h3 { margin-top: 0; }
.history { list-style: none; padding: 0; margin: 0; font-size: 12px; }
.history li { padding: 6px 0; border-bottom: 1px solid var(--border); }

.dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); width: min(440px, 92vw); padding: 16px; }
.dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.dialog__buttons { display: flex; justify-content: flex-end; gap: 8px; }
