/* ============================================================
   WABA CRM — Components
   App shell (sidebar + area kerja), WindowIndicator (elemen signature),
   layar auth, banner koneksi, toast. Struktur inbox 3-panel menyusul
   di modul Inbox (inbox.css) supaya core tetap ramping.
   ============================================================ */

/* ============================================================
   APP SHELL
   ============================================================ */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    height: 100vh;
    height: 100dvh; /* viewport dinamis: menyesuaikan saat keyboard mobile muncul */
    overflow: hidden;
}

/* ---- Sidebar (rail navigasi kiri) ---- */
.rail {
    background: var(--c-surface);
    border-right: 1px solid var(--c-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--sp-4) 0;
    gap: var(--sp-2);
}
.rail__brand {
    width: 40px; height: 40px;
    border-radius: var(--r-md);
    background: var(--c-signal);
    color: var(--c-ink-inv);
    display: grid; place-items: center;
    font-weight: var(--fw-bold);
    font-size: var(--fs-md);
    margin-bottom: var(--sp-4);
    box-shadow: var(--sh-sm);
}
.rail__nav { display: flex; flex-direction: column; gap: var(--sp-1); flex: 1; width: 100%; align-items: center; }
.rail__item {
    position: relative;
    width: 44px; height: 44px;
    border-radius: var(--r-md);
    display: grid; place-items: center;
    color: var(--c-ink-mute);
    transition: background var(--t-fast), color var(--t-fast);
    cursor: pointer;
}
.rail__item:hover { background: var(--c-surface-2); color: var(--c-ink-soft); }
.rail__item.is-active { background: var(--c-signal-soft); color: var(--c-signal-700); }
.rail__item.is-active::before {
    content: ""; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
    width: 3px; height: 22px; border-radius: var(--r-pill); background: var(--c-signal);
}
.rail__item .badge-count {
    position: absolute; top: 4px; right: 4px;
    min-width: 16px; height: 16px; padding: 0 4px;
    background: var(--c-danger); color: #fff;
    border-radius: var(--r-pill);
    font-size: 10px; font-weight: var(--fw-bold);
    display: grid; place-items: center;
    font-family: var(--font-mono);
}

/* Tooltip label rail */
.rail__item[data-label]:hover::after {
    content: attr(data-label);
    position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%);
    background: var(--c-tooltip-bg); color: var(--c-tooltip-ink);
    padding: 4px 9px; border-radius: var(--r-sm);
    font-size: var(--fs-xs); white-space: nowrap;
    box-shadow: var(--sh-md); z-index: var(--z-dropdown);
    pointer-events: none;
}

.rail__foot { margin-top: auto; display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); }

/* ---- Area kerja ---- */
.workspace { overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.workspace__header {
    height: var(--header-h);
    border-bottom: 1px solid var(--c-border);
    background: var(--c-surface);
    display: flex; align-items: center;
    padding: 0 var(--sp-5);
    gap: var(--sp-4);
    flex-shrink: 0;
}
.workspace__title { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.workspace__body { flex: 1; overflow: auto; }

/* ============================================================
   WINDOW INDICATOR — elemen signature
   Bar "fuse" countdown jendela 24 jam WhatsApp.
   Warna berubah jade → amber → rose seiring sisa waktu menipis.
   Struktur HTML dibuat oleh JS (window-indicator.js).
   ============================================================ */
.window-indicator {
    --wi-pct: 100%;
    --wi-color: var(--c-window-open);
    display: inline-flex;
    flex-direction: column;
    gap: 3px;
    min-width: 116px;
}
.window-indicator__head {
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--sp-2);
}
.window-indicator__label {
    font-size: 10px; letter-spacing: .06em; text-transform: uppercase;
    color: var(--c-ink-mute); font-weight: var(--fw-medium);
}
.window-indicator__time {
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    color: var(--wi-color);
    font-feature-settings: "tnum";
}
/* Track + fuse */
.window-indicator__track {
    position: relative;
    height: 5px;
    border-radius: var(--r-pill);
    background: var(--c-surface-3);
    overflow: hidden;
}
.window-indicator__fuse {
    position: absolute; inset: 0 auto 0 0;
    width: var(--wi-pct);
    background: var(--wi-color);
    border-radius: var(--r-pill);
    transition: width 1s linear, background var(--t-base);
}
/* Denyut halus saat mendekati tutup */
.window-indicator.is-warn  { --wi-color: var(--c-window-warn); }
.window-indicator.is-close { --wi-color: var(--c-window-close); }
.window-indicator.is-close .window-indicator__fuse { animation: wi-pulse 1.4s ease-in-out infinite; }
.window-indicator.is-closed {
    --wi-color: var(--c-ink-mute);
    --wi-pct: 0%;
}
.window-indicator.is-closed .window-indicator__time { color: var(--c-ink-mute); }

@keyframes wi-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: .55; }
}

/* Varian ringkas (chip) untuk dipakai di list */
.window-pill {
    display: inline-flex; align-items: center; gap: 5px;
    font-family: var(--font-mono); font-size: 11px; font-weight: var(--fw-medium);
    padding: 1px 7px; border-radius: var(--r-pill);
    background: var(--c-signal-soft); color: var(--c-signal-700);
}
.window-pill.is-warn   { background: var(--c-window-amber-soft); color: var(--c-window-warn); }
.window-pill.is-close  { background: var(--c-window-rose-soft); color: var(--c-danger); }
.window-pill.is-closed { background: var(--c-surface-3); color: var(--c-ink-mute); }

/* ============================================================
   CONNECTION BANNER (WABA belum dikonfigurasi)
   ============================================================ */
.connection-banner {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-5);
    background: var(--c-window-amber-soft);
    border-bottom: 1px solid var(--c-window-warn);
    color: var(--c-window-warn);
    font-size: var(--fs-sm);
}
.connection-banner strong { font-weight: var(--fw-semibold); }
.connection-banner .btn { margin-left: auto; }

/* ============================================================
   AUTH SCREEN
   ============================================================ */
.auth {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr;
    place-items: center;
    padding: var(--sp-6);
    background:
        radial-gradient(1200px 600px at 100% -10%, var(--c-signal-soft), transparent 60%),
        var(--c-bg);
}
.auth__card {
    width: 100%;
    max-width: 400px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--r-xl);
    box-shadow: var(--sh-lg);
    padding: var(--sp-8);
}
.auth__brand {
    display: flex; align-items: center; gap: var(--sp-3);
    margin-bottom: var(--sp-6);
}
.auth__logo {
    width: 44px; height: 44px; border-radius: var(--r-md);
    background: var(--c-signal); color: var(--c-ink-inv);
    display: grid; place-items: center; font-weight: var(--fw-bold); font-size: var(--fs-lg);
    box-shadow: var(--sh-sm);
}
.auth__brand-name { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.auth__brand-sub  { font-size: var(--fs-xs); color: var(--c-ink-mute); }
.auth__title { font-size: var(--fs-lg); margin-bottom: var(--sp-1); }
.auth__subtitle { color: var(--c-ink-mute); font-size: var(--fs-sm); margin-bottom: var(--sp-6); }
.auth__field { margin-bottom: var(--sp-4); }
.auth__error {
    background: var(--c-danger-soft); color: var(--c-danger);
    padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md);
    font-size: var(--fs-sm); margin-bottom: var(--sp-5);
    display: flex; align-items: center; gap: var(--sp-2);
}
.auth__submit { width: 100%; padding: 0.65rem; font-size: var(--fs-base); }
.auth__foot { margin-top: var(--sp-6); text-align: center; font-size: var(--fs-xs); color: var(--c-ink-mute); }

/* Input dengan ikon */
.field-icon { position: relative; }
.field-icon svg {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    color: var(--c-ink-mute); pointer-events: none;
}
.field-icon .form-control { padding-left: 40px; }
.field-icon__toggle {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: var(--c-ink-mute);
    cursor: pointer; padding: 6px; border-radius: var(--r-sm);
    display: grid; place-items: center;
}
.field-icon__toggle:hover { color: var(--c-ink-soft); background: var(--c-surface-2); }

/* ============================================================
   USER MENU (di rail bawah)
   ============================================================ */
.user-menu { position: relative; }
.user-menu__trigger { border: none; background: none; padding: 0; cursor: pointer; border-radius: 50%; }
.user-menu__trigger:focus-visible { box-shadow: var(--sh-focus); outline: none; }
.user-menu__pop {
    position: absolute; bottom: 0; left: calc(100% + 10px);
    width: 240px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-lg);
    padding: var(--sp-2);
    z-index: var(--z-dropdown);
    opacity: 0; visibility: hidden; transform: translateY(6px);
    transition: opacity var(--t-fast), transform var(--t-fast), visibility var(--t-fast);
}
.user-menu.is-open .user-menu__pop { opacity: 1; visibility: visible; transform: translateY(0); }
.user-menu__head { padding: var(--sp-3); border-bottom: 1px solid var(--c-border); margin-bottom: var(--sp-2); }
.user-menu__name { font-weight: var(--fw-semibold); font-size: var(--fs-sm); }
.user-menu__email { font-size: var(--fs-xs); color: var(--c-ink-mute); }
.user-menu__role { margin-top: var(--sp-2); }
.menu-item {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm);
    color: var(--c-ink-soft); font-size: var(--fs-sm); width: 100%;
    background: none; border: none; cursor: pointer; text-align: left;
}
.menu-item:hover { background: var(--c-surface-2); color: var(--c-ink); }
.menu-item--danger { color: var(--c-danger); }
.menu-item--danger:hover { background: var(--c-danger-soft); color: var(--c-danger); }

/* Toggle tema: tampil ikon+label sesuai tema aktif. Di mode TERANG tampil
   bulan + "Mode gelap" (aksi → ke gelap); di mode GELAP tampil matahari +
   "Mode terang". Semua via CSS, JS cuma membalik data-theme. */
.theme-toggle { align-items: center; }
.theme-toggle__sun, .theme-toggle__light-label { display: none; }
[data-theme="dark"] .theme-toggle__moon,
[data-theme="dark"] .theme-toggle__dark-label { display: none; }
[data-theme="dark"] .theme-toggle__sun { display: inline-block; }
[data-theme="dark"] .theme-toggle__light-label { display: inline; }

/* ============================================================
   TOAST (notyf di-styling agar cocok token)
   ============================================================ */
.notyf__toast { border-radius: var(--r-md) !important; box-shadow: var(--sh-lg) !important; }
.notyf__toast--success .notyf__ripple { background: var(--c-signal) !important; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 720px) {
    /* Sisakan ruang aman di ATAS untuk status bar OS (notch / mode edge-to-edge
       di PWA/webview). Tanpa ini, konten paling atas — termasuk header thread
       Inbox — bisa tertutup/tersembunyi di balik status bar (bug "header kadang
       tak terlihat"). box-sizing:border-box global menjaga total tetap 100dvh.
       Di browser biasa env()-nya 0, jadi tak ada efek samping. */
    .app-shell { grid-template-columns: 1fr; padding-top: env(safe-area-inset-top, 0px); }
    .rail {
        position: fixed; bottom: 0; left: 0; right: 0; top: auto;
        flex-direction: row; width: 100%; height: var(--rail-h-mobile);
        border-right: none; border-top: 1px solid var(--c-border);
        padding: 0 var(--sp-3); padding-bottom: env(safe-area-inset-bottom, 0px);
        z-index: var(--z-sticky);
    }
    .rail__brand { display: none; }
    .rail__nav { flex-direction: row; justify-content: space-around; }
    .rail__item.is-active::before { left: 50%; top: -1px; transform: translateX(-50%); width: 22px; height: 3px; }
    .rail__foot { margin-top: 0; }
    .user-menu__pop { bottom: calc(100% + 10px); left: auto; right: 0; }
    .workspace__body { padding-bottom: var(--rail-h-mobile); }
}

/* ============================================================
   Modal & drawer (dipakai lintas modul: Contacts, Team, Templates, Inbox)
   ============================================================ */
.modal-overlay, .drawer-overlay {
    position: fixed; inset: 0; background: rgba(34,32,28,.35); backdrop-filter: blur(2px);
    opacity: 0; visibility: hidden; transition: opacity var(--t-med), visibility var(--t-med); z-index: var(--z-dropdown, 900);
}
.modal-overlay.is-open, .drawer-overlay.is-open { opacity: 1; visibility: visible; }

.modal {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -48%);
    width: 560px; max-width: 94vw; max-height: 86vh;
    background: var(--c-surface); border-radius: var(--r-xl); box-shadow: var(--sh-lg);
    z-index: var(--z-modal, 1000); display: flex; flex-direction: column;
    opacity: 0; visibility: hidden; transition: opacity var(--t-med), transform var(--t-med), visibility var(--t-med);
}
.modal-overlay.is-open ~ .modal,
.modal-overlay.is-open .modal,
.modal.is-open { opacity: 1; visibility: visible; transform: translate(-50%, -50%); }
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--c-border); }
.modal__title { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.modal__body { padding: var(--sp-4) var(--sp-5); overflow-y: auto; }
/* Footer aksi modal — SEBELUMNYA cuma didefinisikan di templates.css & team.css,
   jadi di halaman Inbox (yg tak memuat kedua css itu) .modal__foot TAK BERGAYA:
   tombol Batal/Kirim jatuh ke pojok kiri-bawah tanpa padding/garis/flex &
   tampak "kepotong" (§10.42). Dipindah ke sini (css modal bersama) supaya
   konsisten di SEMUA modul. flex-shrink:0 → footer tak ikut menyusut saat body
   modal panjang & bergulir (modal = flex column, body overflow-y:auto). */
.modal__foot {
    display: flex; align-items: center; gap: var(--sp-2);
    padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--c-border);
    flex-shrink: 0;
}

/* Field generik dalam modal */
.dfield { margin-bottom: var(--sp-3); }
.dfield > label { display: block; font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--c-ink-soft); margin-bottom: 5px; }

/* ============================================================
   Pemilih latar percakapan (modal dari user-menu)
   ============================================================ */
.chatbg-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-3); }
.chatbg-opt {
    display: flex; flex-direction: column; align-items: stretch; gap: 6px;
    padding: 6px; border: 1px solid var(--c-border); border-radius: var(--r-md);
    background: var(--c-surface); cursor: pointer; text-align: center;
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.chatbg-opt:hover { border-color: var(--c-border-strong); }
.chatbg-opt.is-active { border-color: var(--c-signal); box-shadow: 0 0 0 2px var(--c-signal-soft); }
.chatbg-opt__swatch {
    position: relative; height: 64px; border-radius: var(--r-sm);
    border: 1px solid var(--c-border); overflow: hidden; background-repeat: repeat;
}
/* Gelembung mini contoh, biar kebayang tampilan bubble di atas latar. */
.chatbg-opt__bubble {
    position: absolute; right: 8px; bottom: 8px; width: 46%; height: 14px;
    border-radius: 7px 7px 2px 7px; background: var(--c-bubble-out); box-shadow: var(--c-bubble-shadow);
}
.chatbg-opt__bubble::before {
    content: ""; position: absolute; left: 8px; top: 7px; width: 55%; height: 4px;
    border-radius: 2px; background: rgba(0,0,0,.14);
}
.chatbg-opt__label { font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--c-ink-soft); }
.chatbg-opt.is-active .chatbg-opt__label { color: var(--c-signal-700); }
@media (max-width: 480px) { .chatbg-grid { grid-template-columns: repeat(2, 1fr); } }

/* ============================================================
   Timeline aktivitas — dipakai Inbox (panel kontak) & Dashboard
   ============================================================ */
.timeline { position: relative; padding-left: 18px; }
.timeline::before {
    content: ""; position: absolute; left: 5px; top: 4px; bottom: 4px;
    width: 2px; background: var(--c-border);
}
.tl-item { position: relative; padding: 0 0 var(--sp-3) 0; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before {
    content: ""; position: absolute; left: -16px; top: 4px;
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--c-surface); border: 2px solid var(--c-border-strong);
}
.tl-item--signal::before { border-color: var(--c-signal); }
.tl-item--warn::before   { border-color: var(--c-window-warn); }
.tl-item--danger::before { border-color: var(--c-danger); }
.tl-item__text { font-size: var(--fs-sm); color: var(--c-ink-soft); line-height: 1.4; }
.tl-item__text b { color: var(--c-ink); font-weight: var(--fw-medium); }
.tl-item__time { font-size: 10px; color: var(--c-ink-mute); font-family: var(--font-mono); margin-top: 1px; }
.timeline__empty { font-size: var(--fs-xs); color: var(--c-ink-mute); }

/* §10.90 — Chip versi aplikasi di user menu */
.user-menu__version {
    margin-top: 6px; font-size: 10.5px; color: var(--c-ink-mute);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.2px;
}

/* ============================================================
   §10.92 — Bar filter rentang tanggal (Dashboard & Analitik)
   ============================================================ */
.rangebar {
    display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
}
.rangebar__custom {
    display: inline-flex; align-items: center; gap: 4px;
}
.rangebar__custom input[type="date"] {
    width: 138px; font-variant-numeric: tabular-nums;
}
.rangebar__dash { color: var(--c-ink-mute); font-size: var(--fs-sm); }
.an-agent { width: auto; min-width: 148px; max-width: 200px; }

/* Di layar sempit, bar filter turun ke barisnya sendiri agar judul halaman
   tidak terdesak — pola yang sama dengan composer di §10.91. */
@media (max-width: 900px) {
    .workspace__header { flex-wrap: wrap; height: auto; padding-top: 8px; padding-bottom: 8px; row-gap: 8px; }
    .rangebar { margin-left: 0 !important; width: 100%; }
    .rangebar__custom { flex-wrap: wrap; }
    .rangebar__custom input[type="date"] { width: 132px; }
    .an-controls { flex-wrap: wrap; width: 100%; }
    .an-agent { min-width: 132px; }
}

/* §10.94 — rincian pajak di kartu perkiraan biaya */
.dash-cost__taxline {
    display: flex; justify-content: space-between; align-items: baseline;
    font-size: var(--fs-xs); color: var(--c-ink-mute);
    padding: 2px 0; max-width: 320px;
}
.dash-cost__taxline + .dash-cost__taxline { border-top: 1px dashed var(--c-border); }

/* §10.95 — tabel rincian & rekonsiliasi biaya di dashboard */
.dash-cost__table {
    width: 100%; max-width: 560px; margin-top: 10px;
    border-collapse: collapse; font-size: var(--fs-sm);
}
.dash-cost__table td { padding: 5px 0; color: var(--c-ink-soft); }
.dash-cost__table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dash-cost__table td.strong { font-weight: var(--fw-semibold); color: var(--c-ink); }
.dash-cost__table tr.sub td { border-top: 1px solid var(--c-border); padding-top: 8px; }
.dash-cost__table tr.grand td { border-top: 1px solid var(--c-border-strong); padding-top: 8px; font-weight: var(--fw-semibold); color: var(--c-ink); }
.dash-cost__table tr.bill td { padding-top: 10px; }
.dash-cost__table tr.diff td { font-weight: var(--fw-semibold); }
.dash-cost__table tr.diff--ok    td { color: var(--c-signal-700); }
.dash-cost__table tr.diff--over  td { color: var(--c-danger); }
.dash-cost__table tr.diff--under td { color: var(--c-window-warn); }
.dash-cost__warn {
    margin: 10px 0 0; font-size: var(--fs-xs); color: var(--c-window-warn);
    max-width: 560px;
}
.dash-cost__hint { margin: 10px 0 0; font-size: var(--fs-xs); color: var(--c-ink-mute); }
.dash-cost__form {
    display: flex; gap: 6px; align-items: center; margin-top: 10px;
    flex-wrap: wrap; max-width: 560px;
}
.dash-cost__form input { max-width: 170px; }

/* §10.96 — baris pengingat saat PPN belum diaktifkan */
.dash-cost__table tr.taxoff td { color: var(--c-ink-mute); font-style: italic; }
.dash-cost__hint--act { color: var(--c-window-warn); }
.dash-cost__hint--act a { color: inherit; text-decoration: underline; }
