:root {
    --primary: #27244e;
    --primary-dark: #1f1c40;
    --primary-soft: #f4f3fa;
    --bg-main: #f8f9fc;
    --bg-card: #ffffff;
    --border-soft: #e5e7eb;
    --text-main: #111827;
    --text-muted: #6b7280;
    --success: #16a34a;
    --warning: #f59e0b;
    --danger: #dc2626;
    --draft: #6b7280;
    --shadow-soft: 0 14px 34px rgba(17, 24, 39, .055);
    --shadow-hover: 0 20px 42px rgba(17, 24, 39, .085);
}

* { letter-spacing: 0; }

body {
    min-height: 100vh;
    background: var(--bg-main);
    color: var(--text-main);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.auth-page { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%); }

.app-layout { min-height: 100vh; display: flex; }
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    width: 264px;
    padding: 24px 18px;
    color: #fff;
    background:
        radial-gradient(circle at 35% 0%, rgba(255,255,255,.12), transparent 34%),
        var(--primary);
    transition: width .24s ease, transform .24s ease, box-shadow .24s ease, padding .24s ease;
}

.sidebar-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.brand-logo { display: block; object-fit: contain; transition: opacity .18s ease, width .24s ease, height .24s ease; }
.brand-logo-full { width: 168px; height: 48px; }
.brand-logo-icon { display: none; width: 44px; height: 44px; }
.brand-mark {
    width: 44px; height: 44px; border-radius: 16px;
    display: grid; place-items: center;
    color: #fff; font-weight: bold;
    background: rgba(255,255,255,.14);
    border: 1px solid rgba(255,255,255,.16);
}
.brand-title { font-size: 20px; font-weight: bold; line-height: 1; }
.brand-subtitle { color: rgba(255,255,255,.68); font-size: 11px; margin-top: 5px; max-width: 160px; }
.sidebar-menu { display: grid; gap: 7px; }
.sidebar-menu a {
    display: flex; align-items: center; gap: 12px;
    min-height: 46px;
    padding: 12px 14px;
    border-radius: 14px;
    color: rgba(255,255,255,.78);
    text-decoration: none;
    font-size: 14px;
    font-weight: bold;
    transition: background .18s ease, color .18s ease, transform .18s ease;
}
.sidebar-menu a i { width: 20px; flex: 0 0 20px; text-align: center; font-size: 17px; }
.sidebar-menu a span { transition: opacity .16s ease; white-space: nowrap; }
.sidebar-menu a:hover { color: #fff; background: rgba(255,255,255,.09); transform: translateX(2px); }
.sidebar-menu a.active { color: #fff; background: rgba(255,255,255,.14); }
.sidebar-footer {
    position: absolute; left: 18px; right: 18px; bottom: 20px;
    padding-top: 16px;
    border-top: 1px solid rgba(255,255,255,.13);
    color: rgba(255,255,255,.62);
    font-size: 12px;
}

.mobile-overlay { display: none; }
.main-content { flex: 1; min-width: 0; margin-left: 264px; transition: margin-left .24s ease; }
.topbar {
    position: sticky; top: 0; z-index: 1020;
    height: 76px;
    display: flex; align-items: center; justify-content: space-between; gap: 18px;
    padding: 0 30px;
    background: rgba(255,255,255,.94);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border-soft);
    box-shadow: 0 12px 26px rgba(17,24,39,.04);
}
.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.topbar-title { font-size: 16px; font-weight: bold; }
.topbar-subtitle { color: var(--text-muted); font-size: 12px; }
.topbar-search {
    width: min(330px, 34vw);
    display: flex; align-items: center; gap: 8px;
    padding: 10px 13px;
    color: var(--text-muted);
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    background: #fbfbfd;
}
.topbar-search input { border: 0; outline: 0; background: transparent; width: 100%; font-size: 13px; }
.profile-pill {
    display: flex; align-items: center; gap: 10px;
    padding: 7px 10px 7px 7px;
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    background: #fff;
}
.profile-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: bold;
}
.content-wrapper { padding: 30px; }
.page-heading { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 24px; }
.page-title { margin: 0; font-size: 28px; font-weight: bold; }
.page-subtitle { margin-top: 5px; color: var(--text-muted); }

.custom-card, .stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: 18px;
    box-shadow: var(--shadow-soft);
    transition: transform .18s ease, box-shadow .18s ease;
}
.custom-card:hover, .stat-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-hover); }
.custom-card-header {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border-soft);
}
.custom-card-body { padding: 20px; }
.stat-card { padding: 20px; height: 100%; display: flex; align-items: center; gap: 15px; }
.stat-icon {
    width: 48px; height: 48px; border-radius: 16px;
    display: grid; place-items: center;
    color: #fff; background: var(--primary);
}
.stat-value { font-size: 25px; line-height: 1; font-weight: bold; }
.stat-label { color: var(--text-muted); font-size: 12px; font-weight: bold; margin-top: 7px; }

.custom-button, .custom-button-secondary, .custom-button-danger, .custom-button-success, .icon-button {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 42px;
    padding: 10px 15px;
    border-radius: 12px;
    border: 1px solid transparent;
    font-weight: bold;
    font-size: 14px;
    text-decoration: none;
    cursor: pointer;
    transition: background .18s ease, border-color .18s ease, color .18s ease, transform .18s ease;
}
.custom-button { background: var(--primary); border-color: var(--primary); color: #fff; }
.custom-button:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; transform: translateY(-1px); }
.custom-button-secondary { background: #fff; border-color: rgba(39,36,78,.26); color: var(--primary); }
.custom-button-secondary:hover { background: var(--primary-soft); color: var(--primary); }
.custom-button-success { background: var(--success); border-color: var(--success); color: #fff; }
.custom-button-danger { background: #fff; border-color: rgba(220,38,38,.22); color: var(--danger); }
.icon-button { width: 42px; padding: 0; background: #fff; border-color: var(--border-soft); color: var(--primary); }
.button-sm { min-height: 36px; padding: 8px 12px; font-size: 13px; border-radius: 10px; }

.custom-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-span-2 { grid-column: span 2; }
.form-label { display: block; margin-bottom: 8px; color: var(--text-main); font-size: 13px; font-weight: bold; }
.form-control-custom, .form-select-custom, .form-textarea-custom {
    width: 100%;
    border: 1px solid var(--border-soft);
    border-radius: 13px;
    background: #fff;
    color: var(--text-main);
    padding: 12px 13px;
    outline: none;
    transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
.form-control-custom:focus, .form-select-custom:focus, .form-textarea-custom:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(39,36,78,.10);
}
.form-textarea-custom { min-height: 88px; resize: vertical; }
.filter-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 14px; align-items: end; }
.receipt-filter-grid { grid-template-columns: 2fr 1fr auto; }

.custom-table-wrap { overflow: visible; }
.custom-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.custom-table th {
    padding: 14px 16px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 11px;
    text-transform: uppercase;
    font-weight: bold;
}
.custom-table th:first-child { border-radius: 14px 0 0 14px; }
.custom-table th:last-child { border-radius: 0 14px 14px 0; }
.custom-table td {
    padding: 17px 16px;
    border-bottom: 1px solid var(--border-soft);
    vertical-align: middle;
}
.custom-table tbody tr { transition: background .16s ease; }
.custom-table tbody tr:hover { background: #fafbfe; }

.custom-badge {
    display: inline-flex; align-items: center; gap: 6px;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: bold;
    white-space: nowrap;
}
.badge-draft { background: rgba(107,114,128,.12); color: var(--draft); }
.badge-unpaid { background: rgba(245,158,11,.14); color: #b45309; }
.badge-paid { background: rgba(22,163,74,.12); color: var(--success); }
.badge-cancelled { background: rgba(220,38,38,.12); color: var(--danger); }

.action-dropdown { position: relative; display: inline-block; }
.action-menu {
    min-width: 230px;
    border: 1px solid var(--border-soft);
    border-radius: 14px;
    padding: 8px;
    box-shadow: 0 18px 38px rgba(17,24,39,.12);
}
.action-menu .dropdown-item {
    border-radius: 10px;
    padding: 10px 11px;
    font-weight: bold;
    font-size: 13px;
}

.mobile-card-list { display: none; }
.mobile-record-card {
    padding: 17px;
    background: #fff;
    border: 1px solid var(--border-soft);
    border-radius: 18px;
    box-shadow: var(--shadow-soft);
}
.record-top { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.record-title { font-weight: bold; color: var(--primary); }
.record-meta { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.record-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; margin-top: 15px; }
.record-label { color: var(--text-muted); font-size: 11px; text-transform: uppercase; font-weight: bold; }
.record-value { margin-top: 3px; font-weight: bold; }

.invoice-items-desktop { display: block; }
.invoice-items-mobile { display: block; }
.item-mobile-card {
    border: 1px solid var(--border-soft);
    border-radius: 16px;
    padding: 15px;
    background: #fff;
    margin-bottom: 14px;
}
.invoice-total-bar {
    display: flex; justify-content: end; align-items: center; gap: 16px;
    padding: 16px 20px;
    background: var(--primary-soft);
    border-radius: 16px;
    margin-top: 16px;
}
.invoice-total-value { color: var(--primary); font-size: 22px; font-weight: bold; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }

.invoice-document, .receipt-document, .document {
    background: #fff;
    max-width: 920px;
    margin: auto;
    padding: 48px;
    border: 1px solid var(--border-soft);
    border-radius: 18px;
    box-shadow: var(--shadow-soft);
}
.document-header { border-bottom: 3px solid var(--primary); padding-bottom: 18px; }
.doc-hero { display: flex; justify-content: space-between; gap: 28px; align-items: flex-start; }
.doc-logo { width: 178px; height: auto; margin-bottom: 14px; }
.doc-brand { color: var(--text-muted); font-weight: bold; font-size: 11px; text-transform: uppercase; margin-bottom: 6px; }
.doc-title-block { text-align: right; }
.doc-title { margin: 8px 0 4px; color: var(--primary); font-size: 34px; font-weight: bold; }
.doc-muted { color: var(--text-muted); font-size: 13px; line-height: 1.6; }
.doc-type-pill {
    display: inline-block;
    margin-bottom: 12px;
    padding: 7px 11px;
    color: var(--primary);
    background: var(--primary-soft);
    border-radius: 999px;
    font-size: 11px;
    font-weight: bold;
}
.doc-total { color: var(--primary); font-size: 18px; }
.doc-info-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 0; margin: 28px 0; width: 100%; }
.doc-client-card, .doc-meta-card, .doc-note, .doc-summary {
    border: 1px solid var(--border-soft);
    border-radius: 0;
    background: #fff;
}
.doc-meta-card, .doc-summary { border-left: 0; }
.doc-client-card, .doc-note { padding: 20px; }
.doc-label { color: var(--text-muted); font-size: 11px; text-transform: uppercase; font-weight: bold; margin-bottom: 8px; }
.doc-client-name { color: var(--primary); font-size: 20px; font-weight: bold; margin-bottom: 6px; }
.doc-meta-card { overflow: hidden; }
.doc-meta-row { display: flex; justify-content: space-between; gap: 16px; padding: 13px 16px; border-bottom: 1px solid var(--border-soft); }
.doc-meta-row:last-child { border-bottom: 0; }
.doc-meta-row span { color: var(--text-muted); }
.doc-section-title { color: var(--primary); font-size: 13px; text-transform: uppercase; font-weight: bold; margin: 8px 0 12px; }
.doc-bottom-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 0; margin-top: 24px; align-items: stretch; width: 100%; }
.doc-summary { padding: 22px; background: var(--primary-soft); text-align: right; }
.doc-summary-label { color: var(--text-muted); text-transform: uppercase; font-size: 11px; font-weight: bold; }
.doc-summary-amount { color: var(--primary); font-size: 28px; font-weight: bold; margin-top: 8px; }
.doc-summary-status { display: inline-block; color: var(--success); margin-top: 12px; font-weight: bold; }
.doc-note-label { margin-top: 16px; }
.receipt-verification {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: center;
    margin-top: 24px;
    padding: 16px 0;
    border-top: 1px solid var(--border-soft);
    border-bottom: 1px solid var(--border-soft);
}
.verification-code { text-align: right; }
.verification-qr {
    width: 132px;
    height: 132px;
    object-fit: contain;
    padding: 8px;
    border: 1px solid var(--border-soft);
    border-radius: 14px;
    background: #fff;
}
.verify-url { color: var(--text-muted); font-size: 11px; margin-top: 6px; word-break: break-all; }
.paid-stamp {
    display: inline-block;
    color: var(--success);
    border: 2px solid var(--success);
    border-radius: 10px;
    padding: 7px 12px;
    font-weight: bold;
}
.document-table { width: 100%; border-collapse: collapse; }
.document-table th, .document-table td { border-bottom: 1px solid var(--border-soft); padding: 14px 12px; }
.document-table thead { background: var(--primary-soft); }
.document-table tfoot { background: #fff; }
.document-table th { color: var(--primary); }
.document-item-list { display: none; }
.detail-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: end; }

.toast-container { z-index: 1080; }
.titikpay-toast {
    border: 0;
    border-radius: 16px;
    box-shadow: 0 18px 40px rgba(17,24,39,.18);
}
.modal-content {
    border: 0;
    border-radius: 20px;
    box-shadow: 0 22px 60px rgba(17,24,39,.22);
}

.empty-state { padding: 52px 20px; text-align: center; color: var(--text-muted); }
.empty-icon {
    width: 52px; height: 52px; border-radius: 18px;
    display: grid; place-items: center;
    margin: 0 auto 12px;
    color: var(--primary);
    background: var(--primary-soft);
}
.money { white-space: nowrap; }

@media (max-width: 767px) {
    .sidebar {
        width: min(86vw, 320px);
        transform: translateX(-105%);
        box-shadow: none;
    }
    body.sidebar-open .sidebar { transform: translateX(0); box-shadow: 20px 0 60px rgba(17,24,39,.24); }
    .mobile-overlay {
        display: block;
        position: fixed; inset: 0;
        z-index: 1030;
        pointer-events: none;
        opacity: 0;
        background: rgba(17,24,39,.48);
        transition: opacity .22s ease;
    }
    body.sidebar-open .mobile-overlay { opacity: 1; pointer-events: auto; }
    .main-content { margin-left: 0; }
    .topbar { height: 68px; padding: 0 14px; }
    .topbar-search, .topbar-subtitle, .profile-name { display: none; }
    .content-wrapper { padding: 18px 14px 26px; }
    .page-heading { align-items: stretch; }
    .page-heading > a, .page-heading .custom-button { width: 100%; }
    .page-title { font-size: 24px; }
    .custom-card-body { padding: 16px; }
    .custom-card-header { flex-direction: column; align-items: stretch; }
    .custom-card-header .custom-button-secondary,
    .custom-card-header .custom-button { width: 100%; }
    .stat-card { padding: 17px; }
    .desktop-table { display: none; }
    .mobile-card-list { display: grid; gap: 14px; }
    .filter-grid, .receipt-filter-grid, .custom-form-grid { grid-template-columns: 1fr; }
    .form-span-2 { grid-column: span 1; }
    .invoice-items-desktop { display: none; }
    .invoice-items-mobile { display: block; }
    .invoice-total-bar { justify-content: space-between; padding: 15px; }
    .form-actions { position: sticky; bottom: 0; z-index: 20; background: rgba(248,249,252,.95); padding: 12px 0; flex-direction: column; }
    .form-actions .custom-button, .form-actions .custom-button-secondary { width: 100%; }
    .detail-actions { flex-direction: column; }
    .detail-actions > *, .detail-actions .custom-button, .detail-actions .custom-button-secondary, .detail-actions form { width: 100%; }
    .invoice-document, .receipt-document, .document { padding: 24px 16px; border-radius: 16px; }
    .doc-hero, .doc-info-grid, .doc-bottom-grid { display: block; }
    .doc-title-block { text-align: left; margin-top: 18px; }
    .doc-meta-card, .doc-summary { margin-top: 14px; }
    .doc-meta-card, .doc-summary { border-left: 1px solid var(--border-soft); }
    .receipt-verification { display: block; }
    .verification-code { text-align: left; margin-top: 12px; }
    .verification-qr { width: 132px; height: 132px; }
    .document-table-wrap { display: none; }
    .document-item-list { display: grid; gap: 12px; }
    .document-item-card { border: 1px solid var(--border-soft); border-radius: 14px; padding: 13px; }
    .record-grid { grid-template-columns: 1fr; }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .sidebar { transform: translateX(-105%); }
    body.sidebar-open .sidebar { transform: translateX(0); box-shadow: 20px 0 60px rgba(17,24,39,.24); }
    .mobile-overlay {
        display: block; position: fixed; inset: 0; z-index: 1030;
        pointer-events: none; opacity: 0; background: rgba(17,24,39,.48); transition: opacity .22s ease;
    }
    body.sidebar-open .mobile-overlay { opacity: 1; pointer-events: auto; }
    .main-content { margin-left: 0; }
    .content-wrapper { padding: 24px; }
    .filter-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .receipt-filter-grid { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 1024px) {
    body.sidebar-collapsed .sidebar {
        width: 86px;
        padding-left: 15px;
        padding-right: 15px;
    }
    body.sidebar-collapsed .main-content { margin-left: 86px; }
    body.sidebar-collapsed .sidebar-brand { justify-content: center; }
    body.sidebar-collapsed .brand-logo-full { display: none; }
    body.sidebar-collapsed .brand-logo-icon { display: block; }
    body.sidebar-collapsed .sidebar-menu a {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
        gap: 0;
    }
    body.sidebar-collapsed .sidebar-menu a span,
    body.sidebar-collapsed .sidebar-footer {
        opacity: 0;
        pointer-events: none;
        width: 0;
        overflow: hidden;
    }
    body.sidebar-collapsed .sidebar-menu a:hover { transform: translateX(0); }
    .desktop-only { display: initial; }
    .item-mobile-card .custom-form-grid {
        grid-template-columns: 1.4fr 1.4fr .55fr 1fr 1fr;
        align-items: end;
    }
    .item-mobile-card .form-span-2 { grid-column: auto; }
    .item-mobile-card .form-label { font-size: 11px; color: var(--text-muted); }
}
