/* ============================================================
   XCRM — Main CSS Design System
   Dark Glassmorphism Theme with Purple/Indigo Accents
   ============================================================ */

/* ── Custom Properties ─────────────────────────────────────── */
:root {
    /* Colors */
    --bg-base:       #060d1a;
    --bg-surface:    #0d1b2e;
    --bg-card:       #0f2342;
    --bg-elevated:   #132d54;
    --bg-hover:      #1a3a66;

    --accent-1:      #6366f1;
    --accent-2:      #8b5cf6;
    --accent-grad:   linear-gradient(135deg, #6366f1, #8b5cf6);
    --accent-glow:   0 0 30px rgba(99, 102, 241, 0.35);

    --green:         #10b981;
    --green-soft:    rgba(16, 185, 129, 0.15);
    --yellow:        #f59e0b;
    --yellow-soft:   rgba(245, 158, 11, 0.15);
    --red:           #ef4444;
    --red-soft:      rgba(239, 68, 68, 0.15);
    --blue:          #3b82f6;
    --blue-soft:     rgba(59, 130, 246, 0.15);

    --text-primary:  #f0f6ff;
    --text-secondary:#94a3b8;
    --text-muted:    #475569;
    --text-accent:   #818cf8;

    --border:        rgba(99, 102, 241, 0.15);
    --border-hover:  rgba(99, 102, 241, 0.35);
    --glass:         rgba(13, 27, 46, 0.75);
    --glass-blur:    blur(16px);

    /* Spacing */
    --sidebar-w:     260px;
    --topbar-h:      64px;
    --radius:        12px;
    --radius-lg:     20px;
    --radius-sm:     8px;

    /* Transitions */
    --transition:    all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);

    /* Shadows */
    --shadow-sm:     0 2px 8px rgba(0,0,0,0.3);
    --shadow-md:     0 8px 24px rgba(0,0,0,0.4);
    --shadow-lg:     0 24px 48px rgba(0,0,0,0.5);
    --shadow-accent: 0 8px 32px rgba(99, 102, 241, 0.3);
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    opacity: 1;
    transition: opacity 0.3s ease;
}
a { color: inherit; text-decoration: none; cursor: pointer; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input, select, textarea { font-family: inherit; }
svg { fill: currentColor; width: 1.2em; height: 1.2em; flex-shrink: 0; }
img { max-width: 100%; }

/* ── Loading Screen ────────────────────────────────────────── */
.loading-screen {
    position: fixed; inset: 0;
    background: var(--bg-base);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    z-index: 9999;
    gap: 32px;
}
.loading-logo {
    display: flex; align-items: baseline; gap: 4px;
    font-size: 3rem; font-weight: 800;
}
.logo-x  { background: var(--accent-grad); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.logo-crm{ color: var(--text-secondary); font-weight: 300; }
.loading-bar {
    width: 200px; height: 3px;
    background: var(--bg-elevated);
    border-radius: 99px; overflow: hidden;
}
.loading-bar-fill {
    height: 100%; width: 30%;
    background: var(--accent-grad);
    border-radius: 99px;
    animation: loadingSlide 1.5s ease-in-out infinite;
}
@keyframes loadingSlide {
    0%   { transform: translateX(-100%); width: 40%; }
    50%  { width: 70%; }
    100% { transform: translateX(600%); width: 40%; }
}

/* ── Login Screen ──────────────────────────────────────────── */
.login-screen {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-base);
    z-index: 100;
}
.login-bg {
    position: fixed; inset: 0; overflow: hidden; pointer-events: none;
}
.login-orb {
    position: absolute; border-radius: 50%;
    filter: blur(80px); opacity: 0.4;
    animation: orbFloat 8s ease-in-out infinite;
}
.orb1 { width: 400px; height: 400px; background: #6366f1; top: -100px; right: -100px; animation-delay: 0s; }
.orb2 { width: 300px; height: 300px; background: #8b5cf6; bottom: -50px; left: -50px; animation-delay: 2s; }
.orb3 { width: 200px; height: 200px; background: #3b82f6; top: 50%; left: 50%; animation-delay: 4s; }
@keyframes orbFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33%       { transform: translate(20px, -20px) scale(1.05); }
    66%       { transform: translate(-15px, 15px) scale(0.97); }
}

.login-card {
    position: relative; z-index: 1;
    width: 100%; max-width: 420px;
    margin: 20px;
    background: var(--glass);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px;
    box-shadow: var(--shadow-lg), var(--accent-glow);
    animation: fadeInUp 0.5s ease;
}
.login-header { text-align: center; margin-bottom: 32px; }
.login-logo {
    display: flex; align-items: baseline; justify-content: center;
    gap: 4px; font-size: 2.5rem; font-weight: 800; margin-bottom: 8px;
}
.login-subtitle { color: var(--text-secondary); font-size: 0.9rem; }
.login-form { display: flex; flex-direction: column; gap: 20px; }
.login-error {
    background: var(--red-soft); border: 1px solid var(--red);
    color: var(--red); padding: 10px 14px; border-radius: var(--radius-sm);
    font-size: 0.875rem;
}
.login-footer { text-align: center; margin-top: 24px; color: var(--text-muted); font-size: 0.8rem; }

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

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    position: fixed; left: 0; top: 0; bottom: 0;
    z-index: 200;
    transition: var(--transition-slow);
    overflow: hidden;
}
.sidebar.collapsed { width: 72px; }

.sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 16px;
    border-bottom: 1px solid var(--border);
    min-height: 70px;
}
.sidebar-logo {
    display: flex; align-items: baseline; gap: 3px;
    font-size: 1.5rem; font-weight: 800;
    white-space: nowrap; overflow: hidden;
}
.logo-x  { background: var(--accent-grad); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.logo-crm{ color: var(--text-secondary); font-weight: 300; }

.sidebar-toggle {
    color: var(--text-muted); padding: 6px; border-radius: var(--radius-sm);
    transition: var(--transition); flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--bg-elevated); color: var(--text-primary); }

/* Company Switcher */
.company-switcher { padding: 12px; border-bottom: 1px solid var(--border); position: relative; }
.company-current {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    cursor: pointer; transition: var(--transition);
    border: 1px solid transparent;
}
.company-current:hover { background: var(--bg-elevated); border-color: var(--border); }
.company-avatar {
    width: 36px; height: 36px; border-radius: 10px;
    background: var(--accent-grad); display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 1rem; flex-shrink: 0;
    box-shadow: var(--shadow-accent);
}
.company-info { flex: 1; overflow: hidden; }
.company-name { font-weight: 600; font-size: 0.875rem; line-height: 1.2; overflow-wrap: break-word; }
.company-switch-hint { font-size: 0.7rem; color: var(--text-muted); }
.company-chevron { color: var(--text-muted); width: 1em; height: 1em; transition: var(--transition); }
.company-dropdown {
    position: absolute; left: 12px; right: 12px; top: calc(100% - 4px);
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-md);
    z-index: 100; overflow: hidden;
    animation: fadeInUp 0.15s ease;
}
.company-option {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; cursor: pointer; transition: var(--transition);
    font-size: 0.875rem;
}
.company-option:hover  { background: var(--bg-elevated); }
.company-option.active { background: var(--accent-1); }
.co-avatar { width: 28px; height: 28px; border-radius: 8px; background: var(--bg-elevated); display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700; }

/* Navigation */
.sidebar-nav {
    flex: 1; overflow-y: auto; padding: 12px 8px;
    scrollbar-width: thin; scrollbar-color: var(--bg-elevated) transparent;
}
.nav-section-label {
    font-size: 0.65rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.1em; color: var(--text-muted);
    padding: 12px 12px 4px; white-space: nowrap; overflow: hidden;
}
.sidebar.collapsed .nav-section-label { opacity: 0; }
.sidebar.collapsed .company-info, 
.sidebar.collapsed .company-chevron,
.sidebar.collapsed .user-info,
.sidebar.collapsed .logo-crm,
.sidebar.collapsed .logout-btn { display: none; }
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    color: var(--text-secondary); font-size: 0.875rem; font-weight: 500;
    transition: var(--transition); margin-bottom: 2px;
    white-space: nowrap; overflow: hidden; position: relative;
}
.nav-item svg { width: 1.2em; height: 1.2em; flex-shrink: 0; transition: var(--transition); }
.nav-item:hover { background: var(--bg-elevated); color: var(--text-primary); }
.nav-item.active {
    background: linear-gradient(135deg, rgba(99,102,241,0.2), rgba(139,92,246,0.1));
    color: #a5b4fc;
    border: 1px solid rgba(99,102,241,0.3);
    box-shadow: 0 0 20px rgba(99,102,241,0.1);
}
.nav-item.active svg { color: var(--accent-1); }
.nav-badge {
    margin-left: auto; background: var(--red); color: #fff;
    font-size: 0.65rem; font-weight: 700; padding: 2px 6px;
    border-radius: 99px; line-height: 1.4; flex-shrink: 0;
}

/* Sidebar User */
.sidebar-user {
    display: flex; align-items: center; gap: 10px;
    padding: 16px; border-top: 1px solid var(--border);
    overflow: hidden;
}
.user-info { flex: 1; overflow: hidden; }
.user-name { font-size: 0.875rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.logout-btn { color: var(--text-muted); padding: 6px; border-radius: var(--radius-sm); transition: var(--transition); flex-shrink: 0; }
.logout-btn:hover { color: var(--red); background: var(--red-soft); }
.user-avatar, .user-avatar-top {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--accent-grad); display: flex; align-items: center;
    justify-content: center; font-weight: 700; font-size: 0.9rem;
    flex-shrink: 0; cursor: pointer; user-select: none;
    box-shadow: var(--shadow-sm);
}

/* ── Top Bar ───────────────────────────────────────────────── */
.main-content {
    width: calc(100% - var(--sidebar-w));
    margin-left: var(--sidebar-w);
    display: flex; flex-direction: column;
    min-height: 100vh; transition: var(--transition-slow);
}
.sidebar.collapsed ~ .main-content { 
    margin-left: 72px; 
    width: calc(100% - 72px);
}

.top-bar {
    height: var(--topbar-h);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; gap: 16px;
    position: sticky; top: 0; z-index: 100;
}
.top-bar-left { display: flex; align-items: center; gap: 16px; }
.top-bar-right { display: flex; align-items: center; gap: 12px; }
.breadcrumb { font-size: 1rem; font-weight: 600; color: var(--text-primary); }
.mobile-menu-btn { display: none; color: var(--text-secondary); padding: 6px; border-radius: var(--radius-sm); }

/* Global Search */
.global-search {
    position: relative; display: flex; align-items: center;
}
.global-search svg { position: absolute; left: 12px; color: var(--text-muted); width: 1em; height: 1em; pointer-events: none; }
.global-search input {
    background: var(--bg-card); border: 1px solid var(--border);
    color: var(--text-primary); padding: 8px 14px 8px 36px;
    border-radius: var(--radius-sm); font-size: 0.875rem; width: 240px;
    transition: var(--transition);
}
.global-search input:focus { outline: none; border-color: var(--accent-1); width: 300px; box-shadow: 0 0 0 3px rgba(99,102,241,0.15); }
.global-search input::placeholder { color: var(--text-muted); }
.search-results {
    position: absolute; top: calc(100% + 6px); left: 0; right: 0;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-lg); z-index: 200;
    max-height: 300px; overflow-y: auto;
    animation: fadeInUp 0.15s ease;
}
.search-result-item {
    padding: 10px 14px; cursor: pointer; transition: var(--transition);
    border-bottom: 1px solid var(--border); font-size: 0.875rem;
}
.search-result-item:hover { background: var(--bg-elevated); }
.search-result-item:last-child { border-bottom: none; }
.sri-name { font-weight: 600; }
.sri-sub { color: var(--text-muted); font-size: 0.8rem; }

/* Notification Bell */
.notif-bell {
    position: relative; color: var(--text-secondary);
    padding: 8px; border-radius: var(--radius-sm); transition: var(--transition);
}
.notif-bell:hover { color: var(--text-primary); background: var(--bg-elevated); }
.notif-count {
    position: absolute; top: 4px; right: 4px;
    background: var(--red); color: #fff;
    font-size: 0.6rem; font-weight: 700; padding: 1px 5px;
    border-radius: 99px; line-height: 1.4;
}

/* User Dropdown */
.user-menu { position: relative; }
.user-dropdown {
    position: absolute; right: 0; top: calc(100% + 8px);
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-md);
    min-width: 220px; overflow: hidden; z-index: 200;
    animation: fadeInUp 0.15s ease;
}
.dropdown-header { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.dropdown-header div:first-child { font-weight: 600; font-size: 0.875rem; }
.dd-email { color: var(--text-muted); font-size: 0.8rem; margin-top: 2px; }
.dropdown-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 16px; cursor: pointer; transition: var(--transition);
    font-size: 0.875rem; color: var(--text-secondary);
}
.dropdown-item:hover { background: var(--bg-elevated); color: var(--text-primary); }
.dropdown-item.text-danger { color: var(--red); }
.dropdown-item.text-danger:hover { background: var(--red-soft); }
.dropdown-item svg { width: 1em; height: 1em; }
.dropdown-divider { height: 1px; background: var(--border); }

/* ── Page Content ──────────────────────────────────────────── */
.page-content { flex: 1; padding: 28px; overflow-x: hidden; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    transition: var(--transition);
}
.card:hover { border-color: var(--border-hover); }
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px;
}
.card-title { font-size: 1rem; font-weight: 600; }
.card-subtitle { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

/* KPI Cards */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px 24px;
    display: flex; flex-direction: column; gap: 8px;
    position: relative; overflow: hidden;
    transition: var(--transition);
}
.kpi-card::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
}
.kpi-card.indigo::before  { background: var(--accent-grad); }
.kpi-card.green::before   { background: linear-gradient(135deg, #10b981, #34d399); }
.kpi-card.yellow::before  { background: linear-gradient(135deg, #f59e0b, #fbbf24); }
.kpi-card.red::before     { background: linear-gradient(135deg, #ef4444, #f87171); }
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-hover); }
.kpi-label { font-size: 0.75rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.kpi-value { font-size: 2rem; font-weight: 800; line-height: 1; }
.kpi-card.indigo .kpi-value { color: #a5b4fc; }
.kpi-card.green  .kpi-value { color: #34d399; }
.kpi-card.yellow .kpi-value { color: #fbbf24; }
.kpi-card.red    .kpi-value { color: #f87171; }
.kpi-sub { font-size: 0.75rem; color: var(--text-muted); }
.kpi-icon {
    position: absolute; right: 16px; top: 50%;
    transform: translateY(-50%);
    opacity: 0.08; width: 60px; height: 60px;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 8px; padding: 9px 18px; border-radius: var(--radius-sm);
    font-size: 0.875rem; font-weight: 500; transition: var(--transition);
    white-space: nowrap; position: relative; overflow: hidden;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
    background: var(--accent-grad); color: #fff;
    box-shadow: var(--shadow-accent);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); transform: translateY(-1px); box-shadow: 0 12px 32px rgba(99,102,241,0.4); }
.btn-secondary { background: var(--bg-elevated); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent-1); color: #a5b4fc; }
.btn-danger { background: var(--red-soft); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }
.btn-danger:hover:not(:disabled) { background: var(--red); color: #fff; }
.btn-success { background: var(--green-soft); color: var(--green); border: 1px solid rgba(16,185,129,0.3); }
.btn-success:hover:not(:disabled) { background: var(--green); color: #fff; }
.btn-ghost { color: var(--text-secondary); padding: 8px; }
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-elevated); border-radius: var(--radius-sm); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 13px 24px; font-size: 1rem; }
.btn-full { width: 100%; }
.btn-spinner {
    width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff; border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* ── Forms ─────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 0.8rem; font-weight: 500; color: var(--text-secondary); }
.form-label.required::after { content: ' *'; color: var(--red); }
.input-wrapper { position: relative; display: flex; align-items: center; }
.input-icon { position: absolute; left: 12px; color: var(--text-muted); pointer-events: none; width: 1em; height: 1em; }
.form-input {
    width: 100%; background: var(--bg-elevated);
    border: 1px solid var(--border); color: var(--text-primary);
    padding: 10px 14px; border-radius: var(--radius-sm);
    font-size: 0.875rem; transition: var(--transition);
}
.input-wrapper .form-input { padding-left: 38px; }
.form-input:focus { outline: none; border-color: var(--accent-1); box-shadow: 0 0 0 3px rgba(99,102,241,0.15); }
.form-input::placeholder { color: var(--text-muted); }
.form-input:disabled { opacity: 0.5; cursor: not-allowed; }
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2394a3b8'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 1.2em; padding-right: 36px; }
.form-textarea { resize: vertical; min-height: 80px; }
.input-toggle-pass { position: absolute; right: 10px; color: var(--text-muted); padding: 4px; border-radius: 4px; }
.input-toggle-pass:hover { color: var(--text-primary); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: 0.75rem; color: var(--red); margin-top: 4px; }

/* ── Tables ────────────────────────────────────────────────── */
.table-wrapper {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
}
.table-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border); gap: 12px; flex-wrap: wrap;
}
.table-search-wrap { position: relative; flex: 1; max-width: 320px; }
.table-search-wrap svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); width: 1em; height: 1em; }
.table-search {
    width: 100%; padding: 8px 12px 8px 34px;
    background: var(--bg-elevated); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-primary);
    font-size: 0.875rem; transition: var(--transition);
}
.table-search:focus { outline: none; border-color: var(--accent-1); }
.table-actions { display: flex; align-items: center; gap: 8px; }
table { width: 100%; border-collapse: collapse; }
thead { background: var(--bg-elevated); }
th {
    padding: 12px 16px; text-align: left;
    font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.05em; color: var(--text-muted);
    white-space: nowrap; user-select: none;
}
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--text-primary); }
td {
    padding: 13px 16px; font-size: 0.875rem;
    border-top: 1px solid var(--border); vertical-align: middle;
}
tr:hover td { background: var(--bg-elevated); }
tbody tr { transition: var(--transition); }

/* ── Badges / Status ───────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: 99px;
    font-size: 0.7rem; font-weight: 600;
    white-space: nowrap;
}
.badge-green    { background: var(--green-soft);  color: var(--green); }
.badge-yellow   { background: var(--yellow-soft); color: var(--yellow); }
.badge-red      { background: var(--red-soft);    color: var(--red); }
.badge-blue     { background: var(--blue-soft);   color: var(--blue); }
.badge-indigo   { background: rgba(99,102,241,0.15); color: #a5b4fc; }
.badge-gray     { background: rgba(100,116,139,0.2); color: var(--text-muted); }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Expiry Status Badges */
.expiry-active   { color: var(--green);  background: var(--green-soft);  }
.expiry-warning  { color: var(--yellow); background: var(--yellow-soft); }
.expiry-critical { color: #fb923c; background: rgba(251,146,60,0.15); }
.expiry-expired  { color: var(--red);   background: var(--red-soft);    }

/* ── Pagination ────────────────────────────────────────────── */
.pagination {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 20px; border-top: 1px solid var(--border);
    font-size: 0.875rem; color: var(--text-muted);
}
.pagination-controls { display: flex; gap: 4px; }
.page-btn {
    padding: 5px 10px; border-radius: var(--radius-sm);
    transition: var(--transition); font-size: 0.8rem; color: var(--text-secondary);
}
.page-btn:hover   { background: var(--bg-elevated); color: var(--text-primary); }
.page-btn.active  { background: var(--accent-1); color: #fff; }
.page-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Page Header ───────────────────────────────────────────── */
.page-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    margin-bottom: 24px; gap: 16px; flex-wrap: wrap;
}
.page-header-left {}
.page-title { font-size: 1.5rem; font-weight: 700; }
.page-description { color: var(--text-muted); font-size: 0.875rem; margin-top: 4px; }
.page-header-actions { display: flex; align-items: center; gap: 10px; }

/* ── Grid layouts ──────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }

/* ── Tabs ──────────────────────────────────────────────────── */
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 24px; gap: 4px; }
.tab-btn {
    padding: 10px 18px; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    font-size: 0.875rem; font-weight: 500; color: var(--text-muted);
    transition: var(--transition); border: 1px solid transparent;
    border-bottom: none; margin-bottom: -1px;
}
.tab-btn:hover  { color: var(--text-primary); background: var(--bg-elevated); }
.tab-btn.active { color: #a5b4fc; background: var(--bg-card); border-color: var(--border); border-bottom-color: var(--bg-card); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Empty State ───────────────────────────────────────────── */
.empty-state {
    text-align: center; padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state svg { width: 64px; height: 64px; opacity: 0.3; margin-bottom: 16px; }
.empty-state h3 { font-size: 1rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.empty-state p { font-size: 0.875rem; }

/* ── Misc ──────────────────────────────────────────────────── */
.hidden   { display: none !important; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.flex     { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2    { gap: 8px; }
.gap-3    { gap: 12px; }
.gap-4    { gap: 16px; }
.mt-1     { margin-top: 4px; }
.mt-2     { margin-top: 8px; }
.mt-3     { margin-top: 12px; }
.mt-4     { margin-top: 16px; }
.mb-4     { margin-bottom: 16px; }
.fw-600   { font-weight: 600; }
.text-muted { color: var(--text-muted); }
.text-sm  { font-size: 0.8rem; }
.text-green  { color: var(--green); }
.text-red    { color: var(--red); }
.text-yellow { color: var(--yellow); }
.text-accent { color: var(--text-accent); }
.divider  { height: 1px; background: var(--border); margin: 16px 0; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cursor-pointer { cursor: pointer; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── PWA Install Button ─────────────────────────────────────── */
.pwa-install-btn {
    display: flex; align-items: center; gap: 6px;
    padding: 7px 14px;
    background: linear-gradient(135deg, rgba(99,102,241,.2), rgba(139,92,246,.2));
    border: 1px solid rgba(99,102,241,.4);
    border-radius: 8px;
    color: var(--text-accent);
    font-size: 0.8rem; font-weight: 600;
    transition: var(--transition);
    cursor: pointer;
}
.pwa-install-btn:hover {
    background: linear-gradient(135deg, rgba(99,102,241,.35), rgba(139,92,246,.35));
    border-color: var(--accent-1);
    box-shadow: var(--shadow-accent);
}
.pwa-install-btn svg { width: 1rem; height: 1rem; }
@keyframes pwaButtonPulse {
    0%,100% { box-shadow: 0 0 0 0 rgba(99,102,241,.4); }
    50%      { box-shadow: 0 0 0 6px rgba(99,102,241,0); }
}
.pwa-install-animate { animation: pwaButtonPulse 2s ease 3; }

/* ── Safe Area (iPhone notch/dynamic island) ───────────────── */
@supports (padding-top: env(safe-area-inset-top)) {
    .topbar {
        padding-left: max(24px, env(safe-area-inset-left));
        padding-right: max(24px, env(safe-area-inset-right));
    }
    .sidebar {
        padding-bottom: env(safe-area-inset-bottom);
    }
    .mobile-bottom-nav {
        padding-bottom: env(safe-area-inset-bottom);
    }
}
/* Standalone PWA status bar */
body.pwa-standalone .topbar {
    padding-top: env(safe-area-inset-top, 0);
}

/* ── Mobile Bottom Navigation ───────────────────────────────── */
.mobile-bottom-nav {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 900;
    background: var(--glass);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-top: 1px solid var(--border);
    padding: 6px 0 8px;
}
.mobile-bottom-nav-items {
    display: flex; justify-content: space-around; align-items: center;
}
.mobile-nav-item {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 6px 10px; border-radius: 10px;
    color: var(--text-muted); font-size: 0.65rem;
    transition: var(--transition); cursor: pointer;
    min-width: 54px;
}
.mobile-nav-item svg { width: 1.3rem; height: 1.3rem; }
.mobile-nav-item.active { color: var(--accent-1); }
.mobile-nav-item:active { transform: scale(0.92); }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 1200px) {
    :root { --sidebar-w: 220px; }
}

@media (max-width: 1024px) {
    .grid-3 { grid-template-columns: 1fr 1fr; }
    .form-grid-3 { grid-template-columns: 1fr 1fr; }
    .dashboard-grid { grid-template-columns: 1fr !important; }
}

@media (max-width: 768px) {
    :root { --sidebar-w: 0px; --topbar-h: 56px; }

    /* Sidebar: slide-in overlay */
    .sidebar {
        transform: translateX(-280px);
        width: 280px;
        z-index: 1100;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.mobile-open { transform: translateX(0); }
    .sidebar-overlay {
        display: none;
        position: fixed; inset: 0; z-index: 1050;
        background: rgba(0,0,0,0.6);
        backdrop-filter: blur(4px);
    }
    .sidebar-overlay.active { display: block; }

    /* Main layout */
    .main-content { margin-left: 0 !important; padding-bottom: 70px; max-width: 100vw; overflow-x: hidden; }
    .mobile-menu-btn { display: flex !important; }
    .mobile-bottom-nav { display: block; }

    /* Topbar */
    .topbar { padding: 0 14px; gap: 8px; }
    .topbar-left { gap: 8px; }
    .global-search { display: none; } /* Replaced by page-level search on mobile */
    .topbar-right { gap: 6px; }
    .pwa-install-label { display: none; }
    .pwa-install-btn { padding: 7px; }
    .company-switcher-btn { padding: 6px 8px; gap: 0; }

    /* Layout */
    .page-content { padding: 14px; padding-bottom: 80px; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }

    /* Page header */
    .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
    .page-header-actions { width: 100%; justify-content: flex-start; flex-wrap: wrap; }

    /* Tables: mobile card view */
    .table-wrapper { overflow: visible; width: 100%; max-width: 100%; background: transparent; border: none; }
    table, thead, tbody, th, td, tr { display: block; }
    thead tr { position: absolute; top: -9999px; left: -9999px; }
    table { min-width: 0; }
    tr { 
        background: var(--bg-card);
        border: 1px solid var(--border); 
        border-radius: var(--radius); 
        margin-bottom: 12px; 
        overflow: hidden;
    }
    td { 
        border: none; 
        border-bottom: 1px solid var(--border); 
        position: relative; 
        padding: 12px 16px 12px 45%; 
        text-align: right; 
        min-height: 46px;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 8px;
    }
    td:last-child { border-bottom: 0; justify-content: flex-end; }
    td::before { 
        position: absolute; 
        top: 50%; 
        left: 16px; 
        transform: translateY(-50%);
        width: 40%; 
        padding-right: 10px; 
        white-space: nowrap; 
        text-align: left; 
        font-size: 0.75rem;
        font-weight: 600; 
        color: var(--text-muted); 
        text-transform: uppercase;
        content: attr(data-label); 
    }
    .table-toolbar { flex-direction: column; align-items: stretch; gap: 8px; margin-bottom: 16px; }
    .table-search-wrap { max-width: 100%; }
    .table-actions { flex-wrap: wrap; gap: 6px; }

    /* Cards */
    .card { padding: 16px; }
    .kpi-card { padding: 16px 14px; }
    .kpi-value { font-size: 1.8rem; }

    /* Modal: full-screen on small devices */
    .modal-container {
        width: 100vw !important;
        max-width: 100vw !important;
        max-height: 95vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        top: auto;
        margin: 0;
        transform: translateY(100%) !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }
    .modal-container.open { transform: translateY(0) !important; }
    .modal-overlay { align-items: flex-end; }

    /* Filter bar: Wrap elements instead of horizontal scroll to fix dropdown clipping */
    .filter-bar { overflow: visible; flex-wrap: wrap; padding-bottom: 4px; }
    .filter-btn { flex-shrink: 0; }

    /* Client detail tabs: horizontal scroll */
    .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
    .tab-btn { flex-shrink: 0; }

    /* Sub/GPS cards */
    .sub-card { flex-direction: column; align-items: flex-start; gap: 10px; }
    .sub-card-right { align-items: flex-start; flex-direction: row; gap: 8px; }
    .gps-info-grid { grid-template-columns: 1fr 1fr !important; }

    /* Settings: full width sections */
    .settings-section { padding: 16px; }

    /* Buttons */
    .btn-lg { width: 100%; justify-content: center; }
}

@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .login-card { padding: 24px 16px; max-width: 100vw; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
    .login-wrapper { align-items: flex-end; padding: 0; }
    .kpi-value { font-size: 1.6rem; }
    .page-title { font-size: 1.3rem; }
    .gps-info-grid { grid-template-columns: 1fr !important; }
    .client-detail-header { flex-direction: column; }
    .client-avatar-large { width: 56px; height: 56px; font-size: 1.2rem; }
    .fin-summary { grid-template-columns: 1fr; }

    /* Full-width modal on very small screens */
    .modal-body { max-height: 65vh; }
}

/* ── Touch-friendly interactions ────────────────────────────── */
@media (hover: none) and (pointer: coarse) {
    /* Larger tap targets */
    .btn { min-height: 42px; }
    .btn-sm { min-height: 36px; }
    .nav-item { min-height: 44px; }
    .mobile-nav-item { min-height: 50px; }
    .form-input { min-height: 44px; }
    select.form-input { min-height: 44px; }

    /* Remove hover effects that look odd on touch */
    .table-row:hover { background: transparent; }
    .hover-lift:hover { transform: none; box-shadow: var(--shadow-md); }

    /* Larger checkboxes */
    input[type="checkbox"] { width: 20px; height: 20px; }
}

/* ── Print styles ────────────────────────────────────────────── */
@media print {
    .sidebar, .topbar, .mobile-bottom-nav, .pwa-install-btn { display: none !important; }
    .main-content { margin: 0 !important; }
    .page-content { padding: 0 !important; }
    body { background: white; color: black; }
    .card { border: 1px solid #ddd; box-shadow: none; background: white; }
}


/* Hide logo completely when sidebar is collapsed */
.sidebar.collapsed .sidebar-logo { display: none; }
.sidebar.collapsed .sidebar-header { justify-content: center; }
