/* ============================================================
   GEMINI RESELLER DASHBOARD
   Gaya: bersih, terang, mobile-first.
   ============================================================ */

/* ---------- 1. Token reka bentuk ---------- */
:root {
    /* Warna asas */
    --bg:            #F5F7FB;
    --surface:       #FFFFFF;
    --surface-2:     #F8FAFC;
    --border:        #E7ECF3;
    --border-strong: #D7DFEA;

    --text:          #0F172A;
    --text-2:        #475569;
    --text-3:        #64748B;

    /* Jenama */
    --primary:       #2563EB;
    --primary-dark:  #1D4ED8;
    --primary-soft:  #EEF4FF;
    --primary-ring:  rgba(37, 99, 235, .28);

    --induk:         #7C3AED;
    --induk-soft:    #F3EEFF;

    /* Status */
    --ok:            #15803D;
    --ok-soft:       #E8F6EE;
    --ok-line:       #B4E0C5;

    --warn:          #B45309;
    --warn-soft:     #FEF4E2;
    --warn-line:     #F7DDA8;

    --danger:        #C81E1E;
    --danger-soft:   #FDECEC;
    --danger-line:   #F6C6C6;

    /* Sidebar gelap */
    --nav-bg-1:      #121B30;
    --nav-bg-2:      #0B1220;
    --nav-text:      #C7D2E4;
    --nav-text-dim:  #7B8AA5;
    --nav-active:    #1E2A44;

    /* Bentuk */
    --r-sm: 8px;
    --r:    12px;
    --r-lg: 16px;
    --r-xl: 20px;

    --shadow-xs: 0 1px 2px rgba(15, 23, 42, .05);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-md: 0 4px 14px -4px rgba(15, 23, 42, .10), 0 2px 4px rgba(15, 23, 42, .04);
    --shadow-lg: 0 24px 48px -16px rgba(15, 23, 42, .28);

    --topbar-h: 60px;
    --sidebar-w: 252px;

    --ease: cubic-bezier(.4, 0, .2, 1);
}

/* ---------- 2. Reset ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

h1, h2, h3, p { margin: 0; }

button, input, select, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }

a { color: var(--primary); }

img, svg { display: block; max-width: 100%; }

[hidden] { display: none !important; }

::selection { background: var(--primary-soft); }

/* ---------- 3. Utiliti ---------- */
.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.ic {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
    pointer-events: none;
}

.muted { color: var(--text-2); }
.small { font-size: 13px; }
.stack > * + * { margin-top: 10px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.mt-14 { margin-top: 14px; }

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 6px;
}

/* ---------- 4. Butang ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: var(--r);
    background: var(--surface);
    color: var(--text);
    font-size: 14.5px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color .18s var(--ease), border-color .18s var(--ease),
                color .18s var(--ease), transform .12s var(--ease), box-shadow .18s var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }

.btn--primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 1px 2px rgba(37, 99, 235, .3);
}
.btn--primary:hover { background: var(--primary-dark); }

.btn--outline {
    background: var(--surface);
    border-color: var(--border-strong);
    color: var(--text);
}
.btn--outline:hover { background: var(--surface-2); border-color: var(--primary); color: var(--primary); }

.btn--ghost {
    background: var(--primary-soft);
    color: var(--primary-dark);
}
.btn--ghost:hover { background: #E3EDFF; }

.btn--danger {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: var(--danger-line);
}
.btn--danger:hover { background: #FBDADA; }

.btn--sm { min-height: 38px; padding: 0 12px; font-size: 13.5px; }
.btn--lg { min-height: 50px; font-size: 15.5px; }
.btn--block { width: 100%; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--text-2);
    transition: background-color .18s var(--ease), color .18s var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- 5. Lencana & pil ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    white-space: nowrap;
}
.badge--role {
    background: var(--primary-soft);
    color: var(--primary-dark);
    vertical-align: 3px;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px solid transparent;
    font-size: 12px;
    font-weight: 650;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.pill--ok       { background: var(--ok-soft);     color: var(--ok);     border-color: var(--ok-line); }
.pill--warn     { background: var(--warn-soft);   color: var(--warn);   border-color: var(--warn-line); }
.pill--danger   { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-line); }
.pill--neutral  { background: var(--surface-2);   color: var(--text-3); border-color: var(--border); }
.pill--induk    { background: var(--induk-soft);  color: var(--induk);  border-color: #E2D6FF; }
.pill--referral { background: var(--primary-soft);color: var(--primary-dark); border-color: #D5E3FF; }

/* ---------- 6. Amaran ---------- */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--r);
    border: 1px solid;
    font-size: 14px;
    line-height: 1.45;
}
.alert--danger  { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }
.alert--info    { background: var(--primary-soft); border-color: #D5E3FF; color: #1E40AF; }
.alert--warn    { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.alert .ic { margin-top: 1px; }

/* ---------- 7. Halaman log masuk ---------- */
.login-body {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
    background:
        radial-gradient(900px 480px at 50% -8%, #E4ECFB 0%, rgba(228, 236, 251, 0) 62%),
        var(--bg);
}

.login-wrap { width: 100%; max-width: 420px; }

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-md);
    padding: 26px 22px;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 13px;
    margin-bottom: 20px;
}
.login-title { font-size: 21px; font-weight: 750; letter-spacing: -.02em; }
.login-sub { font-size: 13px; color: var(--text-3); }

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px; height: 40px;
    border-radius: 12px;
    background: linear-gradient(140deg, var(--primary), #4F46E5);
    color: #fff;
    box-shadow: 0 6px 14px -6px rgba(37, 99, 235, .7);
}
.brand-mark svg { width: 22px; height: 22px; }
.brand-mark--lg { width: 48px; height: 48px; border-radius: 14px; }
.brand-mark--lg svg { width: 26px; height: 26px; }
.brand-mark--sm { width: 32px; height: 32px; border-radius: 10px; }
.brand-mark--sm svg { width: 18px; height: 18px; }

.login-hint { font-size: 14px; color: var(--text-2); margin-bottom: 16px; }
.login-card .alert { margin-bottom: 16px; }
.login-foot {
    margin-top: 18px;
    text-align: center;
    font-size: 12.5px;
    color: var(--text-3);
}

.pin-field { position: relative; }

.pin-input {
    width: 100%;
    height: 58px;
    padding: 0 52px 0 18px;
    border: 1.5px solid var(--border-strong);
    border-radius: var(--r);
    background: var(--surface-2);
    font-size: 26px;
    font-weight: 700;
    letter-spacing: .42em;
    text-align: center;
    text-indent: .42em;
    font-variant-numeric: tabular-nums;
    transition: border-color .18s var(--ease), box-shadow .18s var(--ease), background-color .18s var(--ease);
}
.pin-input::placeholder { letter-spacing: .3em; color: #B8C2D0; }
.pin-input:focus {
    outline: none;
    background: var(--surface);
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-ring);
}

.pin-toggle {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    display: grid;
    place-items: center;
    width: 44px; height: 44px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text-3);
}
.pin-toggle:hover { background: var(--surface-2); color: var(--text); }

.field-help { margin-top: 8px; font-size: 12.5px; color: var(--text-3); }

.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 16px 0 18px;
}
.key {
    height: 54px;
    border: 1px solid var(--border);
    border-radius: var(--r);
    background: var(--surface);
    font-size: 20px;
    font-weight: 650;
    color: var(--text);
    transition: background-color .14s var(--ease), border-color .14s var(--ease), transform .1s var(--ease);
}
.key:hover { background: var(--primary-soft); border-color: #D5E3FF; }
.key:active { transform: scale(.97); background: #E3EDFF; }
.key--ghost { font-size: 13.5px; font-weight: 600; color: var(--text-3); }
.key--ghost .ic { margin: 0 auto; }

/* ---------- 8. Susun atur utama ---------- */
.shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.content {
    flex: 1;
    width: 100%;
    max-width: 1320px;
    margin: 0 auto;
    padding: 16px 14px calc(40px + env(safe-area-inset-bottom));
}

/* ---------- 9. Sidebar ---------- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 70;
    display: flex;
    flex-direction: column;
    width: var(--sidebar-w);
    height: 100vh;
    height: 100dvh;
    padding: 16px 12px calc(14px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, var(--nav-bg-1), var(--nav-bg-2));
    transform: translateX(-100%);
    transition: transform .28s var(--ease);
    overflow-y: auto;
}
.sidebar.is-open { transform: none; }

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 6px 6px 18px;
    color: #fff;
}
.sidebar-brand-text { display: flex; flex-direction: column; min-width: 0; }
.sidebar-brand-text strong { font-size: 16.5px; font-weight: 700; letter-spacing: -.01em; }
.sidebar-brand-text span { font-size: 12.5px; color: var(--nav-text-dim); }

.sidebar-close {
    margin-left: auto;
    display: grid;
    place-items: center;
    width: 40px; height: 40px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--nav-text-dim);
}
.sidebar-close:hover { background: rgba(255, 255, 255, .08); color: #fff; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 46px;
    padding: 0 12px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--nav-text);
    font-size: 14.5px;
    font-weight: 550;
    text-align: left;
    transition: background-color .18s var(--ease), color .18s var(--ease);
}
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-item.is-active { background: var(--nav-active); color: #fff; font-weight: 650; }
.nav-item.is-active .ic { color: #7DA8FF; }

.sidebar-foot {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, .08);
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.user-chip-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.user-chip-text strong { font-size: 14px; font-weight: 650; }
.user-chip-text span { font-size: 11.5px; color: var(--text-3); }

.user-chip--sidebar .user-chip-text strong { color: #fff; }
.user-chip--sidebar .user-chip-text span { color: var(--nav-text-dim); }

.avatar {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(140deg, var(--primary), #4F46E5);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
}

.sidebar-logout {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    margin-top: 10px;
    padding: 0 12px;
    border-radius: 10px;
    color: var(--nav-text-dim);
    font-size: 14px;
    font-weight: 550;
    text-decoration: none;
}
.sidebar-logout:hover { background: rgba(255, 255, 255, .06); color: #fff; }

.sidebar-scrim {
    position: fixed;
    inset: 0;
    z-index: 65;
    background: rgba(8, 14, 28, .5);
    backdrop-filter: blur(2px);
    animation: fade .2s var(--ease);
}

/* ---------- 10. Topbar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: var(--topbar-h);
    padding: 8px 14px;
    padding-top: calc(8px + env(safe-area-inset-top));
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.topbar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.topbar-brand-text strong { font-size: 15px; font-weight: 700; }
.topbar-brand-text span { font-size: 11.5px; color: var(--text-3); }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.attention-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 36px;
    padding: 0 11px;
    border: 1px solid var(--warn-line);
    border-radius: 999px;
    background: var(--warn-soft);
    color: var(--warn);
    font-size: 13px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.attention-pill:hover { background: #FDEBCE; }
.attention-pill .ic { width: 16px; height: 16px; }

/* ---------- 11. Kepala halaman ---------- */
.view { animation: rise .3s var(--ease); }
.view[hidden] { display: none; }

.page-head { margin-bottom: 14px; }
.page-title {
    font-size: 20px;
    font-weight: 750;
    letter-spacing: -.02em;
    line-height: 1.25;
}
.page-sub { margin-top: 3px; font-size: 13.5px; color: var(--text-3); }

/* ---------- 12. Kad statistik (satu baris pada mobile) ---------- */
.stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 14px;
}
.stats--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stats--1 { grid-template-columns: minmax(0, 1fr); }
.stats--1 .stat { flex-direction: row; align-items: center; }

.stat {
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-width: 0;
    padding: 11px 11px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    box-shadow: var(--shadow-xs);
}

.stat-icon {
    display: grid;
    place-items: center;
    width: 28px; height: 28px;
    border-radius: 9px;
}
.stat-icon .ic { width: 17px; height: 17px; }
.stat--sale   .stat-icon { background: var(--ok-soft);    color: var(--ok); }
.stat--client .stat-icon { background: var(--primary-soft); color: var(--primary); }
.stat--induk  .stat-icon { background: var(--induk-soft); color: var(--induk); }

.stat-body { min-width: 0; }
.stat-label {
    font-size: 10.5px;
    font-weight: 650;
    letter-spacing: .03em;
    text-transform: uppercase;
    color: var(--text-3);
    line-height: 1.3;
}
.stat-value {
    margin-top: 2px;
    font-size: 16px;
    font-weight: 750;
    letter-spacing: -.02em;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.stat-trend {
    display: none;
    margin-top: 2px;
    font-size: 11.5px;
    color: var(--text-3);
}
.stat-trend.is-up   { color: var(--ok);     font-weight: 600; }
.stat-trend.is-down { color: var(--danger); font-weight: 600; }
.stat-trend.is-flat { color: var(--text-3); }

/* ---------- 13. Kad umum ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card + .card { margin-top: 14px; }

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 14px 15px;
    border-bottom: 1px solid var(--border);
}
.card-title { font-size: 15.5px; font-weight: 700; letter-spacing: -.01em; }
.card-sub { margin-top: 2px; font-size: 12.5px; color: var(--text-3); }
.card-body { padding: 15px; }
.card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 14px 15px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}
.card-note { font-size: 12.5px; color: var(--text-3); }

/* ---------- 14. Senarai client ---------- */
.list-head-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 14px 15px 12px;
}
.list-title-wrap { min-width: 0; }

.list-tools {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 15px 12px;
}

.search-field { position: relative; }
.search-icon {
    position: absolute;
    top: 50%;
    left: 13px;
    transform: translateY(-50%);
    width: 17px; height: 17px;
    color: var(--text-3);
}
.search-field input {
    width: 100%;
    height: 44px;
    padding: 0 14px 0 39px;
    border: 1px solid var(--border-strong);
    border-radius: var(--r);
    background: var(--surface-2);
    font-size: 14.5px;
    transition: border-color .18s var(--ease), box-shadow .18s var(--ease), background-color .18s var(--ease);
}
.search-field input::placeholder { color: #97A3B6; }
.search-field input:focus {
    outline: none;
    background: var(--surface);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-ring);
}
.search-field input::-webkit-search-cancel-button { -webkit-appearance: none; }

.list-tools-row {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: space-between;
}
.chips {
    display: flex;
    gap: 7px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 1px;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
    flex: 0 0 auto;
    min-height: 36px;
    padding: 0 12px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-2);
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    transition: all .16s var(--ease);
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.is-active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.sort-field {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    padding: 0 6px 0 11px;
    min-height: 36px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-3);
}
.sort-field .ic { width: 15px; height: 15px; }
.sort-field select {
    appearance: none;
    -webkit-appearance: none;
    border: 0;
    background: transparent;
    padding: 0 18px 0 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-2);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right center;
    cursor: pointer;
}
.sort-field:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.sort-field select:focus { outline: none; }

/* Baris senarai */
.list-body { border-top: 1px solid var(--border); }

.list-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 44px 20px;
    text-align: center;
    color: var(--text-3);
}
.list-empty .ic { width: 34px; height: 34px; color: #B6C1D1; }
.list-empty strong { font-size: 15px; color: var(--text-2); font-weight: 650; }
.list-empty p { font-size: 13.5px; max-width: 34ch; }

.client-row {
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr) auto 34px;
    grid-template-areas:
        "no email expired action"
        "no email harga   action";
    align-items: center;
    column-gap: 10px;
    row-gap: 1px;
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    transition: background-color .16s var(--ease);
}
.client-row:last-child { border-bottom: 0; }
.client-row:hover { background: var(--surface-2); }
.client-row:focus-within { background: var(--surface-2); }

.list-head { display: none; }

.c-no {
    grid-area: no;
    font-size: 12.5px;
    font-weight: 650;
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}

.c-email {
    grid-area: email;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.cell-email {
    font-size: 14px;
    font-weight: 650;
    letter-spacing: -.01em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mobile-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    font-size: 11.5px;
    color: var(--text-3);
    white-space: nowrap;
}
/* Email induk boleh dipotong, nama referral sentiasa kelihatan penuh */
.mobile-meta .meta-induk {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mobile-meta .meta-ref,
.mobile-meta .meta-sep { flex: 0 0 auto; }
.meta-sep { color: #CBD5E1; }
.meta-strong { font-weight: 650; color: var(--text-2); font-variant-numeric: tabular-nums; }

.c-induk, .c-referral, .c-date, .c-used, .c-resit { display: none; }

.cell-text {
    font-size: 13.5px;
    color: var(--text-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cell-muted { color: var(--text-3); }
.cell-num { font-variant-numeric: tabular-nums; font-weight: 650; }

.c-expired {
    grid-area: expired;
    justify-self: end;
    display: flex;
}

.c-harga {
    grid-area: harga;
    justify-self: end;
    text-align: right;
}

.c-action {
    grid-area: action;
    display: flex;
    justify-content: flex-end;
    align-self: center;
}

.row-open {
    display: grid;
    place-items: center;
    width: 34px; height: 34px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: #A6B2C3;
    transition: background-color .16s var(--ease), color .16s var(--ease);
}
.row-open:hover { background: var(--primary-soft); color: var(--primary); }
.row-open .ic { width: 17px; height: 17px; }

.dl-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    padding: 0 11px;
    border: 1px solid #C9DBFF;
    border-radius: 9px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-size: 12.5px;
    font-weight: 650;
    white-space: nowrap;
    transition: background-color .16s var(--ease);
}
.dl-btn:hover { background: #E1EBFF; }
.dl-btn .ic { width: 15px; height: 15px; }
.dl-btn--muted {
    border-color: var(--border-strong);
    background: var(--surface);
    color: var(--text-3);
    font-weight: 600;
}
.dl-btn--muted:hover { background: var(--surface-2); }

/* ---------- 15. Lightbox / modal ---------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}
.modal-scrim {
    position: absolute;
    inset: 0;
    background: rgba(8, 14, 28, .55);
    backdrop-filter: blur(3px);
    animation: fade .22s var(--ease);
}
.modal-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    background: var(--surface);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    box-shadow: var(--shadow-lg);
    animation: sheet-up .3s var(--ease);
    overflow: hidden;
}
.modal-panel::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 38px;
    height: 4px;
    border-radius: 999px;
    background: #DDE3EC;
}

.modal-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 18px 12px 12px;
    border-bottom: 1px solid var(--border);
}
.modal-title {
    flex: 1;
    font-size: 16.5px;
    font-weight: 700;
    letter-spacing: -.01em;
    text-align: center;
}
.modal-back { display: none; }

.modal-body {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.modal-foot {
    display: flex;
    flex-direction: column;
    gap: 9px;
    padding: 13px 15px calc(15px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    background: var(--surface);
}
.modal-foot:empty { display: none; }

.detail-ident {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px;
    margin-bottom: 13px;
    border-radius: var(--r);
    background: linear-gradient(135deg, #F1F5FE, #F7F9FE);
    border: 1px solid #E3EAF8;
}
.detail-ident .avatar { width: 42px; height: 42px; font-size: 16px; border-radius: 13px; }
.detail-ident-text { min-width: 0; }
.detail-ident-text strong {
    display: block;
    font-size: 15.5px;
    font-weight: 700;
    letter-spacing: -.01em;
    overflow: hidden;
    text-overflow: ellipsis;
}
.detail-ident-text span { font-size: 12.5px; color: var(--text-3); }
.detail-ident-badge { margin-left: auto; flex: 0 0 auto; }

.detail-list { border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; }
.detail-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 11px 13px;
    border-bottom: 1px solid var(--border);
}
.detail-row:last-child { border-bottom: 0; }
.detail-row:nth-child(odd) { background: var(--surface-2); }
.detail-label {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    color: var(--text-3);
    flex: 0 0 auto;
}
.detail-label .ic { width: 15px; height: 15px; color: #9AA7BA; }
.detail-value {
    font-size: 13.5px;
    font-weight: 620;
    text-align: right;
    min-width: 0;
    overflow-wrap: anywhere;
}
.detail-value.is-empty { color: var(--text-3); font-weight: 500; }
.detail-value.is-num { font-variant-numeric: tabular-nums; }

.detail-note {
    margin-top: 13px;
    padding: 12px 13px;
    border-radius: var(--r);
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 13.5px;
    color: var(--text-2);
    line-height: 1.5;
}

.detail-notice { margin-top: 13px; }

.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.detail-actions .btn { flex: 1 1 auto; }

/* ---------- 16. Borang ---------- */
.form-grid { display: grid; gap: 14px; }
@media (min-width: 720px) {
    .form-grid { grid-template-columns: repeat(3, 1fr); }
}

.field { display: flex; flex-direction: column; min-width: 0; }
.field > label,
.field-label {
    font-size: 13px;
    font-weight: 650;
    color: var(--text-2);
    margin-bottom: 6px;
}
.field .req { color: var(--danger); margin-left: 2px; }

.field input[type="text"],
.field input[type="email"],
.field input[type="url"],
.field input[type="date"],
.field input[type="number"],
.field input[type="password"],
.field select,
.field textarea,
.input {
    width: 100%;
    min-height: 46px;
    padding: 10px 13px;
    border: 1px solid var(--border-strong);
    border-radius: var(--r);
    background: var(--surface);
    font-size: 15px;
    color: var(--text);
    transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.field textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
.field select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 13px center;
    cursor: pointer;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-ring);
}
.field input[aria-invalid="true"],
.field select[aria-invalid="true"] {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(200, 30, 30, .16);
}
.field .field-help { margin-top: 6px; }
.field-error {
    margin-top: 6px;
    font-size: 12.5px;
    color: var(--danger);
    font-weight: 600;
}

.input-prefix { position: relative; }
.input-prefix .prefix {
    position: absolute;
    top: 50%;
    left: 13px;
    transform: translateY(-50%);
    font-size: 14px;
    font-weight: 650;
    color: var(--text-3);
    pointer-events: none;
}
.input-prefix input { padding-left: 42px; }

.file-drop {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 12px;
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--r);
    background: var(--surface-2);
    cursor: pointer;
    transition: border-color .18s var(--ease), background-color .18s var(--ease);
}
.file-drop:hover { border-color: var(--primary); background: var(--primary-soft); }
.file-drop .ic { width: 22px; height: 22px; color: var(--primary); flex: 0 0 auto; }
.file-drop-text { min-width: 0; font-size: 13.5px; }
.file-drop-text strong { display: block; font-weight: 650; }
.file-drop-text span {
    display: block;
    font-size: 12px;
    color: var(--text-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.form-section-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 20px 0 10px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-3);
}
.form-section-label::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}
.form-section-label:first-child { margin-top: 0; }

/* ---------- 17. Paparan pengguna & tetapan ---------- */
.users-list { display: flex; flex-direction: column; }

.user-row {
    display: grid;
    gap: 10px;
    padding: 14px 15px;
    border-bottom: 1px solid var(--border);
}
.user-row:last-child { border-bottom: 0; }
.user-row-fields { display: grid; gap: 10px; }
.user-row-head {
    display: flex;
    align-items: center;
    gap: 10px;
}
.user-row-head .avatar { width: 34px; height: 34px; font-size: 13px; }
.user-row-head strong { font-size: 14.5px; font-weight: 650; }

@media (min-width: 720px) {
    .user-row-fields { grid-template-columns: 1.1fr 1fr .8fr .9fr auto; align-items: end; }
}

.remove-user {
    align-self: end;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid var(--danger-line);
    border-radius: var(--r);
    background: var(--danger-soft);
    color: var(--danger);
    font-size: 13px;
    font-weight: 600;
}
.remove-user:hover { background: #FBDADA; }

/* ---------- 18. Toast ---------- */
.toast-wrap {
    position: fixed;
    left: 50%;
    bottom: calc(18px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 120;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: max-content;
    max-width: calc(100vw - 28px);
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 11px 15px;
    border-radius: 999px;
    background: #0F172A;
    color: #F8FAFC;
    font-size: 13.5px;
    font-weight: 600;
    box-shadow: 0 12px 28px -10px rgba(15, 23, 42, .6);
    animation: toast-in .26s var(--ease);
}
.toast .ic { width: 17px; height: 17px; }
.toast--ok .ic   { color: #4ADE80; }
.toast--err { background: #7F1D1D; }
.toast--err .ic { color: #FCA5A5; }

/* Apabila lightbox dibuka, naikkan toast supaya tidak menutup butang utama */
body.modal-open .toast-wrap { bottom: calc(116px + env(safe-area-inset-bottom)); }

/* ---------- 19. Animasi ---------- */
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes sheet-up { from { transform: translateY(14px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }

.spinner {
    width: 16px; height: 16px;
    border: 2px solid rgba(255, 255, 255, .45);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
.btn--outline .spinner { border-color: rgba(15, 23, 42, .25); border-top-color: var(--primary); }

/* ---------- 20. Skrin besar ---------- */
@media (min-width: 640px) {
    .stats { gap: 12px; margin-bottom: 18px; }
    .stat { flex-direction: row; align-items: flex-start; gap: 11px; padding: 14px; }
    .stat-trend { display: block; }
    .stat-value { font-size: 17px; }

    .content { padding: 18px 18px 48px; }
}

/* Skrin kecil: jimat ruang supaya senarai client nampak lebih banyak */
@media (max-width: 479px) {
    .topbar-brand-text span { white-space: nowrap; }
    .topbar .user-chip-text { display: none; }
    .sort-field { display: none; }
    .list-tools-row { justify-content: flex-start; }
    /* Label 2 baris ("Total Email Induk") supaya nilai ketiga-tiga kad sejajar */
    .stat-label { min-height: 2.6em; }
}

/* Telefon sangat kecil (320-359px) */
@media (max-width: 359px) {
    .stat { padding: 9px; }
    .stat-value { font-size: 14.5px; }
    .stat-label { font-size: 10px; }
    .stats { gap: 6px; }
}

@media (min-width: 768px) {
    .btn--block-mobile { width: auto; }
    .modal { align-items: center; padding: 24px; }
    .modal-panel {
        max-width: 560px;
        max-height: 86vh;
        border-radius: var(--r-xl);
        animation: rise .26s var(--ease);
    }
    .modal-panel::before { display: none; }
    .modal-head { padding: 16px 18px 14px; }
    .modal-title { text-align: left; }
    .modal-back { display: none; }
    .modal-body { padding: 18px; }
    .modal-foot {
        flex-direction: row;
        justify-content: flex-end;
        padding: 14px 18px;
    }
    .modal-foot .btn { width: auto; min-width: 150px; }
    .detail-actions { flex: 0 0 auto; }
    .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
    .form-row > .field + .field { margin-top: 0; }
    body.modal-open .toast-wrap { bottom: calc(18px + env(safe-area-inset-bottom)); }
}

@media (min-width: 900px) {
    .list-tools { flex-direction: row; align-items: center; }
    .search-field { flex: 0 1 340px; }
    .list-tools-row { flex: 1; }
}

@media (min-width: 1024px) {
    .sidebar {
        transform: none;
        transition: none;
        border-right: 1px solid rgba(255, 255, 255, .06);
    }
    .sidebar-close { display: none; }
    .sidebar-scrim { display: none !important; }

    .shell { margin-left: var(--sidebar-w); }
    .topbar-menu { display: none; }
    .topbar { padding: 10px 22px; min-height: 64px; }
    .topbar-brand { display: none; }
    .content { padding: 22px 22px 56px; }

    .page-title { font-size: 22px; }
    .stats { gap: 14px; }
    .stat { padding: 16px; }
    .stat-value { font-size: 19px; }
    .stat-icon { width: 34px; height: 34px; border-radius: 10px; }
    .stat-icon .ic { width: 19px; height: 19px; }

    .list-head-bar { padding: 16px 18px 14px; }
    .list-tools { padding: 0 18px 14px; }

    /* Jadual desktop */
    .list-head,
    .client-row {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 11px 18px;
    }
    .list-head {
        background: var(--surface-2);
        border-bottom: 1px solid var(--border);
        font-size: 11.5px;
        font-weight: 700;
        letter-spacing: .05em;
        text-transform: uppercase;
        color: var(--text-3);
    }
    .list-body { border-top: 0; }

    /* Semua sel mesti boleh mengecil supaya lebar lajur kekal seimbang */
    .c-no, .c-email, .c-induk, .c-referral, .c-date,
    .c-used, .c-harga, .c-resit, .c-expired, .c-action {
        grid-area: auto;
        min-width: 0;
        justify-self: auto;
    }

    .c-no       { flex: 0 0 30px; }
    .c-email    { flex: 1.4 1 150px; }
    .c-induk    { flex: 1.1 1 140px; display: block; }
    .c-referral { flex: 0 0 88px; display: block; }
    .c-date     { flex: 0 0 102px; display: block; }
    .c-used     { flex: 0 0 86px; display: block; }
    .c-harga    { flex: 0 0 100px; display: block; text-align: right; }
    .c-resit    { flex: 0 0 108px; display: block; }
    .c-expired  { flex: 0 0 98px; display: flex; justify-content: flex-start; }
    .c-action   { flex: 0 0 30px; }

    .mobile-meta { display: none; }
    .cell-email { font-size: 13.5px; }
    .c-induk .cell-text { font-size: 13px; }
    .list-head .c-harga { text-align: right; }
    .list-head .c-expired { justify-content: flex-start; }
}

@media (min-width: 1280px) {
    .c-email { flex: 1 1 220px; }
    .c-induk { flex: 1 1 200px; }
}

/* ---------- 21. Elipsis teks berulang ---------- */
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* ---------- 22. Kurangkan gerakan ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---------- 23. Cetak ---------- */
@media print {
    .sidebar, .topbar, .list-tools, .modal, .toast-wrap, .list-head-bar .btn { display: none !important; }
    .shell { margin: 0; }
    .card { box-shadow: none; }
}
