:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --bg: #f4f5f9;
  --sidebar-bg: #14162b;
  --sidebar-bg-alt: #1b1e3a;
  --sidebar-text: #a5a8c9;
  --sidebar-active: #4f46e5;
  --border: #e6e8f0;
  --success: #16a34a;
  --success-light: #dcfce7;
  --error: #dc2626;
  --error-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --info: #0891b2;
  --info-light: #cffafe;
  --purple: #9333ea;
  --purple-light: #f3e8ff;
  --text: #1e2130;
  --text-muted: #6b7280;
  --sidebar-width: 252px;
  --sidebar-width-collapsed: 0px;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }

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

/* ---------- SIDEBAR ---------- */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  overflow-y: auto;
  overflow-x: hidden;
  transition: margin-left .22s ease, width .22s ease, min-width .22s ease;
  position: relative;
  scrollbar-width: thin;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: #2b2e52; border-radius: 3px; }

/* Desktop (>860px): sidebar tampil default, sidebar-collapsed = disembunyikan */
@media (min-width: 861px) {
  .sidebar { margin-left: 0; }
  body.sidebar-collapsed .sidebar {
    margin-left: calc(-1 * var(--sidebar-width));
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
  }
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-brand .logo-mark {
  width: 34px; height: 34px; flex-shrink: 0;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 10px rgba(79,70,229,.4);
}
.sidebar-brand .logo-mark img { display: block; border-radius: 9px; }
.sidebar-brand .logo-text { display: flex; flex-direction: column; line-height: 1.15; }
.sidebar-brand .logo-text strong { color: #fff; font-size: 15px; font-weight: 700; letter-spacing: .2px; }
.sidebar-brand .logo-text span { color: var(--sidebar-text); font-size: 11px; }

.sidebar-nav { padding: 8px 0 28px; }

/* Seksi utama: Dashboard / Radius / Billing / Utility - judul besar + garis pembatas */
.nav-section { padding: 6px 0; }
.nav-section-title {
  padding: 12px 20px 6px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  letter-spacing: .01em;
}
.nav-section-divider { height: 1px; background: rgba(255,255,255,.09); margin: 6px 18px 2px; }

/* Sub-grup accordion di dalam sebuah seksi (mis. PPPoE, Hotspot, Setting di dalam Radius) */
.nav-group-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 20px;
  margin: 1px 10px;
  border-radius: 8px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--sidebar-text);
  text-align: left;
}
.nav-group-header:hover { background: var(--sidebar-bg-alt); color: #fff; }
.nav-group-header .chevron { flex-shrink: 0; transition: transform .2s ease; color: inherit; opacity: .7; transform: rotate(-90deg); }
.nav-group.open .nav-group-header .chevron { transform: rotate(0deg); }
.nav-group.open .nav-group-header {
  background: linear-gradient(90deg, rgba(79,70,229,.28), rgba(79,70,229,.05));
  color: #fff;
  font-weight: 600;
}
.nav-group-header .group-icon { flex-shrink: 0; opacity: .8; }
.nav-group-header .header-main { display: flex; align-items: center; gap: 10px; }
.nav-link .link-icon { flex-shrink: 0; opacity: .8; }
.nav-group-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height .28s ease;
}
.nav-group.open .nav-group-body { max-height: 640px; }
.nav-group-body-inner { padding: 2px 0 6px 14px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  margin: 1px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--sidebar-text);
}
.nav-link:hover { background: var(--sidebar-bg-alt); color: #fff; }
.nav-link:hover .link-icon { opacity: 1; }
.nav-link.active { background: linear-gradient(90deg, rgba(79,70,229,.28), rgba(79,70,229,.05)); color: #fff; font-weight: 600; }
.nav-link.active .link-icon { opacity: 1; color: #a5b4fc; }

/* ---------- MAIN ---------- */
.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; transition: margin-left .22s ease; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  gap: 16px;
}
.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.sidebar-toggle {
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  color: var(--text);
}
.sidebar-toggle:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.topbar-title { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-user { display: flex; gap: 14px; align-items: center; font-size: 14px; flex-shrink: 0; }
.topbar-user .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.topbar-user .user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.topbar-user .user-meta strong { font-size: 13px; }
.topbar-user .user-meta small { color: var(--text-muted); font-size: 11px; }

.content { padding: 24px; max-width: 1400px; }

/* ---------- CARDS ---------- */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(16,24,40,.04);
  /* Tabel lebar di dalam card akan scroll horizontal sendiri, bukan mendorong layout melebar */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.card table { min-width: 560px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }

.widget-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: 0 1px 2px rgba(16,24,40,.04);
  position: relative;
  overflow: hidden;
}
.widget-card::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--accent, var(--primary));
}
.widget-card .icon-badge {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-light, var(--primary-light));
  color: var(--accent, var(--primary));
  margin-bottom: 12px;
}
.widget-card .label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
.widget-card .value { font-size: 25px; font-weight: 800; margin-top: 4px; letter-spacing: -.3px; }
.widget-card.accent-primary { --accent: #4f46e5; --accent-light: #eef2ff; }
.widget-card.accent-success { --accent: #16a34a; --accent-light: #dcfce7; }
.widget-card.accent-warning { --accent: #d97706; --accent-light: #fef3c7; }
.widget-card.accent-error   { --accent: #dc2626; --accent-light: #fee2e2; }
.widget-card.accent-info    { --accent: #0891b2; --accent-light: #cffafe; }
.widget-card.accent-purple  { --accent: #9333ea; --accent-light: #f3e8ff; }

/* legacy stat-card kept as alias */
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-card .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; }
.stat-card .value { font-size: 24px; font-weight: 700; margin-top: 6px; }

.chart-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.chart-card h3 { margin: 0 0 4px; font-size: 15px; }
.chart-card p.sub { margin: 0 0 16px; color: var(--text-muted); font-size: 12.5px; }
.chart-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-bottom: 24px; }
@media (max-width: 900px) { .chart-grid { grid-template-columns: 1fr; } }

/* ---------- TABLE ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--border); text-align: left; }
th { background: #fafbfd; font-weight: 700; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); }
tr:hover td { background: #fafbff; }

/* ---------- BADGES ---------- */
.badge { padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; display: inline-block; letter-spacing: .02em; }
.badge-active, .badge-paid, .badge-success { background: var(--success-light); color: #166534; }
.badge-isolir, .badge-overdue, .badge-failed { background: var(--error-light); color: #991b1b; }
.badge-suspend, .badge-unpaid, .badge-pending { background: var(--warning-light); color: #92400e; }
.badge-nonaktif, .badge-cancelled { background: #e5e7eb; color: #374151; }

/* ---------- BUTTONS ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--primary); background: var(--primary); color: #fff; font-size: 13.5px; font-weight: 600; cursor: pointer; transition: background .15s, box-shadow .15s; }
.btn:hover { background: var(--primary-dark); box-shadow: 0 2px 8px rgba(79,70,229,.35); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f8f9fc; box-shadow: none; }
.btn-danger { background: var(--error); border-color: var(--error); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 14px; padding: 0; font-weight: 600; }

/* ---------- FORMS ---------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 13.5px; font-weight: 600; }
.form-control { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13.5px; background: #fff; }
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 13.5px; font-weight: 500; }
.alert-success { background: var(--success-light); color: #166534; }
.alert-error { background: var(--error-light); color: #991b1b; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.toolbar .search { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; min-width: 220px; }

/* ---------- LOGIN ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: radial-gradient(circle at top left, #2d2f66, #14162b 60%); }
.login-card { background: #fff; padding: 38px; border-radius: 16px; width: 100%; max-width: 380px; box-shadow: 0 25px 60px rgba(0,0,0,.35); }
.login-card .logo-mark { width: 46px; height: 46px; border-radius: 12px; background: linear-gradient(135deg, #6366f1, #4f46e5); display: flex; align-items: center; justify-content: center; margin-bottom: 16px; box-shadow: 0 6px 14px rgba(79,70,229,.35); }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p { color: var(--text-muted); font-size: 13.5px; margin-top: 0; margin-bottom: 24px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.pagination { display: flex; gap: 6px; margin-top: 16px; }
.pagination a, .pagination span { padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; }
.pagination .active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- RESPONSIVE ---------- */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(15,17,35,.5);
  z-index: 30;
}

/* Modal/dialog (pakai class .card di dalam .modal-overlay, lebar diset inline
   per-halaman) - dibatasi supaya tidak kepotong di layar sempit */
.modal-overlay { padding: 16px; }
.modal-overlay .card { max-width: 92vw; max-height: 88vh; overflow-y: auto; }

@media (max-width: 860px) {
  .sidebar {
    position: fixed; z-index: 40; top: 0; bottom: 0; left: 0;
    margin-left: calc(-1 * var(--sidebar-width));
    box-shadow: 0 0 30px rgba(0,0,0,.3);
  }
  body.sidebar-collapsed .sidebar { margin-left: calc(-1 * var(--sidebar-width)); }
  body.sidebar-open .sidebar { margin-left: 0; }
  body.sidebar-open .sidebar-overlay { display: block; }
  .main-area { width: 100%; }
  .form-row { grid-template-columns: 1fr; }
  .content { padding: 14px; }
  .topbar { padding: 12px 14px; }
  .modal-overlay .card { width: 100% !important; }
}

@media (max-width: 480px) {
  .topbar-user .user-meta { display: none; }
  .toolbar .search { min-width: 0; flex: 1; }
  .card-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .widget-card { padding: 14px; }
  .widget-card .value { font-size: 19px; }
  .widget-card .icon-badge { width: 32px; height: 32px; margin-bottom: 8px; }
}

/* ================================================================
   WHATSAPP CHAT - tema hijau/teal terpisah dari palet utama aplikasi
   ================================================================ */
:root {
  --wa-header: #008069;
  --wa-panel: #f0f2f5;
  --wa-chat-bg: #efeae2;
  --wa-bubble-out: #d9fdd3;
  --wa-bubble-in: #ffffff;
  --wa-green-text: #008069;
}
.wa-chat {
  display: flex;
  height: calc(100vh - 120px);
  min-height: 480px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(16,24,40,.04);
  background: #fff;
}
.wa-sidebar { width: 320px; flex-shrink: 0; border-right: 1px solid #e9edef; display: flex; flex-direction: column; background: #fff; }
.wa-sidebar-header { background: var(--wa-panel); padding: 14px 14px 10px; }
.wa-sidebar-header h3 { margin: 0 0 10px; font-size: 16px; color: #111b21; }
.wa-search { width: 100%; padding: 8px 12px; border-radius: 20px; border: none; background: #fff; font-size: 13.5px; }
.wa-conv-list { flex: 1; overflow-y: auto; }
.wa-conv-item { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-bottom: 1px solid #f2f2f2; cursor: pointer; }
.wa-conv-item:hover { background: #f5f6f6; }
.wa-conv-item.active { background: #f0f2f5; }
.wa-conv-avatar { width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(135deg,#25d366,#008069); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.wa-conv-info { min-width: 0; flex: 1; }
.wa-conv-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.wa-conv-name { font-size: 14px; font-weight: 600; color: #111b21; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-conv-time { font-size: 11px; color: #667781; flex-shrink: 0; }
.wa-conv-preview { font-size: 12.5px; color: #667781; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.wa-conv-badge { display: inline-block; background: var(--sidebar-active); color: #fff; border-radius: 999px; font-size: 10px; padding: 1px 6px; margin-left: 6px; }

.wa-thread { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--wa-chat-bg); background-image: radial-gradient(rgba(0,0,0,.02) 1px, transparent 1px); background-size: 14px 14px; }
.wa-thread-header { background: var(--wa-panel); padding: 10px 18px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid #e9edef; }
.wa-thread-header .wa-conv-avatar { width: 38px; height: 38px; font-size: 13px; }
.wa-thread-header-name { font-size: 14.5px; font-weight: 600; color: #111b21; }
.wa-thread-header-sub { font-size: 12px; color: #667781; }
.wa-thread-body { flex: 1; overflow-y: auto; padding: 18px 8%; display: flex; flex-direction: column; gap: 2px; }
.wa-bubble-row { display: flex; margin-bottom: 6px; }
.wa-bubble-row.out { justify-content: flex-end; }
.wa-bubble { max-width: 65%; padding: 7px 9px 8px; border-radius: 9px; font-size: 13.7px; line-height: 1.4; position: relative; box-shadow: 0 1px 0.5px rgba(0,0,0,.08); }
.wa-bubble.in { background: var(--wa-bubble-in); border-top-left-radius: 0; }
.wa-bubble.out { background: var(--wa-bubble-out); border-top-right-radius: 0; }
.wa-bubble-meta { display: flex; justify-content: flex-end; gap: 4px; margin-top: 3px; font-size: 10.5px; color: #667781; }
.wa-thread-input { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--wa-panel); border-top: 1px solid #e9edef; }
.wa-thread-input input[type=text] { flex: 1; padding: 10px 14px; border-radius: 20px; border: none; font-size: 14px; background: #fff; }
.wa-thread-input button { background: var(--wa-header); color: #fff; border: none; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.wa-thread-input button:hover { background: #017561; }
.wa-empty-thread { flex: 1; display: flex; align-items: center; justify-content: center; flex-direction: column; color: #667781; gap: 10px; }

@media (max-width: 860px) {
  .wa-chat { height: calc(100vh - 160px); flex-direction: column; }
  .wa-sidebar { width: 100%; height: 40%; }
  .wa-thread { height: 60%; }
}
