@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap');

/* ==========================================================================
   DESIGN SYSTEM TOKENS — LIGHT & DARK THEME
   ========================================================================== */
:root {
    color-scheme: light dark;

    /* Typography */
    --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Light Mode Palette — Clean, Bright, Crisp & Modern */
    --bg-body: #f8fafc;
    --bg-body-radial: radial-gradient(1200px 600px at 100% -10%, rgba(99, 102, 241, 0.04), transparent),
                      radial-gradient(1000px 500px at -10% 20%, rgba(14, 165, 233, 0.03), transparent);
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --surface-hover: #f1f5f9;
    --surface-border: #e2e8f0;
    --surface-border-subtle: #f1f5f9;

    --sidebar-bg: #ffffff;
    --sidebar-border: #e2e8f0;
    --sidebar-brand-title: #0f172a;
    --sidebar-text: #64748b;
    --sidebar-text-hover: #0f172a;
    --sidebar-hover-bg: #f1f5f9;
    --sidebar-active-bg: #eef2ff;
    --sidebar-active-text: #4f46e5;
    --sidebar-active-bar: #4f46e5;
    --sidebar-section-title: #94a3b8;
    --sidebar-scrollbar-thumb: rgba(0, 0, 0, 0.08);

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --text-faint: #94a3b8;

    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-subtle: #eef2ff;
    --primary-glow: rgba(79, 70, 229, 0.25);
    --primary-gradient: linear-gradient(135deg, #4f46e5 0%, #3b82f6 100%);

    --success: #10b981;
    --success-subtle: #ecfdf5;
    --warning: #f59e0b;
    --warning-subtle: #fffbeb;
    --danger: #ef4444;
    --danger-subtle: #fef2f2;
    --info: #0ea5e9;
    --info-subtle: #f0f9ff;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.03);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.06), 0 1px 2px -1px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.06), 0 4px 6px -4px rgba(0, 0, 0, 0.06);
    --shadow-pop: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);

    --sidebar-w: 260px;
    --topbar-h: 64px;
}

[data-theme="dark"] {
    --bg-body: #090d16;
    --bg-body-radial: radial-gradient(1200px 600px at 100% -10%, rgba(99, 102, 241, 0.08), transparent),
                      radial-gradient(1000px 500px at -10% 20%, rgba(14, 165, 233, 0.06), transparent);
    --surface: #111827;
    --surface-alt: #162032;
    --surface-hover: #1a253a;
    --surface-border: #1f293d;
    --surface-border-subtle: #192233;

    --sidebar-bg: #090d16;
    --sidebar-border: #1f293d;
    --sidebar-brand-title: #ffffff;
    --sidebar-text: #94a3b8;
    --sidebar-text-hover: #f1f5f9;
    --sidebar-hover-bg: rgba(255, 255, 255, 0.05);
    --sidebar-active-bg: rgba(99, 102, 241, 0.2);
    --sidebar-active-text: #ffffff;
    --sidebar-active-bar: #818cf8;
    --sidebar-section-title: #475569;
    --sidebar-scrollbar-thumb: rgba(255, 255, 255, 0.1);

    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --text-faint: #64748b;

    --primary: #6366f1;
    --primary-hover: #818cf8;
    --primary-subtle: rgba(99, 102, 241, 0.15);
    --primary-glow: rgba(99, 102, 241, 0.35);
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #38bdf8 100%);

    --success: #34d399;
    --success-subtle: rgba(52, 211, 153, 0.12);
    --warning: #fbbf24;
    --warning-subtle: rgba(251, 191, 36, 0.12);
    --danger: #f87171;
    --danger-subtle: rgba(248, 113, 113, 0.12);
    --info: #38bdf8;
    --info-subtle: rgba(56, 189, 248, 0.12);

    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 2px 4px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 8px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 20px -3px rgba(0, 0, 0, 0.5);
    --shadow-pop: 0 20px 30px -5px rgba(0, 0, 0, 0.6);
}

/* ==========================================================================
   BASE RESET & TYPOGRAPHY
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-body);
    background-image: var(--bg-body-radial);
    background-attachment: fixed;
    color: var(--text-primary);
    font-size: 0.915rem;
    line-height: 1.55;
    margin: 0;
    transition: background-color 0.25s ease, color 0.25s ease;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color 0.15s ease;
}
a:hover {
    color: var(--primary-hover);
}

.mono {
    font-family: var(--font-mono);
    letter-spacing: -0.02em;
}

/* ==========================================================================
   SIDEBAR & NAVIGATION
   ========================================================================== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    z-index: 1040;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: var(--shadow-lg);
}

.sidebar-header {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--sidebar-border);
    gap: 0.75rem;
}

.brand-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--primary-gradient);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    box-shadow: 0 4px 12px var(--primary-glow);
}

.brand-title {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--sidebar-brand-title);
    letter-spacing: -0.02em;
}

.brand-subtitle {
    font-size: 0.68rem;
    color: var(--sidebar-text);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem;
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}
.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--sidebar-scrollbar-thumb);
    border-radius: 4px;
}

.nav-section-title {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    color: var(--sidebar-section-title);
    padding: 0.85rem 0.75rem 0.35rem;
    margin: 0;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    color: var(--sidebar-text);
    font-weight: 500;
    font-size: 0.88rem;
    border-radius: var(--radius-sm);
    transition: all 0.18s ease;
    position: relative;
    margin-bottom: 2px;
}

.sidebar-nav .nav-link i {
    font-size: 1.05rem;
    transition: transform 0.18s ease, color 0.18s ease;
}

.sidebar-nav .nav-link:hover {
    color: var(--sidebar-text-hover);
    background: var(--sidebar-hover-bg);
}
.sidebar-nav .nav-link:hover i {
    transform: translateX(2px);
    color: var(--primary);
}

.sidebar-nav .nav-link.active {
    color: var(--sidebar-active-text);
    background: var(--sidebar-active-bg);
    font-weight: 600;
}

.sidebar-nav .nav-link.active::before {
    content: '';
    position: absolute;
    left: -0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 20px;
    border-radius: 0 4px 4px 0;
    background: var(--sidebar-active-bar);
    box-shadow: 0 0 10px var(--primary);
}

.sidebar-nav .nav-link .badge-counter {
    margin-left: auto;
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 20px;
    font-weight: 600;
}

.sidebar-footer {
    padding: 0.85rem 1rem;
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ==========================================================================
   MAIN CONTENT & TOPBAR
   ========================================================================== */
.main-wrapper {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--surface-border);
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: background 0.25s ease, border-color 0.25s ease;
}

.page-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Quick Search Input in Topbar */
.quick-search-box {
    position: relative;
    width: 240px;
}
.quick-search-box input {
    background: var(--surface-alt);
    border: 1px solid var(--surface-border);
    border-radius: 20px;
    padding: 0.4rem 1rem 0.4rem 2.2rem;
    font-size: 0.825rem;
    color: var(--text-primary);
    width: 100%;
    transition: all 0.2s ease;
}
.quick-search-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
    background: var(--surface);
    width: 280px;
}
.quick-search-box i {
    position: absolute;
    left: 0.8rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.85rem;
    pointer-events: none;
}

/* Theme Toggle Button */
.btn-theme-toggle {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--surface-alt);
    border: 1px solid var(--surface-border);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    cursor: pointer;
    transition: all 0.2s ease;
}
.btn-theme-toggle:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
    transform: rotate(20deg) scale(1.05);
}

/* User Profile Badge */
.user-menu-pill {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.35rem 0.65rem;
    border-radius: 24px;
    background: var(--surface-alt);
    border: 1px solid var(--surface-border);
    color: var(--text-primary);
    text-decoration: none;
    transition: all 0.15s ease;
}
.user-menu-pill:hover {
    background: var(--surface-hover);
    border-color: var(--primary);
}

.avatar-initial {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--primary-gradient);
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px var(--primary-glow);
}

.content-body {
    flex: 1;
    padding: 1.5rem;
}

/* ==========================================================================
   CARDS & BENTO GRID ARCHITECTURE
   ========================================================================== */
.card {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    overflow: hidden;
}

.card:hover {
    border-color: rgba(99, 102, 241, 0.2);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--surface-border);
    padding: 1rem 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body {
    padding: 1.25rem;
}

.card-footer {
    background: var(--surface-alt);
    border-top: 1px solid var(--surface-border);
    padding: 0.85rem 1.25rem;
}

/* Bento KPI Stat Cards */
.stat-card {
    position: relative;
    border-radius: var(--radius-lg);
    background: var(--surface);
    border: 1px solid var(--surface-border);
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary-gradient);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.stat-card:hover::after {
    opacity: 1;
}

.stat-card .label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.stat-card .value {
    font-family: var(--font-mono);
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    letter-spacing: -0.03em;
}

.stat-card .sub-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.stat-card .icon-box {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    flex-shrink: 0;
    box-shadow: var(--shadow-xs);
}

.icon-box.primary {
    background: var(--primary-subtle);
    color: var(--primary);
}
.icon-box.success {
    background: var(--success-subtle);
    color: var(--success);
}
.icon-box.warning {
    background: var(--warning-subtle);
    color: var(--warning);
}
.icon-box.danger {
    background: var(--danger-subtle);
    color: var(--danger);
}
.icon-box.info {
    background: var(--info-subtle);
    color: var(--info);
}

/* ==========================================================================
   TABLES & DATA DISPLAY
   ========================================================================== */
.table-responsive {
    border-radius: var(--radius-md);
}

.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text-primary);
    --bs-table-border-color: var(--surface-border);
    margin-bottom: 0;
    vertical-align: middle;
    font-size: 0.88rem;
}

.table > thead {
    background: var(--surface-alt);
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 700;
    border-bottom: 1px solid var(--surface-border);
}

.table > thead th {
    padding: 0.75rem 1rem;
    font-weight: 700;
    white-space: nowrap;
}

.table > tbody > tr {
    transition: background-color 0.15s ease;
}

.table > tbody > tr:hover {
    background-color: var(--surface-hover);
}

.table > tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--surface-border);
}

/* Interactive Table Filter Bar */
.table-filter-bar {
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--surface-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    background: var(--surface);
}

.table-search-input {
    position: relative;
    max-width: 260px;
    width: 100%;
}
.table-search-input input {
    width: 100%;
    padding: 0.4rem 0.85rem 0.4rem 2.2rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--surface-border);
    background: var(--surface-alt);
    font-size: 0.825rem;
    color: var(--text-primary);
}
.table-search-input input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--surface);
}
.table-search-input i {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ==========================================================================
   BADGES & PILLS WITH DOT INDICATORS
   ========================================================================== */
.badge-dot {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.25rem 0.65rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-dot::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.badge-dot.pulse::before {
    box-shadow: 0 0 0 0 currentColor;
    animation: badgePulse 2s infinite;
}

@keyframes badgePulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.badge-soft-success {
    background: var(--success-subtle);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.2);
}
.badge-soft-danger {
    background: var(--danger-subtle);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}
.badge-soft-warning {
    background: var(--warning-subtle);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.2);
}
.badge-soft-info {
    background: var(--info-subtle);
    color: var(--info);
    border: 1px solid rgba(14, 165, 233, 0.2);
}
.badge-soft-primary {
    background: var(--primary-subtle);
    color: var(--primary);
    border: 1px solid rgba(99, 102, 241, 0.2);
}
.badge-soft-secondary {
    background: var(--surface-alt);
    color: var(--text-muted);
    border: 1px solid var(--surface-border);
}

/* Copyable IMEI Chip */
.chip-imei {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    padding: 0.2rem 0.5rem;
    background: var(--surface-alt);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    transition: all 0.15s ease;
}
.chip-imei:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-subtle);
}

/* ==========================================================================
   BUTTONS & FORM CONTROLS
   ========================================================================== */
.btn {
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    transition: all 0.18s ease;
    box-shadow: var(--shadow-xs);
}

.btn:active {
    transform: translateY(1px) scale(0.99);
}

.btn-primary {
    background: var(--primary-gradient);
    border: none;
    color: #fff;
    box-shadow: 0 4px 12px var(--primary-glow);
}
.btn-primary:hover {
    background: var(--primary-gradient);
    filter: brightness(1.08);
    box-shadow: 0 6px 16px var(--primary-glow);
    color: #fff;
}

.btn-outline-secondary {
    border-color: var(--surface-border);
    color: var(--text-secondary);
    background: var(--surface);
}
.btn-outline-secondary:hover {
    background: var(--surface-alt);
    border-color: var(--text-muted);
    color: var(--text-primary);
}

.form-control, .form-select {
    background-color: var(--surface);
    border: 1px solid var(--surface-border);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.85rem;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.form-control:focus, .form-select:focus {
    background-color: var(--surface);
    color: var(--text-primary);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
    outline: none;
}

.form-label {
    font-weight: 600;
    font-size: 0.825rem;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

/* ==========================================================================
   TOAST NOTIFICATIONS
   ========================================================================== */
.toast-container-custom {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.modern-toast {
    pointer-events: auto;
    min-width: 300px;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-pop);
    padding: 0.85rem 1.15rem;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    color: var(--text-primary);
    animation: toastSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.modern-toast.toast-success {
    border-left-color: var(--success);
}
.modern-toast.toast-error {
    border-left-color: var(--danger);
}
.modern-toast.toast-warning {
    border-left-color: var(--warning);
}

.modern-toast i {
    font-size: 1.25rem;
}
.modern-toast.toast-success i { color: var(--success); }
.modern-toast.toast-error i { color: var(--danger); }
.modern-toast.toast-warning i { color: var(--warning); }

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(40px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

/* ==========================================================================
   RESPONSIVE DESIGN (MOBILE / TABLET)
   ========================================================================== */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1035;
}

@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.show {
        transform: translateX(0);
    }
    .sidebar-backdrop.show {
        display: block;
    }
    .main-wrapper {
        margin-left: 0;
    }
    .quick-search-box {
        display: none;
    }
}
