/* PWI Portal (SuperAdmin / Distributor / Reseller) */
@font-face { font-family: 'Poppins'; src: url('../fonts/Poppins-Regular.ttf') format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Poppins'; src: url('../fonts/Poppins-Medium.ttf') format('truetype'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Poppins'; src: url('../fonts/Poppins-Bold.ttf') format('truetype'); font-weight: 700; font-display: swap; }

:root {
    --navy: #0804A3;
    --navy-2: #1e1b9b;
    --blue: #2563eb;
    --text: #1f2937;
    --muted: #6b7280;
    --line: #e5e7eb;
    --bg: #f5f7fb;
    --ok: #16a34a;
    --warn: #d97706;
    --danger: #dc2626;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px -6px rgba(16,24,40,.12);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: 'Poppins', -apple-system, 'Segoe UI', Roboto, Arial, sans-serif; color: var(--text); background: var(--bg); font-size: 14px; -webkit-font-smoothing: antialiased; }
a { color: var(--navy); }
h1, h2, h3 { margin: 0; }
button, input, select, textarea { font-family: inherit; font-size: 14px; }

/* Layout */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 256px; flex-shrink: 0; background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 40; }
.brand { padding: 20px 22px 8px; }
.brand img { width: 130px; }
.balance { margin: 10px 16px 14px; padding: 14px 16px; border-radius: 14px; background: linear-gradient(135deg, #2B7FFF 0%, #4F39F6 100%); color: #fff; }
.balance .label { font-size: 12px; opacity: .85; }
.balance .amount { font-size: 22px; font-weight: 700; margin: 2px 0; }
.balance .who { font-size: 11px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar nav { display: flex; flex-direction: column; padding: 4px 10px; gap: 2px; flex: 1; }
.sidebar nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: #374151; text-decoration: none; font-weight: 500; }
.sidebar nav a:hover { background: #f3f4f6; }
.sidebar nav a.on { background: var(--navy); color: #fff; }
.sidebar .ico { width: 20px; height: 20px; background: currentColor; -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat; flex-shrink: 0; }
.logout { margin: 12px 16px 20px; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: pointer; color: var(--danger); font-weight: 500; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 16px 28px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
.topbar h1 { font-size: 20px; font-weight: 700; }
.topbar .me { margin-left: auto; color: var(--muted); font-size: 13px; }
.burger { display: none; border: 0; background: none; font-size: 22px; cursor: pointer; padding: 4px 8px; }
.content { padding: 24px 28px 48px; }

/* Cards & grid */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 20px; }
.metric { background: #fff; border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.metric .label { color: var(--muted); font-size: 13px; }
.metric .value { font-size: 24px; font-weight: 700; margin-top: 6px; color: var(--navy); }
.panel { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.panel + .panel { margin-top: 18px; }
.panel h2 { font-size: 16px; margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 16px; cursor: pointer; font-weight: 500; }
.tabs button.on { background: var(--navy); color: #fff; border-color: var(--navy); }

/* Forms */
.input, select.input, textarea.input { width: 100%; padding: 9px 12px; border: 1px solid #d1d5db; border-radius: 10px; background: #fff; color: var(--text); outline: none; }
.input:focus { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(8,4,163,.12); }
.input.sm { width: auto; min-width: 160px; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; color: #374151; }
label.f small { color: var(--muted); font-size: 12px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; cursor: pointer; }
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 10px; border: 1px solid var(--navy); background: var(--navy); color: #fff; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--navy-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.light { background: #fff; color: var(--navy); }
.btn.light:hover { background: #eef2ff; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--navy); padding: 6px 8px; }
.btn.ghost:hover { background: #eef2ff; }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.err { color: var(--danger); font-size: 13px; margin: 6px 0; min-height: 1em; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table.t { width: 100%; border-collapse: collapse; background: #fff; }
.t th { text-align: left; font-size: 12px; font-weight: 600; color: #4b5563; background: #f9fafb; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.t td { padding: 10px 12px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t tr:hover td { background: #fafbff; }
.t td.num, .t th.num { text-align: right; font-variant-numeric: tabular-nums; }
.t .actions { white-space: nowrap; text-align: right; }
.empty-row { text-align: center; color: var(--muted); padding: 28px !important; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; color: var(--muted); font-size: 13px; }
.pager .btns { display: flex; gap: 6px; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.tag.ok, .tag.success, .tag.active { background: #dcfce7; color: #166534; }
.tag.pending { background: #fef3c7; color: #92400e; }
.tag.failed, .tag.inactive, .tag.off { background: #fee2e2; color: #991b1b; }
.tag.info { background: #e0e7ff; color: #3730a3; }
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #d1d5db; border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span::before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--navy); }
.switch input:checked + span::before { transform: translateX(18px); }

/* Modal, toast, loader */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 560px; box-shadow: 0 30px 60px -20px rgba(0,0,0,.35); }
.modal.wide { max-width: 820px; }
.modal-h { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-h h3 { font-size: 17px; }
.modal-h .x { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-b { padding: 18px 20px; }
.modal-f { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
#toast { position: fixed; right: 20px; top: 20px; z-index: 200; width: 360px; max-width: calc(100% - 40px); }
.toast { background: #fff; border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; box-shadow: 0 16px 30px -12px rgba(0,0,0,.3); border-left: 4px solid var(--ok); display: flex; gap: 10px; animation: slide .2s ease-out; }
.toast.error { border-left-color: var(--danger); }
.toast .x { margin-left: auto; border: 0; background: none; cursor: pointer; color: var(--muted); }
@keyframes slide { from { transform: translateX(20px); opacity: 0; } }
#loader { position: fixed; inset: 0; background: rgba(255,255,255,.5); z-index: 150; display: none; align-items: center; justify-content: center; }
#loader.on { display: flex; }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 4px solid #c7d2fe; border-top-color: var(--navy); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.right { text-align: right; }
.mt { margin-top: 14px; }
.row-gap { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.qr-img { width: 240px; max-width: 100%; image-rendering: pixelated; border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: #fff; }
.thumb { width: 72px; height: 40px; object-fit: cover; border-radius: 6px; background: #f1f5f9; }
.notice { background: #eef2ff; border: 1px solid #c7d2fe; color: #312e81; border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; font-size: 13px; }
.notice.warn { background: #fffbeb; border-color: #fde68a; color: #78350f; }

/* Login */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(180deg, #E0E7FF 0%, #EFF6FF 100%); padding: 20px; }
.login-card { background: #fff; width: 100%; max-width: 400px; border-radius: 20px; padding: 32px 28px; box-shadow: 0 30px 60px -25px rgba(30,41,59,.4); }
.login-card img { display: block; width: 160px; margin: 0 auto 18px; }
.login-card h1 { text-align: center; font-size: 20px; margin-bottom: 4px; }
.login-card p { text-align: center; color: var(--muted); margin: 0 0 20px; }

@media (max-width: 900px) {
    .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.2); }
    .sidebar.open { transform: none; }
    .burger { display: block; }
    .content { padding: 16px; }
    .topbar { padding: 12px 16px; }
    .grid2, .fgrid { grid-template-columns: 1fr; }
    .kv { grid-template-columns: 1fr; }
}
.grid2 > .panel + .panel { margin-top: 0; }
.grid2 { margin-bottom: 18px; }
.t td { white-space: nowrap; }
.t td.wrap { white-space: normal; min-width: 200px; }
