/* ============================================================
   KINGNET - Unified Design System
   One stylesheet for the whole app: login, admin dashboard,
   customer portal, and every module page.
   ============================================================ */

:root{
  --bg:            #020617;
  --bg-soft:       #0b1224;
  --surface:       #0f172a;
  --surface-2:     #131f37;
  --border:        rgba(255,255,255,.08);
  --border-soft:   rgba(255,255,255,.05);
  --text:          #f1f5f9;
  --text-dim:      #94a3b8;
  --text-faint:    #64748b;

  --primary:       #22c55e;
  --primary-dark:  #16a34a;
  --primary-soft:  rgba(34,197,94,.12);
  --accent:        #3b82f6;
  --accent-soft:   rgba(59,130,246,.12);
  --warn:          #f59e0b;
  --warn-soft:     rgba(245,158,11,.12);
  --danger:        #ef4444;
  --danger-soft:   rgba(239,68,68,.12);

  --radius-sm: 10px;
  --radius:    16px;
  --radius-lg: 22px;
  --shadow:    0 20px 50px rgba(0,0,0,.45);

  --sidebar-w: 260px;
  --topbar-h:  64px;
  --bottomnav-h: 66px;

  --scrollbar-thumb: #1e293b;
  --hover-overlay: rgba(255,255,255,.02);
}

/* ===== LIGHT MODE ===== */
[data-theme="light"]{
  --bg:            #f1f5f9;
  --bg-soft:       #ffffff;
  --surface:       #ffffff;
  --surface-2:     #f8fafc;
  --border:        rgba(15,23,42,.10);
  --border-soft:   rgba(15,23,42,.06);
  --text:          #0f172a;
  --text-dim:      #64748b;
  --text-faint:    #94a3b8;

  --primary:       #16a34a;
  --primary-dark:  #15803d;
  --primary-soft:  rgba(22,163,74,.10);
  --accent:        #2563eb;
  --accent-soft:   rgba(37,99,235,.10);
  --warn:          #d97706;
  --warn-soft:     rgba(217,119,6,.10);
  --danger:        #dc2626;
  --danger-soft:   rgba(220,38,38,.10);

  --shadow: 0 12px 30px rgba(15,23,42,.10);
  --scrollbar-thumb: #cbd5e1;
  --hover-overlay: rgba(15,23,42,.03);
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: system-ui,-apple-system,'Segoe UI',Roboto,sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing:antialiased;
  overflow-x:hidden;
}
a{ color:inherit; }
img{ max-width:100%; }
button{ font-family:inherit; }

::-webkit-scrollbar{ width:8px; height:8px; }
::-webkit-scrollbar-thumb{ background:var(--scrollbar-thumb); border-radius:8px; }

/* ============================================================
   APP SHELL: sidebar + topbar + main + mobile bottom-nav
   ============================================================ */
.app{
  display:flex;
  min-height:100vh;
}

.sidebar{
  position:fixed;
  top:0; left:0; bottom:0;
  width:var(--sidebar-w);
  background:var(--bg);
  border-right:1px solid var(--border-soft);
  padding:26px 18px;
  overflow-y:auto;
  z-index:200;
  transition:transform .25s ease;
}
.sidebar .logo{
  display:flex; align-items:center; gap:10px;
  font-size:20px; font-weight:800; letter-spacing:.5px;
  color:var(--primary);
  margin-bottom:8px; padding:0 8px;
}
.sidebar .logo-sub{
  font-size:11px; color:var(--text-faint);
  padding:0 8px; margin-bottom:26px;
}
.side-group-label{
  font-size:11px; text-transform:uppercase; letter-spacing:.08em;
  color:var(--text-faint); margin:18px 10px 8px;
}
.side-link{
  position:relative;
  display:flex; align-items:center; gap:13px;
  padding:11px 14px; border-radius:12px;
  text-decoration:none; color:var(--text-dim);
  font-size:14.5px; margin-bottom:4px;
  transition:.15s;
}
.side-link svg{ width:19px; height:19px; stroke:currentColor; flex:none; }
.side-link:hover{ background:var(--surface); color:var(--text); }
.side-link.active{ background:var(--primary-soft); color:var(--primary); font-weight:600; }
.side-link.active::before{
  content:""; position:absolute; left:-18px; top:8px; bottom:8px; width:4px;
  background:var(--primary); border-radius:0 4px 4px 0;
}
.side-link .badge{ margin-left:auto; }

/* ===== COLLAPSIBLE SIDEBAR GROUPS ===== */
.side-group{ margin-bottom:4px; }
.side-group-toggle{
  box-sizing:border-box;
  position:relative;
  display:flex; align-items:center; gap:13px; width:100%;
  padding:11px 14px; border-radius:12px;
  cursor:pointer; user-select:none;
  color:var(--text-dim); font-size:14.5px; line-height:1.3;
  background:none; border:none; margin:0;
  transition:background .15s, color .15s;
}
.side-group-toggle svg.side-group-icon{ width:19px; height:19px; stroke:currentColor; flex:none; }
.side-group-toggle:hover{ background:var(--surface); color:var(--text); }
.side-group-toggle .chevron{
  margin-left:auto; width:15px; height:15px; stroke:currentColor; flex:none;
  transition:transform .15s;
}
.side-group.open > .side-group-toggle .chevron{ transform:rotate(90deg); }
.side-group.has-active > .side-group-toggle{ background:var(--primary-soft); color:var(--primary); font-weight:600; }
.side-subnav{
  padding-left:14px;
  max-height:0; overflow:hidden;
  transition:max-height .2s ease;
}
.side-group.open > .side-subnav{ max-height:600px; margin-top:2px; }
.side-subnav .side-link{ padding:9px 14px; font-size:13.5px; }
.side-subnav .side-link svg{ width:16px; height:16px; }

.main{
  flex:1;
  margin-left:var(--sidebar-w);
  padding:28px 32px 90px;
  max-width:1400px;
  width:100%;
}

.topbar{
  display:flex; align-items:center; gap:14px;
  margin-bottom:24px;
  position:sticky; top:0; z-index:120;
  background:var(--bg);
  padding:8px 0 16px;
}
.topbar .menu-toggle{
  display:none;
  background:var(--surface); border:1px solid var(--border);
  color:var(--text); border-radius:10px; padding:9px 11px;
  cursor:pointer;
  flex:none;
}
.topbar .grow{ flex:1; min-width:0; }
.page-title{
  font-size:24px; font-weight:800; margin:0;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.page-subtitle{
  color:var(--text-dim); margin-top:3px; font-size:13.5px;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}

.theme-toggle{
  display:inline-flex; align-items:center; justify-content:center;
  width:38px; height:38px; flex:none; margin-right:14px;
  background:var(--surface); border:1px solid var(--border);
  color:var(--text-dim); border-radius:10px; cursor:pointer;
  transition:background .15s, color .15s;
}
.theme-toggle:hover{ color:var(--text); background:var(--surface-2); }
.theme-toggle .icon-sun{ display:block; }
.theme-toggle .icon-moon{ display:none; }
[data-theme="light"] .theme-toggle .icon-sun{ display:none; }
[data-theme="light"] .theme-toggle .icon-moon{ display:block; }
.topbar-user{
  display:flex; align-items:center; gap:10px;
  background:var(--surface); border:1px solid var(--border);
  padding:8px 14px 8px 10px; border-radius:999px; font-size:13.5px;
}
.topbar-user .avatar{
  width:28px; height:28px; border-radius:50%;
  background:var(--primary-soft); color:var(--primary);
  display:flex; align-items:center; justify-content:center;
  font-weight:700; font-size:12.5px;
}
.role-pill{
  font-size:11px; padding:2px 9px; border-radius:999px;
  background:var(--accent-soft); color:#93c5fd; font-weight:600;
  text-transform:capitalize;
}

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

/* Mobile bottom nav */
.bottom-nav{
  display:none;
  position:fixed; bottom:0; left:0; right:0; height:var(--bottomnav-h);
  background:var(--bg); border-top:1px solid var(--border-soft);
  align-items:stretch; z-index:150;
  padding-bottom:env(safe-area-inset-bottom);
  padding-left:env(safe-area-inset-left);
  padding-right:env(safe-area-inset-right);
  box-shadow:0 -4px 20px rgba(0,0,0,.25);
}
.bottom-nav a{
  flex:1 1 0;
  min-width:0;
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:3px;
  text-decoration:none; color:var(--text-faint); font-size:10px;
  padding:6px 2px;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.bottom-nav a svg{ width:21px; height:21px; stroke:currentColor; flex:none; }
.bottom-nav a span{ overflow:hidden; text-overflow:ellipsis; max-width:100%; }
.bottom-nav a.active{ color:var(--primary); }

@media (max-width:980px){
  .sidebar{ transform:translateX(-100%); }
  .sidebar.open{ transform:translateX(0); box-shadow:var(--shadow); }
  .sidebar-overlay.open{ display:block; }
  .main{ margin-left:0; padding:18px 16px 96px; }
  .topbar .menu-toggle{ display:inline-flex; }
  .bottom-nav{ display:flex; }
  .page-title{ font-size:18px; }
  .page-subtitle{ display:none; }
  .theme-toggle{ width:34px; height:34px; margin-right:8px; }
  .topbar-user{ padding:6px 10px 6px 6px; gap:6px; }
  .topbar-user .avatar{ width:24px; height:24px; font-size:11px; }
  .role-pill{ display:none; }
}
@media (max-width:400px){
  .topbar-user > div:not(.avatar){ max-width:70px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
}

/* ============================================================
   CARDS / GRID / STATS
   ============================================================ */
.card{
  background:var(--surface);
  border:1px solid var(--border-soft);
  border-radius:var(--radius);
  padding:22px;
  margin-bottom:22px;
}
.card-title{ font-size:16px; font-weight:700; margin:0 0 16px; display:flex; align-items:center; justify-content:space-between; gap:10px; flex-wrap:wrap;}
.card-title small{ font-weight:400; color:var(--text-dim); font-size:12.5px; }

.stats-grid{ display:grid; grid-template-columns:repeat(4,1fr); gap:16px; }
@media (max-width:980px){ .stats-grid{ grid-template-columns:repeat(2,1fr); gap:10px; } }
.stats-grid-3{ display:grid; grid-template-columns:repeat(3,1fr); gap:16px; }
@media (max-width:980px){ .stats-grid-3{ grid-template-columns:repeat(2,1fr); gap:10px; } }
@media (max-width:480px){ .stats-grid-3{ grid-template-columns:1fr; } }
.stat{
  background:var(--bg-soft); border:1px solid var(--border-soft);
  border-radius:var(--radius-sm); padding:18px; text-align:left;
}
.stat-icon{
  width:36px; height:36px; border-radius:10px; display:flex; align-items:center; justify-content:center;
  background:var(--primary-soft); color:var(--primary); margin-bottom:10px;
}
.stat-icon svg{ width:18px; height:18px; }
.stat-value{ font-size:24px; font-weight:800; }
.stat-label{ font-size:12.5px; color:var(--text-dim); margin-top:3px; }

.menu-grid{ display:grid; grid-template-columns:repeat(5,1fr); gap:12px; }
@media (max-width:980px){ .menu-grid{ grid-template-columns:repeat(3,1fr); } }
@media (max-width:560px){ .menu-grid{ grid-template-columns:repeat(2,1fr); } }
.menu-item{
  text-decoration:none; color:var(--text); text-align:center;
  padding:18px 8px; border-radius:14px; background:var(--bg-soft);
  border:1px solid var(--border-soft); transition:.15s;
}
.menu-item:hover{ background:var(--surface-2); transform:translateY(-2px); }
.menu-item svg{ width:26px; height:26px; stroke:var(--primary); margin-bottom:8px; }
.menu-item .menu-label{ font-size:12.5px; color:var(--text-dim); }

/* ============================================================
   BUTTONS / BADGES / ALERTS
   ============================================================ */
.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:8px;
  padding:11px 18px; border-radius:12px; border:1px solid transparent;
  font-size:14px; font-weight:600; cursor:pointer; text-decoration:none;
  transition:.15s;
}
.btn-primary{ background:var(--primary); color:#04140a; }
.btn-primary:hover{ background:var(--primary-dark); }
.btn-outline{ background:transparent; border-color:var(--border); color:var(--text); }
.btn-outline:hover{ background:var(--surface); }
.btn-danger{ background:var(--danger); color:#fff; }
.btn-danger:hover{ opacity:.9; }
.btn-sm{ padding:7px 12px; font-size:12.5px; border-radius:9px; }
.btn-block{ width:100%; }

.badge{ display:inline-flex; align-items:center; padding:3px 10px; border-radius:999px; font-size:11.5px; font-weight:700; }
.badge-success{ background:var(--primary-soft); color:var(--primary); }
.badge-warn{ background:var(--warn-soft); color:var(--warn); }
.badge-danger{ background:var(--danger-soft); color:var(--danger); }
.badge-muted{ background:rgba(148,163,184,.12); color:var(--text-dim); }

.alert{ padding:13px 16px; border-radius:12px; font-size:13.5px; margin-bottom:16px; border:1px solid transparent; }
.alert-danger{ background:var(--danger-soft); color:#fca5a5; border-color:rgba(239,68,68,.25); }
.alert-success{ background:var(--primary-soft); color:#86efac; border-color:rgba(34,197,94,.25); }
.alert-warn{ background:var(--warn-soft); color:#fcd34d; border-color:rgba(245,158,11,.25); }

/* ============================================================
   FORMS
   ============================================================ */
.form-group{ margin-bottom:16px; }
label{ display:block; font-size:13px; color:var(--text-dim); margin-bottom:6px; }
.input, input, input[type=text], input[type=password], input[type=email], input[type=number],
input[type=date], input[type=tel], select, textarea{
  width:100%; padding:12px 14px; border-radius:11px; border:1px solid var(--border);
  background:var(--bg-soft); color:var(--text); font-size:14.5px; outline:none;
}
input[type=checkbox], input[type=radio]{
  width:auto; padding:0; border:none; background:none; border-radius:0;
}
.input:focus, input:focus, select:focus, textarea:focus{ border-color:var(--primary); }

/* Chrome/Edge/Safari auto-apply a light yellow/white background to fields
   they recognize as login fields (name="username"/"password" especially) -
   this overrides it back to match the dark theme. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active{
  -webkit-text-fill-color: var(--text) !important;
  -webkit-box-shadow: 0 0 0px 1000px var(--bg-soft) inset !important;
  box-shadow: 0 0 0px 1000px var(--bg-soft) inset !important;
  caret-color: var(--text);
  transition: background-color 5000s ease-in-out 0s;
}
.form-row{ display:grid; grid-template-columns:1fr 1fr; gap:14px; }
@media (max-width:640px){ .form-row{ grid-template-columns:1fr; } }

/* ============================================================
   TABLES (responsive)
   ============================================================ */
.table-wrap{ overflow-x:auto; border-radius:var(--radius-sm); border:1px solid var(--border-soft); }
table.data-table{ width:100%; border-collapse:collapse; min-width:640px; font-size:13.5px; }
table.data-table th{
  text-align:left; padding:12px 14px; background:var(--bg-soft);
  color:var(--text-dim); font-weight:600; font-size:12px; text-transform:uppercase; letter-spacing:.04em;
  border-bottom:1px solid var(--border-soft); white-space:nowrap;
}
table.data-table td{ padding:12px 14px; border-bottom:1px solid var(--border-soft); vertical-align:middle; }
table.data-table tr:last-child td{ border-bottom:none; }
table.data-table tr:hover td{ background:var(--hover-overlay); }
table.data-table td a{ color:var(--text); text-decoration:none; font-weight:600; }
table.data-table td a:hover{ color:var(--primary); }
.table-actions{ display:flex; gap:8px; flex-wrap:wrap; }

/* ============================================================
   SHARED POPUP MODAL - used by any page needing a quick confirm
   or small-form popup (e.g. picking a payment method before
   marking something paid, editing a date, etc).
   ============================================================ */
.modal-overlay{
  display:none; position:fixed; inset:0; background:rgba(0,0,0,.55);
  z-index:1000; align-items:center; justify-content:center; padding:20px;
}
.modal-overlay.open{ display:flex; }
.modal-box{
  background:var(--bg); border:1px solid var(--border); border-radius:var(--radius);
  padding:22px; width:100%; max-width:400px; box-shadow:var(--shadow);
}

/* ============================================================
   DETAIL PAGES (customer detail, refill, etc) - shared 2-column
   layout + label:value rows, so any page can opt in with just
   the wrapper classes below instead of redefining this per-page.
   ============================================================ */
.pdetail-wrap{ max-width:1100px; }
.pdetail-grid{ display:grid; grid-template-columns:1fr 1fr; gap:16px; align-items:start; }
@media(max-width:900px){ .pdetail-grid{ grid-template-columns:1fr; } }

.info-row{
  display:flex; justify-content:space-between; align-items:center; gap:14px;
  padding:12px 0; border-bottom:1px solid var(--border-soft);
}
.info-row:last-child{ border-bottom:none; }
.info-row .info-label{ color:var(--text-dim); font-size:13px; flex:none; }
.info-row .info-value{ font-weight:600; font-size:14px; text-align:right; }

@media(max-width:640px){
  .card-title{ flex-direction:column; align-items:stretch; gap:12px; }
  .card-title .flex.gap-8{ display:grid !important; grid-template-columns:1fr 1fr; gap:8px; width:100%; }
  .card-title .flex.gap-8 .btn{ width:100%; text-align:center; margin:0; }
  .info-row{ flex-direction:column; align-items:flex-start; gap:3px; }
  .info-row .info-value{ text-align:left; }
}
.empty-state{ text-align:center; padding:40px 20px; color:var(--text-dim); }

/* ============================================================
   AUTH PAGES (login)
   ============================================================ */
.auth-body{ display:flex; align-items:center; justify-content:center; min-height:100vh; padding:20px; background:radial-gradient(circle at top left,#0f172a,#020617 55%);}
.auth-wrapper{
  width:100%; max-width:980px; background:var(--bg);
  border-radius:var(--radius-lg); overflow:hidden; display:flex; box-shadow:var(--shadow);
  border:1px solid var(--border-soft);
}
.auth-left{
  flex:1; padding:60px 50px; color:#fff; display:flex; flex-direction:column; justify-content:center;
  background:
    radial-gradient(circle at top left,rgba(34,197,94,.2),transparent 40%),
    radial-gradient(circle at bottom right,rgba(59,130,246,.2),transparent 40%),
    var(--bg);
}
.auth-brand-icon{ font-size:56px; color:var(--primary); margin-bottom:14px; }
.auth-brand-title{ font-size:32px; font-weight:800; letter-spacing:.5px; }
.auth-brand-sub{ color:var(--text-dim); margin-top:10px; line-height:1.7; font-size:14.5px; }
.auth-role-list{ margin-top:26px; display:flex; flex-direction:column; gap:10px; }
.auth-role-list div{ display:flex; align-items:center; gap:10px; font-size:13px; color:var(--text-dim); }
.auth-role-list .dot{ width:7px; height:7px; border-radius:50%; background:var(--primary); }

.auth-right{ flex:1; background:var(--surface); padding:56px 48px; display:flex; flex-direction:column; justify-content:center; }
.auth-form-title{ font-size:24px; font-weight:700; margin-bottom:5px; }
.auth-form-sub{ color:var(--text-dim); font-size:13.5px; margin-bottom:24px; }

.access-denied-card{ text-align:center; max-width:420px; margin:0 auto; padding:30px; }
.access-denied-code{ font-size:56px; font-weight:800; color:var(--danger); }

@media(max-width:800px){
  .auth-wrapper{ flex-direction:column; max-width:420px; }
  .auth-left{ padding:32px 26px; text-align:center; }
  .auth-right{ padding:32px 26px; }
  .auth-brand-title{ font-size:24px; }
  .auth-role-list{ align-items:center; }
}

/* ============================================================
   MISC utilities
   ============================================================ */
.text-dim{ color:var(--text-dim); }
.text-center{ text-align:center; }
.mt-0{ margin-top:0 } .mb-0{ margin-bottom:0 }
.flex{ display:flex; } .items-center{ align-items:center; } .gap-8{ gap:8px; } .gap-12{ gap:12px; }
.justify-between{ justify-content:space-between; }
.w-full{ width:100%; }
