@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

/* ==========================================================================
   DESIGN TOKENS — Light, professional: white surfaces, blue + rose-gold accents
   ========================================================================== */
:root {
    /* Primary accent — professional blue */
    --primary: #2A6FA8;
    --primary-hover: #1F5A8C;
    --primary-soft: #EAF2F9;
    --primary-glow: rgba(42, 111, 168, 0.14);
    /* Secondary accent — rose-gold / bronze, used sparingly for warmth */
    --rose-gold: #A9713F;
    --rose-gold-hover: #8F5D30;
    --rose-gold-soft: #F7EEE2;
    /* Semantic status accents */
    --accent-credit: #2A6FA8;   /* blue */
    --accent-consumed: #A9713F; /* rose-gold / bronze */
    --accent-balance: #3F8564;  /* muted green */
    --danger: #B3413B;
    --danger-soft: #FBEAE9;
    /* Surfaces & Canvas — all light, no dark panels */
    --bg: #F7F6F3;
    --surface: #FFFFFF;
    --surface-hover: #F4F1EC;
    --border: #E7E2DA;
    --border-subtle: #F0ECE5;
    --sidebar-bg: #FFFFFF;
    /* Typography */
    --text: #262220;
    --text-muted: #6B655D;
    --text-subtle: #948C82;
    --on-sidebar: #48423C;
    --on-sidebar-muted: #948C82;
    /* Elevation — soft, not glowy */
    --shadow-xs: 0 1px 2px 0 rgba(38, 34, 32, 0.04);
    --shadow-sm: 0 1px 3px 0 rgba(38, 34, 32, 0.06), 0 1px 2px -1px rgba(38, 34, 32, 0.04);
    --shadow-md: 0 4px 10px -2px rgba(38, 34, 32, 0.07);
    --shadow-lg: 0 12px 28px -8px rgba(38, 34, 32, 0.12);
    /* Geometry */
    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 10px;
    --radius-full: 9999px;
    /* Typography stacks */
    --sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --mono: 'IBM Plex Mono', "SF Mono", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
    font-family: var(--sans);
    color: var(--text);
    background-color: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; border: none; background: transparent; cursor: pointer; }

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

.sidebar {
    width: 258px; flex-shrink: 0;
    background-color: var(--sidebar-bg);
    color: var(--on-sidebar);
    display: flex; flex-direction: column;
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 100;
    overflow-y: auto;
    border-right: 1px solid var(--border);
}
.sidebar-brand {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px; border-bottom: 1px solid var(--border);
}
.brand-badge { display: flex; align-items: center; gap: 12px; }
.auth-brand-mark {
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    background: var(--rose-gold);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-family: var(--mono); font-weight: 700; font-size: 14px;
}
.brand-title { color: var(--text); font-weight: 600; font-size: 14.5px; letter-spacing: -0.01em; }
.brand-sub {
    font-size: 11px; color: var(--text-subtle); font-weight: 500;
    text-transform: uppercase; letter-spacing: 0.05em; margin-top: 1px;
}
.drawer-close {
    display: none; color: var(--text-muted); width: 32px; height: 32px;
    border-radius: 8px; align-items: center; justify-content: center;
}
.drawer-close svg { width: 20px; height: 20px; }
.sidebar-nav { padding: 14px; flex: 1; }
.sidebar-section {
    font-size: 10.5px; text-transform: uppercase; color: var(--text-subtle);
    font-weight: 700; letter-spacing: 0.07em; padding: 18px 12px 8px;
}
.sidebar-section:first-child { padding-top: 4px; }
.sidebar-link {
    display: flex; align-items: center; gap: 12px;
    padding: 9px 14px; border-radius: var(--radius-sm);
    font-size: 13.5px; font-weight: 500; margin-bottom: 2px;
    color: var(--on-sidebar);
    transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-link:hover { background: var(--surface-hover); }
.sidebar-link.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.sidebar-link .icon { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.8; }
.sidebar-link.active .icon { opacity: 1; color: var(--primary); }
.sidebar-foot {
    padding: 16px 20px; border-top: 1px solid var(--border);
    font-size: 12px; color: var(--text-subtle); display: flex; align-items: center; gap: 8px;
}
.system-status-indicator { width: 7px; height: 7px; border-radius: 50%; background-color: var(--accent-balance); }

/* ---------- Main / topbar ---------- */
.main { margin-left: 258px; flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    height: 60px; background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 28px; position: sticky; top: 0; z-index: 40;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-title { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; color: var(--text); }
.menu-toggle { display: none; padding: 8px; border-radius: var(--radius-sm); color: var(--text); }
.menu-toggle svg { width: 22px; height: 22px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.dealer-chip {
    display: flex; align-items: center; gap: 10px; padding: 5px 12px 5px 5px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-full); font-size: 13px; font-weight: 500;
}
.dealer-avatar {
    width: 26px; height: 26px; border-radius: 50%; background: var(--primary);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700;
}
.logout-btn {
    display: flex; align-items: center; gap: 6px; color: var(--text-muted);
    font-size: 13px; font-weight: 500; padding: 6px 10px; border-radius: var(--radius-sm);
    transition: color 0.15s ease, background 0.15s ease;
}
.logout-btn:hover { color: var(--danger); background: var(--danger-soft); }
.icon-logout { width: 16px; height: 16px; }
.content { padding: 26px 28px 48px; max-width: 1360px; width: 100%; }

/* ---------- Status strip (light card, not a dark panel) ---------- */
.status-strip {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); display: flex; overflow: hidden; margin-bottom: 26px;
    box-shadow: var(--shadow-sm);
}
.status-seg { flex: 1; padding: 20px 26px; position: relative; border-left: 3px solid transparent; }
.status-seg + .status-seg { border-left: 1px solid var(--border-subtle); }
.status-seg.credit { border-left-color: var(--accent-credit); }
.status-seg.consumed { border-left-color: var(--accent-consumed); }
.status-seg.balance { border-left-color: var(--accent-balance); }
.status-label { color: var(--text-muted); font-size: 12.5px; font-weight: 500; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.status-value { font-family: var(--mono); font-size: 30px; font-weight: 600; color: var(--text); line-height: 1.1; letter-spacing: -0.01em; }
.status-unit { font-size: 13px; color: var(--text-subtle); margin-left: 6px; font-family: var(--sans); font-weight: 500; }

/* ---------- Panels / cards ---------- */
.section-title { font-size: 15px; font-weight: 600; color: var(--text); letter-spacing: -0.005em; margin: 0 0 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.quick-links { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.quick-link {
    display: flex; align-items: center; gap: 11px; padding: 13px 15px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 13.5px; font-weight: 500; color: var(--text); background-color: var(--surface);
    transition: border-color 0.15s ease, background-color 0.15s ease;
}
.quick-link:hover { border-color: var(--primary); background-color: var(--primary-soft); color: var(--primary-hover); }
.quick-link .icon { width: 18px; height: 18px; color: var(--primary); flex-shrink: 0; }
.mini-stats { display: flex; gap: 20px; margin-bottom: 18px; padding-bottom: 16px; border-bottom: 1px solid var(--border-subtle); }
.mini-stat { flex: 1; }
.mini-stat-value { font-family: var(--mono); font-size: 21px; font-weight: 600; color: var(--text); }
.mini-stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; margin-top: 2px; }
.activity-row { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border-subtle); font-size: 13.5px; }
.activity-row:last-child { border-bottom: none; padding-bottom: 0; }
.activity-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--primary); flex-shrink: 0; }
.activity-detail { flex: 1; color: var(--text); font-weight: 500; }
.activity-type { font-weight: 600; font-size: 12px; color: var(--text-muted); min-width: 110px; }
.activity-time { color: var(--text-subtle); font-size: 12px; font-family: var(--mono); white-space: nowrap; }

/* ---------- Auth pages (light, warm card, no dark shell) ---------- */
.body-auth { background: var(--bg); }
.auth-shell { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 24px; }
.auth-card {
    width: 100%; max-width: 400px; background: var(--surface); border-radius: var(--radius-lg);
    padding: 40px 36px; box-shadow: var(--shadow-lg); border-top: 3px solid var(--rose-gold);
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.auth-brand-name { font-weight: 600; font-size: 17px; letter-spacing: -0.01em; color: var(--text); }
.auth-brand-sub { font-size: 12px; color: var(--text-muted); }
.auth-card h1 { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; color: var(--text); margin-bottom: 6px; }
.auth-card p.lead { color: var(--text-muted); font-size: 14px; margin-bottom: 24px; }
.field { margin-bottom: 18px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 7px; color: var(--text); }
.field input[type="text"], .field input[type="password"], .field input[type="tel"] {
    width: 100%; height: 42px; padding: 0 13px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: 14.5px; font-family: var(--sans);
    background: var(--bg); color: var(--text); transition: border-color 0.15s ease, background 0.15s ease;
}
.field input:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px var(--primary-glow); }
.field-error { color: var(--danger); font-size: 12px; font-weight: 500; margin-top: 6px; }
.auth-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; font-size: 13.5px; }
.auth-row label { display: flex; align-items: center; gap: 8px; color: var(--text-muted); cursor: pointer; }
.auth-row a { color: var(--primary); font-weight: 600; }
.btn-primary { width: 100%; height: 42px; background: var(--primary); color: #fff; border-radius: var(--radius-sm); font-size: 14.5px; font-weight: 600; cursor: pointer; transition: background 0.15s ease; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: scale(0.99); }

/* ---------- Mobile bottom bar & overlay ---------- */
.ios-bottom-bar { display: none; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background-color: rgba(38,34,32,.35); z-index: 90; opacity: 0; transition: opacity .25s ease; }
.sidebar-backdrop.active { display: block; opacity: 1; }

/* ---------- Mobile (<=768px) ---------- */
@media (max-width: 768px) {
    .topbar { padding-top: env(safe-area-inset-top); height: calc(56px + env(safe-area-inset-top)); padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
    .content { padding: 16px max(16px, env(safe-area-inset-right)) calc(80px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
    .menu-toggle { display: flex; align-items: center; justify-content: center; }
    .dealer-name { display: none; }
    .dealer-chip { padding: 3px; border: none; background: transparent; }
    .logout-text { display: none; }
    .main { margin-left: 0; }
    .sidebar { transform: translateX(-100%); transition: transform .25s ease; box-shadow: none; width: min(300px, 84vw); padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .drawer-close { display: flex; }
    .grid-2 { grid-template-columns: 1fr; gap: 16px; }
    .quick-links { grid-template-columns: 1fr; }
    .status-strip { flex-direction: column; border-radius: var(--radius); }
    .status-seg { padding: 16px 20px; }
    .status-seg + .status-seg { border-left: none; border-top: 1px solid var(--border-subtle); }
    .status-value { font-size: 25px; }
    .ios-bottom-bar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50; height: calc(56px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--border); align-items: center; justify-content: space-around; }
    .tab-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-muted); font-size: 10.5px; font-weight: 500; gap: 3px; touch-action: manipulation; transition: color .15s ease; }
    .tab-item svg { width: 22px; height: 22px; }
    .tab-item.active { color: var(--primary); font-weight: 600; }
}
@media (max-width: 390px) {
    .topbar-title { font-size: 15px; }
    .panel { padding: 16px; }
}

.dataTables_wrapper .dataTables_paginate {
    display: flex !important;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    white-space: nowrap;
}

    .dataTables_wrapper .dataTables_paginate .paginate_button {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        min-width: 38px;
        height: 32px;
        margin: 0 !important;
        padding: 6px 12px !important;
        box-sizing: border-box;
    }

    .dataTables_wrapper .dataTables_paginate .ellipsis {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
.dt-paging {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    flex-direction: row !important;
    gap: 4px;
}

.dt-paging-button {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
}