/* Core Styling System for Tenant Admin */
:root {
    --bg-main: #090d16;
    --bg-card: rgba(17, 24, 39, 0.6);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #f3f4f6;
    --text-muted: #9ca3af;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --pink: #db2777;
    --green: #059669;
    --red: #dc2626;
    --gold: #d97706;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    overflow-x: hidden;
    min-height: 100vh;
}

/* Glassmorphism card utility */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
}

.hide {
    display: none !important;
}

/* Welcome style card */
.welcome-card {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(219, 39, 119, 0.1));
    margin-bottom: 30px;
}
.welcome-card h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}
.welcome-card p {
    color: var(--text-muted);
    font-size: 15px;
    line-height: 1.5;
}

/* Login Page Styling */
#login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    background: radial-gradient(circle at top right, rgba(99, 102, 241, 0.15), transparent),
                radial-gradient(circle at bottom left, rgba(219, 39, 119, 0.1), transparent);
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: rgba(17, 24, 39, 0.85);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(20px);
}

.logo {
    text-align: center;
    margin-bottom: 30px;
}

.logo i {
    font-size: 40px;
    color: var(--primary);
    margin-bottom: 10px;
}

.logo h2 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 1px;
}

.logo p {
    color: var(--text-muted);
    font-size: 14px;
}

.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.input-group input, .input-group select {
    width: 100%;
    background: rgba(31, 41, 55, 0.9);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: all 0.3s ease;
}

select option {
    background-color: #0f172a !important;
    color: #f8fafc !important;
    padding: 10px;
}

.input-group input:focus, .input-group select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.3);
}

.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, var(--primary), #818cf8);
    border: none;
    border-radius: 8px;
    padding: 12px;
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(99, 102, 241, 0.4);
}

.error-alert {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid var(--red);
    color: #fca5a5;
    padding: 12px;
    border-radius: 8px;
    margin-top: 15px;
    font-size: 14px;
    text-align: center;
}

/* Sidebar Navigation Layout */
#app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: rgba(17, 24, 39, 0.95);
    border-right: 1px solid var(--border-color);
    padding: 30px 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 10;
    overflow: hidden;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand i {
    font-size: 24px;
    color: var(--primary);
}

.brand h2 {
    font-size: 20px;
    font-weight: 700;
}

.tenant-info {
    padding: 12px;
    background: rgba(255,255,255,0.03);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tenant-info .biz-name {
    font-weight: 600;
    font-size: 14px;
}

.tenant-info .user-role {
    font-size: 12px;
    color: var(--text-muted);
}

.tenant-info .plan-badge {
    font-size: 11px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #fff;
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
    align-self: flex-start;
    font-weight: 500;
    margin-top: 4px;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
}
.nav-menu::-webkit-scrollbar { width: 6px; }
.nav-menu::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
.nav-menu::-webkit-scrollbar-track { background: transparent; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.nav-item:hover, .nav-item.active {
    color: white;
    background: rgba(99, 102, 241, 0.1);
}

.nav-item.active {
    background: var(--primary);
}

.nav-item.logout {
    margin-top: auto;
}

.nav-item.logout:hover {
    background: rgba(220, 38, 38, 0.15);
    color: var(--red);
}

/* Sidebar menu groups (collapsible accordion) */
.nav-group {
    display: flex;
    flex-direction: column;
}
.nav-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px 5px;
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    cursor: pointer;
    user-select: none;
    opacity: 0.7;
    transition: opacity 0.2s, color 0.2s;
}
.nav-group-header:hover {
    opacity: 1;
    color: var(--text-primary);
}
.nav-group-header > span {
    display: flex;
    align-items: center;
    gap: 10px;
}
.nav-group-chevron {
    font-size: 9px;
    transition: transform 0.25s ease;
}
.nav-group.collapsed .nav-group-chevron {
    transform: rotate(-90deg);
}
.nav-group-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.nav-group.collapsed .nav-group-items {
    display: none;
}

/* Content Area */
.content {
    margin-left: 260px;
    flex-grow: 1;
    padding: 40px;
    background: radial-gradient(circle at top right, rgba(99, 102, 241, 0.05), transparent);
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
}

.top-bar h1 {
    font-size: 28px;
    font-weight: 700;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 14px;
}

.avatar {
    width: 40px;
    height: 40px;
    background: rgba(99, 102, 241, 0.2);
    border: 1px solid var(--primary);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--primary);
}

/* Stats Cards Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    backdrop-filter: blur(16px);
}

.stat-icon {
    width: 54px;
    height: 54px;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 22px;
}

.stat-icon.pink { background: rgba(219, 39, 119, 0.15); color: var(--pink); }
.stat-icon.green { background: rgba(5, 150, 105, 0.15); color: var(--green); }
.stat-icon.gold { background: rgba(217, 119, 6, 0.15); color: var(--gold); }

.stat-info h3 {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 500;
}

.stat-info p {
    font-size: 24px;
    font-weight: 700;
    margin-top: 4px;
}

/* Action Bar */
.action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

/* Branches Card Grid */
.branches-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
}

.branch-card {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.branch-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.branch-title {
    font-size: 18px;
    font-weight: 600;
}

.branch-contact {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.4;
}

.payment-toggles {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(255,255,255,0.03);
    padding: 14px;
    border-radius: 8px;
}

.payment-toggle-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}

/* Switches */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 22px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255,255,255,0.1);
    transition: .3s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary);
}

input:checked + .slider:before {
    transform: translateX(22px);
}

/* Tables Section */
.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.table-header h2, .table-header h3 {
    font-size: 20px;
    font-weight: 600;
}

.search-wrap {
    display: flex;
    gap: 12px;
}

.search-box {
    position: relative;
    width: 300px;
}

.search-box i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-box input {
    width: 100%;
    background: rgba(31, 41, 55, 0.5);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 16px 10px 40px;
    color: white;
    outline: none;
    font-size: 14px;
}

.search-box input:focus {
    border-color: var(--primary);
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
}

/* Tabel dengan tinggi dibatasi ~6 baris; sisanya di-scroll, header tetap menempel di atas. */
.scroll-rows {
    max-height: 384px;
    overflow-y: auto;
}
.scroll-rows thead th {
    position: sticky;
    top: 0;
    background: #0e1420;
    z-index: 2;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th, td {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
}

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

tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    display: inline-block;
}

.badge.owner { background: rgba(219, 39, 119, 0.15); color: var(--pink); }
.badge.admin_cabang { background: rgba(99, 102, 241, 0.15); color: #818cf8; }
.badge.kasir { background: rgba(217, 119, 6, 0.15); color: var(--gold); }
.badge.gudang { background: rgba(5, 150, 105, 0.15); color: var(--green); }

.badge.active { background: rgba(5, 150, 105, 0.15); color: #a7f3d0; }
.badge.suspended { background: rgba(220, 38, 38, 0.15); color: #fca5a5; }

/* Buttons */
.btn-sm {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.3s ease;
}

.btn-danger { background: rgba(220, 38, 38, 0.15); color: #fca5a5; border: 1px solid rgba(220, 38, 38, 0.3); }
.btn-danger:hover { background: var(--red); color: white; }

.btn-success { background: rgba(5, 150, 105, 0.15); color: #a7f3d0; border: 1px solid rgba(5, 150, 105, 0.3); }
.btn-success:hover { background: var(--green); color: white; }

.btn-sub { background: rgba(99, 102, 241, 0.15); color: #c7d2fe; border: 1px solid rgba(99, 102, 241, 0.3); margin-right: 6px; }
.btn-sub:hover { background: var(--primary); color: white; }

.action-buttons {
    display: flex;
    gap: 4px;
}

/* Grid layout for modals */
.grid-2-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.col-span-2 {
    grid-column: span 2;
}

/* Dual Layout for Products management page */
.products-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 24px;
    align-items: start;
}

/* DESKTOP FIX: cegah tabel lebar (mis. Kelola Produk) mendorong halaman melebar -> kolom "Aksi"
   kepotong di 100%. Tanpa min-width:0, flex/grid item menolak menyusut < lebar kontennya, sehingga
   tabel memaksa halaman melebar alih-alih discroll di dalam wadahnya. */
.content { min-width: 0; }
.products-layout > * { min-width: 0; }
.products-main-box .table-responsive { overflow-x: auto; }
/* Padding tabel produk dirapatkan agar lebih banyak muat tanpa scroll. */
.products-main-box th, .products-main-box td { padding: 10px 12px; }

.category-box {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.section-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.category-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.category-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-muted);
    transition: all 0.3s ease;
}

.category-item:hover, .category-item.active {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.category-item.active {
    border-left: 3px solid var(--primary);
}

.cat-actions {
    display: none;
    gap: 4px;
}

.category-item:hover .cat-actions {
    display: flex;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
}

.btn-icon:hover {
    color: white;
}

/* Modals layout styling */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    z-index: 99990 !important;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-y: auto;
    padding: 16px 10px;
}

.modal-content {
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0,0,0,0.6);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.btn-close-modal {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
}

.modal-body {
    margin-bottom: 16px;
    overflow-y: auto;
    flex: 1;
    padding-right: 4px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    flex-shrink: 0;
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 8px;
    padding: 10px 16px;
    font-weight: 600;
    cursor: pointer;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* Collapsible Sidebar transitions & layout adjustments */
.sidebar {
    transition: transform 0.3s ease, width 0.3s ease, padding 0.3s ease, border-color 0.3s ease;
}
.content {
    transition: margin-left 0.3s ease;
}
#app-container.sidebar-collapsed .sidebar {
    transform: translateX(-100%) !important;
    width: 0 !important;
    min-width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    border-right-color: transparent !important;
    overflow: hidden !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}
#app-container.sidebar-collapsed .content {
    margin-left: 0 !important;
    width: 100% !important;
}
#btn-toggle-sidebar:hover {
    color: var(--primary) !important;
}

/* ==========================================
   MOBILE RESPONSIVE & TOUCH-OPTIMIZED STYLES (< 768px)
   ========================================== */
@media (max-width: 768px) {
    button, input, select {
        min-height: 44px;
    }

    .content {
        margin-left: 0 !important;
        padding: 12px !important;
    }

    #btn-close-mobile-sidebar {
        display: block !important;
    }

    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        z-index: 9999 !important;
        width: 270px !important;
        transform: translateX(-100%) !important;
        transition: transform 0.3s ease !important;
        box-shadow: none !important;
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
    }

    #app-container.mobile-sidebar-open .sidebar {
        transform: translateX(0) !important;
        box-shadow: 4px 0 35px rgba(0, 0, 0, 0.8) !important;
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
        overflow-y: auto !important;
    }

    .topbar {
        padding: 10px 14px !important;
        flex-wrap: wrap;
        gap: 10px;
    }

    .grid-2-col, .grid-3-col, .grid-4-col {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    .table-responsive {
        width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    table {
        min-width: 600px;
    }

    .modal-content {
        width: 96% !important;
        max-width: 100% !important;
        margin: 10px auto !important;
        border-radius: 16px !important;
        padding: 16px !important;
    }

    .table-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !important;
    }

    .table-header div {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
}

/* ===== Perbaikan responsif & optimasi layar mobile menyeluruh (≤768px) ===== */
@media (max-width: 768px) {
    body {
        font-size: 14px;
    }
    
    .content {
        min-width: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        margin-left: 0 !important;
        padding: 10px !important;
        box-sizing: border-box;
    }

    .glass-card {
        padding: 14px 16px !important;
        border-radius: 12px !important;
        overflow-wrap: anywhere;
    }

    /* Collapse semua grid menjadi 1 kolom di HP */
    .stats-grid, .branches-grid, .products-layout,
    [class*="grid-"], [class*="-grid"],
    .content [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    .stats-grid > *, .branches-grid > *, .products-layout > *,
    [class*="grid-"] > *, [class*="-grid"] > *,
    .table-header > *, .action-bar > *, .search-wrap > *,
    .content [style*="grid-template-columns"] > * {
        min-width: 0 !important;
    }

    /* Baris filter & tombol pada mobile */
    .table-header, .action-bar, .search-wrap,
    [style*="display: flex"], [style*="display:flex"] {
        flex-wrap: wrap !important;
    }

    /* Wadah filter tanggal & cabang pada mobile */
    .glass-card [style*="overflow-x: auto"],
    .glass-card [style*="overflow-x:auto"] {
        flex-wrap: wrap !important;
        white-space: normal !important;
        overflow-x: visible !important;
        gap: 8px !important;
    }

    /* Input & Select pada mobile */
    input[type="text"], input[type="date"], input[type="number"], input[type="email"], input[type="password"], select {
        font-size: 13px !important;
        min-height: 38px !important;
    }

    button {
        min-height: 38px !important;
        touch-action: manipulation;
    }

    /* Modal pada Mobile */
    .modal-content {
        width: 95% !important;
        max-width: 100% !important;
        max-height: 88vh !important;
        overflow-y: auto !important;
        margin: 12px auto !important;
        border-radius: 14px !important;
        padding: 16px !important;
    }

    /* Tabel pada Mobile */
    .table-responsive, .table-container {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        margin-top: 8px;
    }

    .content table {
        width: 100%;
        min-width: 580px !important;
        white-space: nowrap;
    }

    /* Typography & Header pada Mobile */
    .welcome-card h2 {
        font-size: 18px !important;
    }
    
    .welcome-card p {
        font-size: 12.5px !important;
    }

    .top-bar {
        padding: 10px 12px !important;
    }

    .top-bar h1 {
        font-size: 17px !important;
    }
}

/* ===== Pengaman tablet (769–1024px) ===== */
@media (min-width: 769px) and (max-width: 1024px) {
    .content { min-width: 0 !important; }
    .stats-grid > *, .branches-grid > *, .products-layout > *,
    [class*="grid-"] > *, [class*="-grid"] > * { min-width: 0 !important; }
    .table-responsive, .table-container { max-width: 100% !important; overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
    .products-layout { grid-template-columns: 200px 1fr !important; }
    .modal-content { max-height: 90vh !important; overflow-y: auto !important; }
}

/* ===== Animasi Pergerakan Data Transaksi Real-time ===== */
.stat-card.flash-update {
    animation: flashGreen 0.9s ease-out;
}

@keyframes flashGreen {
    0% { border-color: #10b981; box-shadow: 0 0 25px rgba(16, 185, 129, 0.6); transform: scale(1.02); }
    50% { border-color: #34d399; box-shadow: 0 0 35px rgba(52, 211, 153, 0.8); transform: scale(1.03); }
    100% { border-color: var(--border-color); box-shadow: none; transform: scale(1); }
}
