:root {
    --color-primary: #8c52ff;
    --color-primary-dark: #7239e0;
    --color-primary-light: #f1ebff;
    --color-accent: #ffd000;
    --color-accent-dark: #e0b400;
    --color-ink: #241748;
    --color-bg: #f8f6fd;
    --color-surface: #ffffff;
    --color-border: #e9e3f7;
    --color-text-muted: #6e6485;
    --color-danger: #dc2626;
    --color-success: #16a34a;
    --sidebar-bg: #241748;
    --sidebar-bg-active: #382266;
    --radius: 10px;
}

* {
    box-sizing: border-box;
}

/*
 * Pakai font sistem Mac (San Francisco / SF Pro) lewat -apple-system.
 * Ini BUKAN embed file font - browser/Electron otomatis mengambilnya
 * langsung dari macOS, sesuai lisensi resmi Apple (font SF tidak boleh
 * di-bundle sebagai file di dalam software pihak ketiga).
 */
html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-ink);
}

/* ---------- Layout dengan sidebar ---------- */
.app-shell {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 232px;
    height: 100vh;
    background: var(--sidebar-bg);
    color: #cfc4ec;
    padding: 20px 0;
    flex-shrink: 0;
    overflow-y: auto;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 12px;
}

.sidebar__brand img {
    width: 34px;
    height: 34px;
    object-fit: contain;
}

.sidebar__brand span {
    font-weight: 700;
    font-size: 15px;
    color: #fff;
    line-height: 1.2;
}

.sidebar__nav a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    margin: 2px 10px;
    border-radius: 8px;
    color: #cfc4ec;
    text-decoration: none;
    font-size: 14px;
    transition: background 0.15s ease, color 0.15s ease;
}

.sidebar__nav a:hover {
    background: var(--sidebar-bg-active);
    color: #fff;
}

.sidebar__nav a.active {
    background: var(--color-accent);
    color: var(--color-ink);
    font-weight: 700;
}

.content {
    flex: 1;
    padding: 24px 32px;
    height: 100vh;
    overflow-y: auto;
}

/* ---------- Login page ---------- */
.login-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 30% 20%, #a476ff 0%, var(--color-ink) 65%);
}

.login-logo {
    width: 110px;
    height: 110px;
    object-fit: contain;
    margin-bottom: 18px;
}

.login-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 16px;
    padding: 32px;
    width: 320px;
    box-shadow: 0 20px 50px rgba(36, 23, 72, 0.35);
}

/* ---------- Komponen umum ---------- */
h1 {
    font-size: 20px;
    margin: 0 0 20px;
}

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: 0 1px 2px rgba(36, 23, 72, 0.04);
}

label {
    display: block;
    font-size: 13px;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

input, select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 14px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    font-family: inherit;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

button {
    cursor: pointer;
    border: none;
    border-radius: 8px;
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 600;
    background: var(--color-primary);
    color: #fff;
    transition: background 0.15s ease, transform 0.05s ease;
}

/* Kasih jarak antar tombol yang bersebelahan (toolbar, Edit/Hapus di
   tabel, dst) - tanpa ini tombol saling nempel karena tidak ada gap
   bawaan antar elemen inline. */
button + button {
    margin-left: 8px;
}

button:hover {
    background: var(--color-primary-dark);
}

button:active {
    transform: scale(0.98);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

button.secondary {
    background: transparent;
    color: var(--color-ink);
    border: 1px solid var(--color-border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th, td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border);
}

tbody tr {
    transition: background 0.1s ease;
}

tbody tr:hover {
    background: var(--color-primary-light);
}

th {
    color: var(--color-text-muted);
    font-weight: 600;
}

.error-text {
    color: var(--color-danger);
    font-size: 13px;
    margin: -8px 0 12px;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

/* ---------- Order items & badges ---------- */
.order-item-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

.order-item-row select,
.order-item-row .searchable-select {
    flex: 2;
    margin-bottom: 0;
}

.order-item-row input {
    flex: 0 0 70px;
    margin-bottom: 0;
}

.order-item-row .item-subtotal {
    flex: 0 0 110px;
    font-size: 13px;
    color: var(--color-text-muted);
}

.bulk-item-row,
.bulk-customer-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

.bulk-item-row select,
.bulk-item-row .searchable-select,
.bulk-customer-row select,
.bulk-customer-row .searchable-select {
    flex: 1;
    margin-bottom: 0;
}

.session-item-row {
    padding-bottom: 10px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--color-border);
}

.session-item-row:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: #e5e7eb;
    color: #374151;
}

.badge.LUNAS, .badge.COMPLETED, .badge.PAID { background: #dcfce7; color: #15803d; }
.badge.SUBMIT { background: #ede9fe; color: #6d28d9; }
.badge.SEBAGIAN, .badge.WAITING_PAYMENT, .badge.ON_SITE { background: #fef3c7; color: #92400e; }
.badge.BELUM_BAYAR, .badge.DRAFT { background: #e5e7eb; color: #374151; }
.badge.CANCELLED { background: #fee2e2; color: #b91c1c; }
.badge.INVOICE_SENT { background: #dbeafe; color: #1d4ed8; }

/* ---------- Select status inline di tabel Order (tampilan mirip badge) ---------- */
.badge-select {
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    background: #e5e7eb;
    color: #374151;
}

.badge-select.LUNAS, .badge-select.COMPLETED, .badge-select.PAID { background: #dcfce7; color: #15803d; }
.badge-select.SEBAGIAN, .badge-select.WAITING_PAYMENT, .badge-select.ON_SITE { background: #fef3c7; color: #92400e; }
.badge-select.BELUM_BAYAR, .badge-select.DRAFT { background: #e5e7eb; color: #374151; }
.badge-select.CANCELLED { background: #fee2e2; color: #b91c1c; }
.badge-select.INVOICE_SENT { background: #dbeafe; color: #1d4ed8; }

.link-btn {
    background: none;
    border: none;
    color: var(--color-primary);
    font-weight: 600;
    padding: 0;
}
.link-btn:hover { background: none; text-decoration: underline; }

/* ---------- Select order & ubah status massal (halaman Order) ---------- */
.orders-bulk-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--color-border);
}

.orders-select-all-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--color-text-muted);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.orders-select-all-label input[type="checkbox"] {
    margin: 0;
    width: 20px;
    flex: 0 0 20px;
}

/* Baris 1: checkbox "Pilih Semua" + jumlah terpilih - dikelompokkan biar
   gampang diatur sejajar kiri-kanan bareng (lihat override-nya di
   mobile.css). */
.orders-bulk-select-row {
    display: flex ;
    align-items: center;
    gap: 15px;
}

.orders-bulk-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.orders-bulk-actions select,
.orders-bulk-actions button {
    margin: 0;
}

/* Bungkus tombol Batal + Terapkan biar bisa digeser sebagai satu grup
   (lihat override posisinya di mobile.css). */
.orders-bulk-actions__buttons {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Select "Ubah status ke..." kepakai juga di mobile, di mana select biasa
   dipaksa font-size 16px (lihat mobile.css - biar Safari nggak auto-zoom
   pas fokus). Di sini sengaja dikecilkan pakai id selector (spesifisitasnya
   otomatis menang atas rule mobile itu) - sama seperti .badge-select yang
   juga sengaja dikecilkan, biar nggak keliatan gede sendiri dibanding
   elemen lain di bar aksi massal. */
#bulk-status-select {
    font-size: 13px;
    padding: 6px 10px;
}

#orders-table td.col-select {
    width: 36px;
}

#orders-table td.col-select input[type="checkbox"] {
    margin: 0;
}

/* Kolom checkbox (header & tiap baris) disembunyikan default - baru
   tampil setelah tombol "Pilih Order" diklik (lihat #orders-table.selection-mode-active). */
#orders-table:not(.selection-mode-active) .col-select {
    display: none !important;
}

/* Tombol "Pilih Order" di toolbar - state aktif dikasih aksen warna primary
   supaya kelihatan mode select lagi nyala, mirip titik aktif di tombol Filter. */
#btn-toggle-select-mode.active-toggle {
    background: var(--color-primary-light);
    border-color: var(--color-primary);
    color: var(--color-primary-dark);
}

/* Tab "Order Tunggal" / "Order Massal" di modal Order Baru - tab yang lagi
   aktif dikasih aksen warna primary, sama treatment-nya kayak tombol
   "Pilih Order" di atas. */
#btn-tab-single-order.active-toggle,
#btn-tab-bulk-order.active-toggle {
    background: var(--color-primary-light);
    border-color: var(--color-primary);
    color: var(--color-primary-dark);
}

/* Tombol WhatsApp - hijau sesuai warna icon-nya, icon + teks sejajar. */
.btn-whatsapp {
    background: #45c655;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-whatsapp:hover {
    background: #379645;
}

.btn-whatsapp img {
    width: 16px;
    height: 16px;
    display: block;
}

/* Kartu produk "ringkas -> tap -> buka di tengah" itu fitur khusus
   mobile (lihat mobile.css) - di desktop, backdrop-nya dipaksa
   tersembunyi apa pun state JS-nya, supaya klik kartu di desktop tidak
   memunculkan overlay gelap yang nggak ngapa-ngapain. */
/* Baris ringkas (nama + jumlah varian) di kartu produk - cuma dipakai
   di mobile (lihat mobile.css), disembunyikan di desktop karena body
   lengkapnya sudah selalu tampil. */
.product-card__compact-row {
    display: none;
}

@media (min-width: 861px) {
    #product-card-backdrop {
        display: none !important;
    }
}

/* Kartu Brand/Kategori/Event (halaman "Kelola Data"). Desktop: satu baris
   padat per item (Nama, Jumlah, Link, Edit, Hapus sejajar) - mirip tabel
   tapi tetap pakai markup div (bukan <table>) supaya bisa dipakai ulang
   buat versi mobile yang beda (lihat mobile.css - collapse jadi ringkas,
   tap buat buka detail di tengah layar). */
.master-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    padding: 10px 16px;
    margin-bottom: 8px;
}

.master-card__row {
    display: flex;
    align-items: center;
    gap: 16px;
}

.master-card__extra {
    display: flex;
    align-items: center;
    gap: 16px;
}

.master-card__actions {
    display: flex;
    gap: 8px;
}

@media (min-width: 861px) {
    #master-card-backdrop {
        display: none !important;
    }
}

/* Kartu Brand di halaman List Belanja - pola sama persis dengan
   .master-card di atas. */
.shopping-card__compact-row {
    display: none;
}

@media (min-width: 861px) {
    #shopping-card-backdrop {
        display: none !important;
    }
}

/* Baris/kartu order bisa di-tap langsung buka Detail (kecuali dropdown
   Status) - kursor pointer jadi penanda visual bahwa ini interaktif. */
.order-row-clickable {
    cursor: pointer;
}

/* Tombol X buat nutup modal/panel - dipisah dari tombol aksi lain
   supaya tidak numpuk, ditaruh di pojok kanan atas. */
.modal-close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 50%;
    background: #f1f1f4;
    color: #4b5563;
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close-btn:hover {
    background: #e2e2e8;
}

/* Nama (customer, brand, kategori, dst) dibedain (tebal + warna brand)
   supaya gampang di-scan sekilas, tidak ketuker sama data lain di
   baris/kartu yang sama. */
.name-highlight {
    font-weight: 700;
    color: var(--color-primary-dark);
}

.muted {
    color: var(--color-text-muted);
    font-size: 13px;
}

.product-card {
    margin-bottom: 16px;
}

.product-card__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

/* ---------- Micro-interaction: animasi masuk untuk form card ---------- */
@keyframes cardIn {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

.card-anim {
    animation: cardIn 0.18s ease;
}

/* ---------- Toast notification ---------- */
#toast-container {
    position: fixed;
    top: max(20px, env(safe-area-inset-top));
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
}

.toast {
    min-width: 260px;
    max-width: 360px;
    padding: 12px 16px;
    border-radius: 10px;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 10px 30px rgba(36, 23, 72, 0.25);
    animation: toastIn 0.2s ease;
}

.toast.success { background: var(--color-success); }
.toast.error { background: var(--color-danger); }
.toast.info { background: var(--color-ink); }

.toast.toast-out {
    animation: toastOut 0.2s ease forwards;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-10px); }
}

/* ---------- Modal konfirmasi ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(36, 23, 72, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: overlayIn 0.15s ease;
}

@keyframes overlayIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-box {
    background: var(--color-surface);
    border-radius: 14px;
    padding: 24px;
    width: 340px;
    box-shadow: 0 20px 50px rgba(36, 23, 72, 0.35);
    animation: cardIn 0.18s ease;
}

.modal-box p {
    margin: 0 0 20px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--color-ink);
}

.modal-box--center p {
    text-align: center;
}

.modal-box__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ---------- Form mengambang di tengah layar (Edit Produk/Order dkk) ---------- */
/* Dipakai supaya form tidak perlu discroll ke atas dulu - muncul di tengah
   layar persis, terlepas dari posisi scroll halaman saat tombol diklik. */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(36, 23, 72, 0.45);
    z-index: 999;
}

.floating-form-card {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    width: 90%;
    max-width: 640px;
    max-height: 85vh;
    overflow-y: auto;
}

#filter-active-dot {
    color: var(--color-primary);
    font-size: 10px;
    vertical-align: middle;
}

/* ---------- Skeleton loading ---------- */
@keyframes skeletonPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.skeleton-line {
    height: 14px;
    border-radius: 4px;
    background: var(--color-border);
    animation: skeletonPulse 1.2s ease-in-out infinite;
}

/* ---------- Empty state ---------- */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--color-text-muted);
}

.empty-state__icon {
    font-size: 36px;
    margin-bottom: 12px;
}

.empty-state__title {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-ink);
    margin: 0 0 4px;
}

.empty-state__hint {
    font-size: 13px;
    margin: 0 0 16px;
}

/* ---------- Dashboard stat cards ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.stat-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-card__label {
    font-size: 13px;
    color: var(--color-text-muted);
    font-weight: 600;
}

.stat-card__value {
    font-size: 26px;
    font-weight: 700;
    color: var(--color-ink);
}

.stat-card--link {
    color: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.stat-card--link:hover {
    box-shadow: 0 4px 12px rgba(36, 23, 72, 0.1);
    border-color: var(--color-primary);
}

.stat-card__icon {
    font-size: 20px;
}

@media (max-width: 900px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
/* ==========================================================================
   AI Chat Widget (chat mengambang)
   ========================================================================== */
#ai-chat-widget {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1000;
    font-family: inherit;
}

#ai-chat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    font-size: 24px;
    border: none;
    box-shadow: 0 6px 16px rgba(140, 82, 255, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#ai-chat-toggle:hover {
    background: var(--color-primary-dark);
}

#ai-chat-panel {
    position: absolute;
    right: 0;
    bottom: 72px;
    width: 340px;
    height: 460px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(36, 23, 72, 0.18);
    flex-direction: column;
    overflow: hidden;
}

#ai-chat-header {
    background: var(--color-primary);
    color: #fff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
}

#ai-chat-header button {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

#ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-chat-bubble {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-chat-bubble--user {
    align-self: flex-end;
    background: var(--color-primary);
    color: #fff;
    border-bottom-right-radius: 2px;
}

.ai-chat-bubble--model {
    align-self: flex-start;
    background: var(--color-primary-light);
    color: var(--color-ink);
    border-bottom-left-radius: 2px;
}

.ai-chat-bubble--error {
    background: #fee2e2;
    color: var(--color-danger);
}

#ai-chat-form {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid var(--color-border);
}

#ai-chat-form input {
    flex: 1;
    margin: 0;
}

#ai-chat-form button {
    margin: 0;
    padding: 8px 14px;
}

@media (max-width: 480px) {
    #ai-chat-panel {
        width: calc(100vw - 32px);
        height: 70vh;
        max-height: 70vh;
        right: -4px;
    }
}