:root {
  --primary:  #1E3A5F;
  --accent:   #3B82F6;
  --success:  #10B981;
  --danger:   #EF4444;
  --warning:  #F59E0B;
  --surface:  #F8FAFC;
  --card:     #FFFFFF;
  --muted:    #64748B;
  --border:   #E2E8F0;
  --sidebar-w: 240px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  background: var(--surface);
  color: #1E293B;
  min-height: 100vh;
  overflow-x: hidden;
  max-width: 100vw;
}

/* ── Login ── */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, var(--primary) 0%, #2d5986 100%); }
.login-wrapper { width: 100%; max-width: 420px; padding: 1.5rem; }
.login-card { background: var(--card); border-radius: 16px; padding: 2.5rem; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-brand { text-align: center; margin-bottom: 2rem; }
.login-brand-icon { font-size: 3rem; color: var(--primary); }
.login-title { font-size: 2rem; font-weight: 700; color: var(--primary); margin-top: .5rem; }
.login-subtitle { color: var(--muted); font-size: .875rem; }
.login-footer { text-align: center; color: var(--muted); font-size: .75rem; margin-top: 1.5rem; }

/* ── Layout ── */
.app-wrapper { display: flex; min-height: 100vh; width: 100%; max-width: 100vw; overflow-x: hidden; }

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: center; gap: .75rem; padding: 1.25rem 1.25rem 1rem; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand-icon { font-size: 1.5rem; }
.brand-text { font-weight: 700; font-size: .95rem; line-height: 1.2; }
.sidebar-nav { flex: 1; padding: .75rem 0; }
.sidebar-nav li { list-style: none; }
.nav-link { display: flex; align-items: center; gap: .75rem; padding: .65rem 1.25rem; color: rgba(255,255,255,.7); text-decoration: none; border-radius: 0; transition: all .15s; }
.nav-link i { font-size: 1rem; width: 1.2rem; text-align: center; }
.nav-link:hover, .nav-link.active { background: rgba(255,255,255,.12); color: #fff; }
.nav-link.active { border-left: 3px solid var(--accent); }

.sidebar-saldo { margin: 0 1rem 1rem; background: rgba(255,255,255,.08); border-radius: 10px; padding: 1rem; }
.saldo-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: rgba(255,255,255,.5); margin-bottom: .25rem; }
.saldo-value { font-size: 1.1rem; font-weight: 700; color: #fff; font-variant-numeric: tabular-nums; }
.saldo-bar-wrap { background: rgba(255,255,255,.15); border-radius: 99px; height: 5px; margin: .5rem 0 .25rem; overflow: hidden; }
.saldo-bar { height: 100%; border-radius: 99px; transition: width .4s; }
.saldo-pct { font-size: .7rem; color: rgba(255,255,255,.5); }

.sidebar-user { padding: 1rem 1.25rem; border-top: 1px solid rgba(255,255,255,.1); display: flex; align-items: center; gap: .5rem; }
.user-info { flex: 1; overflow: hidden; }
.user-name { display: block; font-size: .875rem; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .65rem; background: var(--accent); color: #fff; padding: 1px 6px; border-radius: 4px; }
.btn-logout { color: rgba(255,255,255,.6); font-size: 1.1rem; text-decoration: none; flex-shrink: 0; }
.btn-logout:hover { color: var(--danger); }

/* ── Main Content ── */
.main-content { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-width: 0; max-width: 100%; }

.topbar { background: var(--card); border-bottom: 1px solid var(--border); padding: .875rem 1.5rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.topbar-title { font-size: 1.1rem; font-weight: 600; color: var(--primary); }
.topbar-actions { display: flex; gap: .5rem; align-items: center; }

.page-body { padding: 1.5rem; flex: 1; min-width: 0; }

/* ── Cards / KPI ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi-card { background: var(--card); border-radius: 12px; padding: 1.25rem; border: 1px solid var(--border); box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.kpi-label { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: .5rem; }
.kpi-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--primary); }
.kpi-sub { font-size: .75rem; color: var(--muted); margin-top: .25rem; }
.kpi-card.success .kpi-value { color: var(--success); }
.kpi-card.danger  .kpi-value { color: var(--danger); }
.kpi-card.accent  .kpi-value { color: var(--accent); }
.kpi-icon { font-size: 2rem; color: var(--border); float: right; margin-top: -1.75rem; }

/* ── Chart grid ── */
.chart-grid { display: grid; grid-template-columns: 1fr 1.6fr; gap: 1rem; margin-bottom: 1.5rem; }
.chart-card { background: var(--card); border-radius: 12px; padding: 1.25rem; border: 1px solid var(--border); }
.chart-title { font-size: .875rem; font-weight: 600; color: var(--primary); margin-bottom: 1rem; }

/* ── Table ── */
.table-card { background: var(--card); border-radius: 12px; border: 1px solid var(--border); overflow: hidden; min-width: 0; width: 100%; }
.table-header { padding: 1rem 1.25rem; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.table-header h6 { font-size: .875rem; font-weight: 600; margin: 0; }

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-responsive::-webkit-scrollbar {
  height: 6px;
}
.table-responsive::-webkit-scrollbar-track {
  background: #F1F5F9;
}
.table-responsive::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 3px;
}
.table-responsive::-webkit-scrollbar-thumb:hover {
  background: #94A3B8;
}

table.simda-table { width: 100%; min-width: 580px; border-collapse: collapse; }
table.simda-table th { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: .75rem 1rem; text-align: left; border-bottom: 1px solid var(--border); background: #FAFBFC; white-space: nowrap; }
table.simda-table td { padding: .75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
table.simda-table td a { white-space: normal; display: inline-block; min-width: 140px; max-width: 320px; }
table.simda-table tr:last-child td { border-bottom: none; }
table.simda-table tr:hover td { background: #F8FAFC; }
.num { font-variant-numeric: tabular-nums; }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; gap: .2rem; padding: 2px 8px; border-radius: 99px; font-size: .7rem; font-weight: 600; white-space: nowrap; }
.badge-success { background: #D1FAE5; color: #065F46; }
.badge-danger  { background: #FEE2E2; color: #991B1B; }
.badge-muted   { background: #F1F5F9; color: var(--muted); }
.badge-accent  { background: #DBEAFE; color: #1E40AF; }
.badge-warning { background: #FEF3C7; color: #92400E; }

/* ── Forms ── */
.form-card { background: var(--card); border-radius: 12px; border: 1px solid var(--border); padding: 1.5rem; }
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .8rem; font-weight: 600; color: #475569; margin-bottom: .4rem; }
.form-control, .form-select {
  width: 100%; padding: .5rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px; font-family: inherit; font-size: .875rem;
  background: #fff; color: #1E293B;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus, .form-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.input-icon { position: relative; }
.input-icon i { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.input-icon .form-control { padding-left: 2.2rem; }
.form-check-label { font-size: .875rem; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: .35rem; padding: .45rem 1rem; border-radius: 8px; font-size: .875rem; font-weight: 500; border: 1.5px solid transparent; cursor: pointer; text-decoration: none; transition: all .15s; white-space: nowrap; }
.btn-primary  { background: var(--accent);   border-color: var(--accent);   color: #fff; }
.btn-primary:hover  { background: #2563EB; border-color: #2563EB; }
.btn-success  { background: var(--success);  border-color: var(--success);  color: #fff; }
.btn-success:hover  { background: #059669; }
.btn-danger   { background: var(--danger);   border-color: var(--danger);   color: #fff; }
.btn-danger:hover   { background: #DC2626; }
.btn-outline  { background: transparent; border-color: var(--border); color: #475569; }
.btn-outline:hover  { border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: .3rem .7rem; font-size: .78rem; border-radius: 6px; }
.btn-xs { padding: .2rem .5rem; font-size: .72rem; border-radius: 5px; }
.w-100 { width: 100%; justify-content: center; }
.mt-2 { margin-top: .5rem; }

/* ── Alerts ── */
.alert { padding: .75rem 1rem; border-radius: 8px; font-size: .875rem; margin-bottom: 1rem; display: flex; align-items: center; gap: .5rem; }
.alert-success { background: #D1FAE5; color: #065F46; border: 1px solid #A7F3D0; }
.alert-danger  { background: #FEE2E2; color: #991B1B; border: 1px solid #FECACA; }
.alert-warning { background: #FEF3C7; color: #92400E; border: 1px solid #FDE68A; }
.alert-info    { background: #DBEAFE; color: #1E40AF; border: 1px solid #BFDBFE; }
.alert-dismissible { position: relative; padding-right: 2.5rem; }
.btn-close { position: absolute; right: .75rem; top: 50%; transform: translateY(-50%); background: none; border: none; font-size: 1rem; cursor: pointer; opacity: .6; }
.btn-close:hover { opacity: 1; }

/* ── Pagination ── */
.pagination-wrap { padding: 1rem 1.25rem; display: flex; align-items: center; gap: .5rem; border-top: 1px solid var(--border); }
.page-link { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 6px; border: 1px solid var(--border); font-size: .8rem; color: #475569; text-decoration: none; }
.page-link:hover, .page-link.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-info { font-size: .8rem; color: var(--muted); margin-left: auto; }

/* ── Filter bar ── */
.filter-bar { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; margin-bottom: 1rem; display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.filter-bar .form-group { margin-bottom: 0; }

/* ── Void tag ── */
.tr-void td { opacity: .45; text-decoration: line-through; }

/* ── Countdown chip ── */
.next-report { display: inline-flex; align-items: center; gap: .4rem; background: #DBEAFE; color: #1E40AF; border-radius: 8px; padding: .4rem .75rem; font-size: .8rem; font-weight: 500; white-space: nowrap; }

/* ── Detail page ── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.detail-item { margin-bottom: .75rem; }
.detail-label { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: .2rem; }
.detail-value { font-size: .95rem; color: #1E293B; word-break: break-word; }
.bukti-thumb { border-radius: 8px; border: 1px solid var(--border); max-width: 100%; height: auto; cursor: pointer; object-fit: contain; }

/* ── Laporan ── */
.laporan-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.5rem; }

/* ── Color picker ── */
input[type="color"] { width: 2.5rem; height: 2rem; border: 1px solid var(--border); border-radius: 4px; padding: 2px; cursor: pointer; }

/* ── Utilities ── */
.text-success { color: var(--success) !important; }
.text-danger  { color: var(--danger) !important; }
.text-muted   { color: var(--muted) !important; }
.text-primary { color: var(--primary) !important; }
.text-right   { text-align: right; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.me-1 { margin-right: .25rem; }
.me-2 { margin-right: .5rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: .25rem; }
.mb-4 { margin-bottom: 1rem; }
.gap-2 { gap: .5rem; }
.d-flex { display: flex; }
.align-items-center { align-items: center; }
.justify-content-between { justify-content: space-between; }
.fade.show { display: flex; }

/* ── Mobile Layout Optimization ── */
@media (max-width: 768px) {
  /* Hide desktop-only elements */
  .sidebar-brand, .sidebar-saldo, .sidebar-user { display: none !important; }
  
  /* Main Layout */
  .app-wrapper { flex-direction: column; }
  .main-content { margin-left: 0; padding-bottom: 75px; } /* Space for bottom nav */
  .topbar { padding: 0.75rem 1rem; flex-wrap: wrap; gap: 0.5rem; }
  .topbar-title { font-size: 1rem; }
  .topbar-actions { flex-wrap: wrap; gap: 0.35rem; }
  .next-report { font-size: 0.72rem; padding: 0.25rem 0.5rem; }
  .page-body { padding: 0.875rem; }
  .login-card { padding: 2rem 1.5rem; }
  
  /* Grid Breakpoints */
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 0.75rem; }
  .kpi-card { padding: 1rem; }
  .kpi-value { font-size: 1.15rem; }
  .kpi-icon { font-size: 1.4rem; margin-top: -1.25rem; }
  .chart-grid { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; gap: 0.75rem; }
  .detail-grid { grid-template-columns: 1fr; gap: 1rem; }
  .laporan-summary { grid-template-columns: 1fr 1fr; gap: 0.75rem; }
  
  /* Filter bar on mobile */
  .filter-bar { padding: 0.75rem; gap: 0.5rem; }
  .filter-bar .form-group { flex: 1 1 calc(50% - 0.5rem); min-width: 120px; }
  .filter-bar .form-group:last-child { flex: 1 1 100%; display: flex; gap: 0.5rem; margin-top: 0.25rem; }
  .filter-bar .form-group:last-child .btn { flex: 1; justify-content: center; }
  
  /* Pagination on mobile */
  .pagination-wrap { flex-wrap: wrap; gap: 0.35rem; justify-content: center; padding: 0.75rem; }
  .page-info { width: 100%; text-align: center; margin-left: 0; margin-top: 0.25rem; font-size: 0.75rem; }

  /* Sidebar -> Bottom Nav */
  #sidebar {
    width: 100%;
    height: auto;
    top: auto; 
    bottom: 0;
    flex-direction: row;
    padding: 0;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    background: #ffffff;
    border-top: 1px solid var(--border);
    z-index: 1000;
  }
  
  .sidebar-nav {
    display: flex;
    flex-direction: row;
    width: 100%;
    padding: 0;
    margin: 0;
    justify-content: space-around;
    align-items: stretch;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .sidebar-nav li { 
    flex: 1 0 auto; 
    min-width: 44px;
    display: flex;
  }
  
  .nav-link {
    width: 100%;
    flex-direction: column;
    padding: 0.45rem 0.15rem;
    gap: 0.15rem;
    font-size: 0.6rem;
    font-weight: 500;
    justify-content: center;
    border-left: none;
    border-top: 3px solid transparent;
    color: var(--muted);
    text-align: center;
    white-space: nowrap;
  }
  
  .nav-link i { font-size: 1.15rem; width: auto; }
  
  .nav-link:hover {
    background: transparent;
    color: var(--primary);
  }
  
  .nav-link.active {
    border-left: none;
    border-top: 3px solid var(--accent);
    background: transparent;
    color: var(--accent);
  }
  
  .mobile-logout { display: block; }
  .mobile-logout .nav-link { color: var(--danger); }
}

@media (max-width: 420px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .laporan-summary { grid-template-columns: 1fr; }
  .filter-bar .form-group { flex: 1 1 100%; }
}

@media (min-width: 769px) {
  .mobile-logout { display: none; }
}
