/* =============================================================================
   AEI App - Stylesheet
   Mobile-first, clean, responsive
   ============================================================================= */

/* CSS Variables - design tokens */
:root {
    --color-primary: #2c5282;
    --color-primary-dark: #1e3a5f;
    --color-primary-light: #4a7bb0;
    --color-bg: #f7fafc;
    --color-surface: #ffffff;
    --color-border: #e2e8f0;
    --color-border-strong: #cbd5e0;
    --color-text: #1a202c;
    --color-text-secondary: #4a5568;
    --color-text-muted: #718096;
    --color-success: #38a169;
    --color-success-bg: #c6f6d5;
    --color-error: #e53e3e;
    --color-error-bg: #fed7d7;
    --color-warning: #dd6b20;
    --color-warning-bg: #feebc8;
    --color-info: #3182ce;
    --color-info-bg: #bee3f8;
    
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    
    --sidebar-w: 240px;
    --topbar-h: 56px;
    
    --transition-fast: 0.15s ease;
    --transition: 0.25s ease;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}

/* =============================================================================
   App Shell - sidebar + main area
   ============================================================================= */

.app-shell {
    min-height: 100vh;
    display: flex;
}

.sidebar {
    width: var(--sidebar-w);
    background: var(--color-primary-dark);
    color: rgba(255,255,255,0.95);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    transition: transform var(--transition);
    z-index: 100;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: white;
    text-decoration: none;
}

.logo-mark {
    width: 32px;
    height: 32px;
    background: var(--color-primary-light);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
}

.logo-text {
    font-weight: 600;
    font-size: 15px;
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    line-height: 1;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 8px;
}

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

.nav-group-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(255,255,255,0.4);
    padding: 0 12px 8px;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    border-radius: var(--radius-md);
    font-size: 13.5px;
    transition: background var(--transition-fast), color var(--transition-fast);
    margin-bottom: 2px;
}

.nav-item:hover {
    background: rgba(255,255,255,0.08);
    color: white;
}

.nav-item.active {
    background: var(--color-primary-light);
    color: white;
    font-weight: 500;
}

.nav-icon {
    width: 18px;
    height: 18px;
    display: inline-block;
    background: currentColor;
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    flex-shrink: 0;
    opacity: 0.85;
}

/* Pakai SVG mask data URL biar tidak perlu icon library */
.nav-icon[data-icon="home"] {
    -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z'/><polyline points='9 22 9 12 15 12 15 22'/></svg>");
    mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z'/><polyline points='9 22 9 12 15 12 15 22'/></svg>");
}

/* Main area */
.main-area {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-h);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    width: 36px;
    height: 36px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    border-radius: var(--radius-md);
}

.sidebar-toggle:hover { background: var(--color-bg); }
.sidebar-toggle span { width: 18px; height: 2px; background: var(--color-text); border-radius: 2px; }

.topbar-title {
    flex: 1;
    font-weight: 500;
    font-size: 15px;
    color: var(--color-text);
}

.user-menu { position: relative; }

.user-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: 1px solid var(--color-border);
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 13px;
    color: var(--color-text);
    transition: background var(--transition-fast);
}

.user-trigger:hover { background: var(--color-bg); }

.user-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--color-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 12px;
}

.user-arrow { color: var(--color-text-muted); font-size: 10px; }

.user-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 200px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: none;
    overflow: hidden;
}

.user-dropdown.active { display: block; }

.user-info {
    padding: 12px 14px;
    border-bottom: 1px solid var(--color-border);
}

.user-info-name { font-weight: 500; font-size: 13px; }
.user-info-role { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; }

.dropdown-item {
    display: block;
    padding: 10px 14px;
    color: var(--color-text);
    text-decoration: none;
    font-size: 13px;
    transition: background var(--transition-fast);
}

.dropdown-item:hover { background: var(--color-bg); }
.dropdown-item-danger { color: var(--color-error); }
.dropdown-item-danger:hover { background: var(--color-error-bg); }

/* Page content */
.page-content {
    padding: 20px;
    flex: 1;
    max-width: 100%;
}

.page-footer {
    padding: 16px 20px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 12px;
    border-top: 1px solid var(--color-border);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

/* =============================================================================
   Page Header (judul + tombol action)
   ============================================================================= */

.page-header {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.page-header h1 {
    font-size: 20px;
    margin: 0;
    color: var(--color-text);
    font-weight: 600;
}

.page-header .subtitle {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-top: 4px;
}

.page-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* =============================================================================
   Buttons
   ============================================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    transition: background var(--transition-fast), border-color var(--transition-fast), opacity var(--transition-fast);
    line-height: 1.4;
    white-space: nowrap;
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border);
}

.btn:hover { background: var(--color-bg); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--color-primary); color: white; border-color: var(--color-primary); }
.btn-primary:hover { background: var(--color-primary-dark); }

.btn-success { background: var(--color-success); color: white; border-color: var(--color-success); }
.btn-success:hover { opacity: 0.9; background: var(--color-success); }

.btn-danger { background: var(--color-error); color: white; border-color: var(--color-error); }
.btn-danger:hover { opacity: 0.9; background: var(--color-error); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 18px; font-size: 15px; }

.btn-block { width: 100%; }

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
}

/* =============================================================================
   Card
   ============================================================================= */

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--color-border);
}

.card-header h2,
.card-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

/* Stat cards untuk dashboard */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 16px;
}

.stat-label {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stat-value {
    font-size: 22px;
    font-weight: 600;
    color: var(--color-text);
}

.stat-meta {
    font-size: 12px;
    margin-top: 4px;
    color: var(--color-text-muted);
}

.stat-meta.up { color: var(--color-success); }
.stat-meta.down { color: var(--color-error); }

/* =============================================================================
   Form
   ============================================================================= */

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: 5px;
}

.form-group label .required { color: var(--color-error); }

.form-control {
    display: block;
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    font-size: 14px;
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    box-sizing: border-box;
    font-family: inherit;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(44,82,130,0.12);
}

.form-control:disabled, .form-control[readonly] {
    background: var(--color-bg);
    cursor: not-allowed;
}

textarea.form-control { min-height: 80px; resize: vertical; }

.form-help {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: 4px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}

.form-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding-top: 14px;
    margin-top: 14px;
    border-top: 1px solid var(--color-border);
}

/* Number input format ribuan akan di-handle via JS class .input-rupiah */
.input-rupiah { text-align: right; font-variant-numeric: tabular-nums; }

/* =============================================================================
   Table
   ============================================================================= */

.table-wrap {
    overflow-x: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
}

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

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

.table th {
    background: var(--color-bg);
    font-weight: 600;
    color: var(--color-text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.table tbody tr:hover { background: rgba(0,0,0,0.015); }
.table td.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { display: flex; gap: 4px; }

.table-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--color-text-muted);
}

/* Badge / status */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
}

.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-error { background: var(--color-error-bg); color: var(--color-error); }
.badge-info { background: var(--color-info-bg); color: var(--color-info); }
.badge-gray { background: var(--color-bg); color: var(--color-text-secondary); }

/* =============================================================================
   Flash messages
   ============================================================================= */

.flash-container { padding: 0 20px; margin-top: 12px; }

.flash {
    padding: 10px 14px;
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border: 1px solid;
}

.flash-success { background: var(--color-success-bg); color: var(--color-success); border-color: var(--color-success); }
.flash-error { background: var(--color-error-bg); color: var(--color-error); border-color: var(--color-error); }
.flash-warning { background: var(--color-warning-bg); color: var(--color-warning); border-color: var(--color-warning); }
.flash-info { background: var(--color-info-bg); color: var(--color-info); border-color: var(--color-info); }

.flash-close {
    background: none; border: none; cursor: pointer;
    font-size: 20px; line-height: 1; color: inherit; opacity: 0.7;
}

/* =============================================================================
   Modal
   ============================================================================= */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}

.modal-backdrop.active { display: flex; }

.modal {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-lg { max-width: 800px; }

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 { margin: 0; font-size: 16px; }

.modal-body { padding: 20px; }

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.modal-close {
    background: none; border: none; cursor: pointer;
    font-size: 24px; color: var(--color-text-muted);
    line-height: 1; padding: 0; width: 28px; height: 28px;
}

/* =============================================================================
   Permission grid (panel admin permission)
   ============================================================================= */

.permission-grid {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.permission-grid th,
.permission-grid td {
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    text-align: center;
}

.permission-grid th:first-child,
.permission-grid td:first-child {
    text-align: left;
    background: var(--color-bg);
    font-weight: 500;
}

.permission-grid input[type=checkbox] { transform: scale(1.2); cursor: pointer; }

/* =============================================================================
   Mobile (< 768px)
   ============================================================================= */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    
    .sidebar.active { transform: translateX(0); }
    .sidebar-overlay.active { display: block; }
    
    .sidebar-toggle { display: flex; }
    .sidebar-close { display: block; }
    
    .topbar { padding: 0 12px; }
    .topbar-title { font-size: 14px; }
    .user-name { display: none; }
    .user-trigger { padding: 4px 6px; }
    
    .page-content { padding: 14px; }
    
    .page-header { flex-direction: column; align-items: flex-start; }
    .page-actions { width: 100%; }
    .page-actions .btn { flex: 1; }
    
    /* Tabel: jadikan card-style di mobile */
    .table-mobile-cards .table thead { display: none; }
    .table-mobile-cards .table tr {
        display: block;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-md);
        padding: 12px;
        margin-bottom: 8px;
    }
    .table-mobile-cards .table td {
        display: flex;
        justify-content: space-between;
        border: none;
        padding: 4px 0;
    }
    .table-mobile-cards .table td::before {
        content: attr(data-label);
        font-weight: 500;
        color: var(--color-text-muted);
        font-size: 12px;
    }
    
    /* Form 1 kolom di mobile */
    .form-row { grid-template-columns: 1fr; }
    
    /* Modal full-screen di mobile */
    .modal { max-height: calc(100vh - 32px); border-radius: var(--radius-lg); }
}

/* =============================================================================
   Utilities
   ============================================================================= */

.text-muted { color: var(--color-text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-numeric { font-variant-numeric: tabular-nums; }

.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }

.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-1 { gap: 8px; } .gap-2 { gap: 12px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

.hidden { display: none !important; }

.is-loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.is-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'><circle cx='12' cy='12' r='10' stroke='%232c5282' stroke-width='3' fill='none' stroke-dasharray='40' stroke-dashoffset='10'><animateTransform attributeName='transform' type='rotate' from='0 12 12' to='360 12 12' dur='0.8s' repeatCount='indefinite'/></circle></svg>") center no-repeat;
}
