:root {
  --brand-deep: #0d2137;
  --brand-cyan: #0891b2;
  --brand-cyan-light: #22d3ee;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #dc2626;
  --warn: #f59e0b;
  --success: #10b981;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: var(--text); background: var(--bg); font-size: 14px; }
a { color: var(--brand-cyan); text-decoration: none; }
code { background: #eef2ff; padding: 1px 6px; border-radius: 4px; font-size: 0.9em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.money { font-variant-numeric: tabular-nums; }

/* Auth */
.auth-bg { min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--brand-deep), var(--brand-cyan)); }
.auth-card { background: var(--surface); padding: 40px; border-radius: 16px; width: 400px; max-width: 92vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.auth-brand { text-align: center; margin-bottom: 32px; }
.auth-logo { display: inline-flex; width: 64px; height: 64px; align-items: center; justify-content: center;
  background: var(--brand-cyan); color: white; font-weight: 800; font-size: 20px; border-radius: 16px; }
.auth-brand h1 { margin: 16px 0 4px; font-size: 22px; }
.auth-card label { display: block; margin-top: 14px; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.auth-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px; }
.auth-card input:focus { outline: 2px solid var(--brand-cyan); border-color: transparent; }
.auth-card button { margin-top: 20px; width: 100%; padding: 12px; background: var(--brand-cyan); color: white;
  border: 0; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 15px; }
.auth-card button:hover { background: #0e7490; }
.err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }
.auth-card .footer { margin-top: 24px; text-align: center; font-size: 12px; }

/* App shell */
body { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--brand-deep); color: white; padding: 20px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding-bottom: 16px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-logo { width: 40px; height: 40px; background: var(--brand-cyan); border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 12px; }
.sidebar-title { font-weight: 700; font-size: 14px; }
.sidebar-sub { font-size: 11px; opacity: 0.7; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; margin-top: 14px; flex: 1; }
.sidebar-nav a { padding: 9px 12px; border-radius: 8px; color: rgba(255,255,255,0.75); font-size: 13px; }
.sidebar-nav a:hover { background: rgba(255,255,255,0.08); color: white; }
.sidebar-nav a.active { background: var(--brand-cyan); color: white; }
.sidebar-user { border-top: 1px solid rgba(255,255,255,0.1); padding-top: 12px; font-size: 12px; }
.sidebar-user .muted { color: rgba(255,255,255,0.6); margin-bottom: 8px; }
.btn-secondary { width: 100%; background: transparent; color: white; border: 1px solid rgba(255,255,255,0.2);
  padding: 7px; border-radius: 8px; cursor: pointer; font-size: 12px; }
.btn-secondary:hover { background: rgba(255,255,255,0.05); }
button.btn-primary { background: var(--brand-cyan); color: white; border: 0; padding: 8px 14px;
  border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 13px; }
button.btn-primary:hover { background: #0e7490; }
button.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
button.btn-primary.small, button.btn-secondary.small { padding: 4px 10px; font-size: 11px; width: auto; }
button.btn-secondary {
  display: inline-flex; align-items: center; gap: 4px;
}
.main button.btn-secondary { background: white; color: var(--text); border: 1px solid var(--border); width: auto; padding: 7px 12px; font-size: 13px; }
.main button.btn-secondary:hover { background: #f1f5f9; }

.main { padding: 24px 32px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.topbar h1 { margin: 0; font-size: 22px; }
.topbar-meta { font-size: 13px; }

.tab { display: none; }
.tab.active { display: block; }

/* Cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card { background: var(--surface); padding: 16px; border-radius: 10px; border: 1px solid var(--border); }
.stat-card.alert { border-left: 4px solid var(--warn); }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; font-weight: 600; }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat-value.money { font-size: 18px; }

.card { background: var(--surface); padding: 20px; border-radius: 10px; border: 1px solid var(--border); margin-bottom: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }
.card h2 { margin: 0 0 10px 0; font-size: 15px; }
.card.stub { background: #fef9c3; border-color: #fde047; }
.head-actions { display: flex; gap: 8px; align-items: center; }

.master-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.master-grid .card { margin-bottom: 0; }
.master-list { list-style: none; padding: 0; margin: 0; }
.master-list li { padding: 8px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.master-list li:last-child { border: 0; }
.master-list .del { background: transparent; border: 0; color: var(--danger); cursor: pointer; font-size: 12px; }

/* Forms */
.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.form-row input, .form-row select { padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; min-width: 140px; }
input.search { padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; width: 220px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.form-grid > div { display: flex; flex-direction: column; }
.form-grid .col2 { grid-column: span 2; }
.form-grid label { font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 3px; text-transform: uppercase; letter-spacing: 0.3px; }
.form-grid input, .form-grid select { padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { background: #f8fafc; font-weight: 600; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.3px; }
tbody tr:hover { background: #f8fafc; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; }
.badge.success { background: #dcfce7; color: #15803d; }
.badge.warn { background: #fef3c7; color: #b45309; }
.badge.danger { background: #fee2e2; color: #b91c1c; }
.badge.info { background: #dbeafe; color: #1d4ed8; }
.badge.muted { background: #f1f5f9; color: var(--muted); }

/* Modal */
.modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(15,23,42,0.5); z-index: 100; align-items: flex-start; justify-content: center; overflow-y: auto; padding: 40px 20px; }
.modal-backdrop.open { display: flex; }
.modal { background: white; border-radius: 12px; width: 100%; max-width: 700px; overflow: hidden; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-close { background: transparent; border: 0; cursor: pointer; font-size: 18px; color: var(--muted); }
.modal-body { padding: 20px; max-height: 70vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); background: #f8fafc; }
.modal-foot button { padding: 8px 18px; width: auto; }

.action-btn { background: transparent; border: 1px solid var(--border); padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 11px; margin-right: 4px; display: inline-block; text-decoration: none; color: var(--text); }
.action-btn:hover { background: #f1f5f9; }
.action-btn.approve { color: var(--success); border-color: var(--success); }
.action-btn.reject { color: var(--danger); border-color: var(--danger); }
.action-btn.primary { color: var(--brand-cyan); border-color: var(--brand-cyan); }

/* Settings grid + field layout */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; margin-bottom: 14px; }
.settings-grid .card { margin-bottom: 0; }
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 3px; text-transform: uppercase; letter-spacing: 0.3px; }
.field input, .field select { width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }

/* Info box */
.info-box { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e3a8a; padding: 10px 14px; border-radius: 8px; font-size: 12px; margin-bottom: 12px; line-height: 1.6; }

/* Modal tabs */
.modal-lg { max-width: 900px; }
.modal-tabs { display: flex; border-bottom: 1px solid var(--border); background: #f8fafc; }
.modal-tabs a { padding: 10px 18px; font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; }
.modal-tabs a.active { color: var(--brand-cyan); border-bottom-color: var(--brand-cyan); background: white; font-weight: 600; }
.mtab { display: none; }
.mtab.active { display: block; }

/* Payroll timeline (inline steps) */
.payroll-timeline { display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  font-size: 11px; margin-top: 4px; color: var(--muted); }
.payroll-timeline .tl-step { display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 8px; border-radius: 99px; background: #f1f5f9; }
.payroll-timeline .tl-step.done { background: #dcfce7; color: #15803d; }
.payroll-timeline .tl-step.pending { background: #fef3c7; color: #b45309; opacity: 0.85; }
.payroll-timeline .tl-sep { color: #cbd5e1; font-size: 10px; }

/* Download menu dropdown */
.dl-menu { display: none; position: absolute; top: 100%; right: 0; margin-top: 4px;
  background: white; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1); min-width: 220px; z-index: 20; overflow: hidden; }
.dl-menu a { display: block; padding: 10px 14px; font-size: 13px; color: var(--text);
  border-bottom: 1px solid var(--border); }
.dl-menu a:last-child { border-bottom: 0; }
.dl-menu a:hover { background: #f1f5f9; color: var(--brand-cyan); }

/* Components list */
.comp-list { list-style: none; padding: 0; margin: 0; }
.comp-list li { padding: 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.comp-list .comp-amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.comp-list .pos { color: var(--success); }
.comp-list .neg { color: var(--danger); }

/* ============ Mobile responsive ============ */
@media (max-width: 900px) {
  body { grid-template-columns: 1fr !important; }
  .sidebar {
    position: fixed !important; top: 0; left: 0; right: 0; height: auto;
    z-index: 50; padding: 12px; flex-direction: column;
  }
  .sidebar-brand { padding-bottom: 10px; margin-bottom: 0; }
  .sidebar-nav {
    flex-direction: row; flex-wrap: wrap; gap: 4px;
    max-height: 0; overflow: hidden; transition: max-height 0.3s;
    margin-top: 0;
  }
  .sidebar.open .sidebar-nav { max-height: 500px; margin-top: 10px; }
  .sidebar-nav a { padding: 8px 12px; font-size: 13px; flex: 1 1 45%; }
  .sidebar-user {
    display: flex; gap: 6px; padding-top: 8px;
    position: absolute; top: 10px; right: 10px; border: 0;
  }
  .sidebar-user button { width: auto; }
  .sidebar-user .muted { display: none; }
  .sidebar::after {
    content: '☰ Menu'; position: absolute; top: 18px; left: 60px;
    color: white; cursor: pointer; font-size: 14px; font-weight: 600;
  }
  .main { padding: 100px 16px 20px; min-width: 0; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-value { font-size: 20px; }
  .form-grid { grid-template-columns: 1fr !important; }
  .form-grid .col2 { grid-column: span 1 !important; }
  .settings-grid { grid-template-columns: 1fr !important; }
  .master-grid { grid-template-columns: 1fr !important; }
  .modal { max-width: 95vw !important; }
  .modal-lg { max-width: 95vw !important; }
  .form-row { flex-direction: column; align-items: stretch; }
  .form-row > * { width: 100%; }
  table { font-size: 12px; }
  th, td { padding: 6px 8px; }
  /* Horizontal scroll buat table yang lebar */
  .card { overflow-x: auto; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 4px; }
  input.search { width: 100%; }
}

@media (max-width: 500px) {
  .stat-grid { grid-template-columns: 1fr; }
  .sidebar-nav a { flex: 1 1 100%; }
}
