:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --bg: #f4f5fb;
  --card-bg: #ffffff;
  --text-dark: #1e293b;
  --text-muted: #64748b;
  --border: #e5e7eb;
  --sidebar-w: 260px;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  background: var(--bg);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text-dark);
  margin: 0;
  min-height: 100vh;
}

/* ===== Layout ===== */
.app-wrapper { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #1e1b4b 0%, #312e81 100%);
  color: #e0e7ff;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: transform .25s ease;
}

.sidebar-brand {
  padding: 24px 22px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand .icon-box {
  width: 40px; height: 40px;
  background: rgba(255,255,255,.15);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.icon-box-brand {
  background: linear-gradient(135deg, #fb923c 0%, #ea580c 100%) !important;
  color: #fff !important;
  font-weight: 800;
  font-size: 15px !important;
  letter-spacing: .02em;
  box-shadow: 0 4px 10px rgba(234, 88, 12, .35);
}
.sidebar-brand .title { font-weight: 700; font-size: 17px; line-height: 1.2; }
.sidebar-brand .subtitle { font-size: 11px; opacity: .7; }

.sidebar-nav { padding: 18px 12px; flex: 1; overflow-y: auto; }
.sidebar-nav .nav-section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: rgba(255,255,255,.45); padding: 10px 12px 6px;
}
.sidebar-nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 10px;
  color: #c7d2fe; text-decoration: none;
  font-size: 14.5px; font-weight: 500;
  margin-bottom: 3px;
  transition: all .15s ease;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-nav a.active { background: #fff; color: var(--primary-dark); font-weight: 600; }
.sidebar-nav a i { width: 18px; text-align: center; font-size: 16px; }

.sidebar-user {
  padding: 16px 18px; border-top: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-user .avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; flex-shrink: 0;
}
.sidebar-user .name { font-size: 13.5px; font-weight: 600; color: #fff; }
.sidebar-user .role { font-size: 11.5px; color: rgba(255,255,255,.55); text-transform: capitalize; }

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 16px 28px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 900;
}
.topbar .page-title { font-size: 20px; font-weight: 700; margin: 0; }
.topbar .page-desc { font-size: 13px; color: var(--text-muted); margin: 2px 0 0; }
.btn-toggle-sidebar {
  display: none; background: none; border: none; font-size: 22px; color: var(--text-dark); cursor: pointer;
}

.content-area { padding: 26px 28px 40px; flex: 1; }

/* ===== Cards ===== */
.card-modern {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}
.card-modern .card-header-modern {
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
}
.card-modern .card-header-modern h5 { margin: 0; font-weight: 700; font-size: 16px; }
.card-modern .card-body-modern { padding: 22px; }

/* ===== Stat Cards ===== */
.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  display: flex; align-items: center; gap: 16px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}
.stat-card .stat-icon {
  width: 52px; height: 52px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}
.stat-card .stat-value { font-size: 22px; font-weight: 800; line-height: 1.1; }
.stat-card .stat-label { font-size: 13px; color: var(--text-muted); margin-top: 3px; }

.bg-soft-primary { background: #eef2ff; color: #4f46e5; }
.bg-soft-success { background: #dcfce7; color: #16a34a; }
.bg-soft-warning { background: #fef3c7; color: #d97706; }
.bg-soft-danger  { background: #fee2e2; color: #dc2626; }

/* ===== Buttons ===== */
.btn-primary-modern {
  background: var(--primary); border: none; color: #fff;
  padding: 10px 18px; border-radius: 10px; font-weight: 600; font-size: 14px;
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none;
  transition: background .15s ease;
}
.btn-primary-modern:hover { background: var(--primary-dark); color: #fff; }

/* ===== Table ===== */
.table-modern { width: 100%; border-collapse: separate; border-spacing: 0; }
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}
.table-modern thead th {
  background: #f8fafc; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); padding: 12px 16px; border-bottom: 1px solid var(--border);
  font-weight: 700; white-space: nowrap;
}
.table-modern tbody td {
  padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle;
}
.table-modern tbody tr:hover { background: #fafafe; }
.table-modern tbody tr:last-child td { border-bottom: none; }
.table-modern tbody tr.row-spj-done { background: #dcfce7; }
.table-modern tbody tr.row-spj-done:hover { background: #bbf7d0; }
.table-modern tbody tr.row-spj-pending { background: #fef9c3; }
.table-modern tbody tr.row-spj-pending:hover { background: #fef08a; }

/* ===== Checkbox oranye pada form Buat/Edit SPJ ===== */
.group-toggle,
.rapat-checkbox {
  border: 2px solid #f97316 !important;
  accent-color: #f97316;
}
.group-toggle:checked,
.rapat-checkbox:checked {
  background-color: #f97316 !important;
  border-color: #f97316 !important;
}
.group-toggle:focus,
.rapat-checkbox:focus {
  border-color: #f97316 !important;
  box-shadow: 0 0 0 3px rgba(249, 115, 22, .2) !important;
}

.badge-soft {
  padding: 5px 11px; border-radius: 20px; font-size: 12px; font-weight: 600;
}

/* ===== Forms ===== */
.form-label-modern { font-weight: 600; font-size: 13.5px; margin-bottom: 6px; display: block; }
.form-control, .form-select {
  border-radius: 10px; border: 1px solid var(--border); padding: 10px 14px; font-size: 14px;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}

/* ===== Login Page ===== */
.login-wrapper {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #4338ca 0%, #6366f1 50%, #818cf8 100%);
  padding: 20px;
}
.login-card {
  background: #fff; border-radius: 20px; padding: 40px 36px;
  width: 100%; max-width: 400px;
  box-shadow: 0 20px 60px rgba(30, 27, 75, 0.35);
}
.login-icon {
  width: 60px; height: 60px; border-radius: 16px; margin: 0 auto 18px;
  background: var(--primary-light); color: var(--primary);
  display: flex; align-items: center; justify-content: center; font-size: 28px;
}
.login-icon-brand {
  background: linear-gradient(135deg, #fb923c 0%, #ea580c 100%);
  color: #fff;
  font-weight: 800;
  font-size: 22px;
  box-shadow: 0 6px 16px rgba(234, 88, 12, .3);
}

/* Calc box in form */
.calc-box {
  background: var(--primary-light); border: 1px dashed #c7d2fe;
  border-radius: 12px; padding: 16px 18px;
}
.calc-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.calc-row.total { border-top: 1px solid #c7d2fe; margin-top: 6px; padding-top: 10px; font-weight: 700; font-size: 15px; }

@media (max-width: 991px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.show { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .btn-toggle-sidebar { display: block; }
}

/* ===== Sidebar overlay backdrop (mobile) ===== */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .45);
  z-index: 999;
}
.sidebar-backdrop.show { display: block; }

/* ===== Mobile fine-tuning (phones) ===== */
@media (max-width: 767px) {
  .topbar {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 10px;
  }
  .topbar .page-title { font-size: 17px; }
  .topbar .page-desc { font-size: 12px; }
  .topbar > div[style] { width: auto; }

  .content-area { padding: 16px 14px 32px; }

  .card-modern .card-header-modern {
    padding: 14px 16px;
    flex-direction: column;
    align-items: stretch;
  }
  .card-modern .card-header-modern form { width: 100%; }
  .card-modern .card-header-modern form input { min-width: 0 !important; flex: 1; }
  .card-modern .card-body-modern { padding: 16px; }

  .stat-card { padding: 16px; gap: 12px; }
  .stat-card .stat-icon { width: 44px; height: 44px; font-size: 18px; }
  .stat-card .stat-value { font-size: 18px; }

  .table-modern thead th, .table-modern tbody td {
    padding: 10px 12px;
    font-size: 13px;
  }

  .btn-primary-modern, .btn { font-size: 13.5px; }

  /* Form grid: full width fields, comfortable tap targets */
  .row.g-3 > [class*="col-"] { margin-bottom: 2px; }
  .form-control, .form-select { padding: 11px 14px; font-size: 16px; } /* 16px avoids iOS auto-zoom */

  .d-flex.gap-2.mt-4 { flex-wrap: wrap; }
  .d-flex.gap-2.mt-4 .btn, .d-flex.gap-2.mt-4 a { flex: 1; text-align: center; justify-content: center; }
}

@media (max-width: 480px) {
  .login-card { padding: 30px 22px; border-radius: 16px; }
  .login-icon { width: 52px; height: 52px; font-size: 18px; }
  .sidebar-brand { padding: 20px 16px; }
  .content-area { padding: 14px 10px 28px; }
  .calc-box { padding: 14px; }
  .calc-row { font-size: 13px; }
}

/* Larger tap targets across the app on touch devices */
@media (hover: none) and (pointer: coarse) {
  .btn, .btn-primary-modern, a.btn-primary-modern, .form-control, .form-select {
    min-height: 44px;
  }
  .table-modern .btn-sm { min-height: 36px; min-width: 36px; }
}
