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

/* ── Design Tokens ─────────────────────────────────────────── */
:root {
    --color-primary:        #2B5BA8;
    --color-primary-dark:   #0D1B3E;
    --color-primary-icon:   #3F5FA0;
    --color-primary-light:  #EAF0FB;
    --color-accent:         #F97316;
    --color-accent-hover:   #EA6A0A;

    --color-bg:             #F1F5F9;
    --color-surface:        #FFFFFF;
    --color-border:         #E2E8F0;
    --color-border-strong:  #CBD5E1;

    --color-text-primary:   #0F172A;
    --color-text-secondary: #64748B;
    --color-text-muted:     #94A3B8;

    --color-success:        #059669;
    --color-success-bg:     #ECFDF5;
    --color-warning:        #D97706;
    --color-warning-bg:     #FFFBEB;
    --color-error:          #DC2626;
    --color-error-bg:       #FEF2F2;

    --radius-sm:  4px;
    --radius-md:  8px;
    --radius-lg:  12px;

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

    --font-heading: 'Inter', sans-serif;
    --font-data:    'IBM Plex Sans', sans-serif;

    /* ── Dashboard / theme tokens (light defaults) ──────────────── */
    --card-bg:              #FFFFFF;
    --card-inner-bg:        #F8FAFC;
    --chip-border:          #E2E8F0;
    --chip-color:           #64748B;
    --filter-input-bg:      #FFFFFF;
    --filter-input-color:   #0F172A;
    --filter-input-border:  #E2E8F0;
    --chart-grid:           rgba(0,0,0,.05);
    --chart-tick:           #94A3B8;
    --chart-legend:         #64748B;
    --table-td-color:       #374151;
    --table-border:         #F1F5F9;
    --table-alt-bg:         #F8FAFC;
    --hm-border:            #E2E8F0;
    --hm-header-color:      #64748B;
}

/* ── Dark Theme ─────────────────────────────────────────────────── */
[data-theme="dark"] {
    --color-bg:             #0F172A;
    --color-surface:        #1E293B;
    --color-border:         #334155;
    --color-border-strong:  #475569;
    --color-text-primary:   #F1F5F9;
    --color-text-secondary: #94A3B8;
    --color-text-muted:     #64748B;
    --color-primary-light:  rgba(43,91,168,0.15);
    --color-success-bg:     rgba(5,150,105,0.12);
    --color-warning-bg:     rgba(217,119,6,0.12);
    --color-error-bg:       rgba(220,38,38,0.12);

    --card-bg:              #1E293B;
    --card-inner-bg:        #0F172A;
    --chip-border:          #334155;
    --chip-color:           #94A3B8;
    --filter-input-bg:      #0F172A;
    --filter-input-color:   #E2E8F0;
    --filter-input-border:  #334155;
    --chart-grid:           rgba(255,255,255,.05);
    --chart-tick:           #64748B;
    --chart-legend:         #94A3B8;
    --table-td-color:       #CBD5E1;
    --table-border:         #1E293B;
    --table-alt-bg:         #0F172A;
    --hm-border:            #334155;
    --hm-header-color:      #94A3B8;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font-data); background: var(--color-bg); color: var(--color-text-primary); font-size: 14px; line-height: 1.6; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--color-primary-dark);
    color: #CBD5E1;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; right: 0;
    height: 100vh;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-header {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    padding: 20px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: var(--topbar-h);
}

.sidebar-logo { width: 36px; height: 36px; border-radius: 50%; }
.sidebar-brand { font-family: var(--font-heading); font-size: 16px; font-weight: 700; color: #fff; line-height: 1.2; }
.sidebar-brand span { display: block; font-size: 11px; font-weight: 400; color: rgba(255,255,255,0.6); }

.sidebar-nav { padding: 12px 8px; flex: 1; }
.nav-section-title {
    font-size: 10px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.08em; color: #64748B; padding: 16px 8px 6px;
}
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: var(--radius-md);
    color: #CBD5E1; font-size: 13px; font-weight: 500;
    transition: background 0.15s;
    margin-bottom: 2px; cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--color-primary); color: #fff; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 12px; color: #64748B;
}

/* ── Main Content ──────────────────────────────────────────── */
.main-content { margin-right: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    height: var(--topbar-h);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-family: var(--font-heading); font-size: 18px; font-weight: 600; }

.topbar-user { display: flex; align-items: center; gap: 10px; }
.user-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--color-primary-light);
    color: var(--color-primary);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 14px;
}
.user-info { line-height: 1.3; }
.user-name { font-size: 13px; font-weight: 600; }
.user-company { font-size: 11px; color: var(--color-text-secondary); }

.page-body { padding: 24px; flex: 1; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px;
}
.card-header { margin-bottom: 16px; }
.card-title { font-family: var(--font-heading); font-size: 16px; font-weight: 600; }

/* ── KPI Cards ─────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px; position: relative; overflow: hidden;
}
.kpi-card::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0;
    height: 3px; background: linear-gradient(90deg, var(--color-primary), var(--color-primary-dark));
}
.kpi-label { font-size: 12px; font-weight: 500; color: var(--color-text-secondary); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-family: var(--font-heading); font-size: 28px; font-weight: 700; color: var(--color-text-primary); margin: 4px 0; }
.kpi-sub { font-size: 12px; color: var(--color-text-muted); }

/* ── Company Cards ─────────────────────────────────────────── */
.company-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.company-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    cursor: pointer; transition: box-shadow 0.2s, border-color 0.2s;
    display: flex; flex-direction: column; gap: 12px;
}
.company-card:hover { box-shadow: 0 4px 16px rgba(43,91,168,0.12); border-color: var(--color-primary); text-decoration: none; }
.company-card-header { display: flex; align-items: flex-start; justify-content: space-between; }
.company-name { font-family: var(--font-heading); font-size: 15px; font-weight: 600; color: var(--color-text-primary); }
.company-zone { font-size: 12px; color: var(--color-text-secondary); margin-top: 2px; }
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 8px; border-radius: 100px; font-size: 11px; font-weight: 500;
}
.badge-online  { background: var(--color-success-bg); color: var(--color-success); }
.badge-offline { background: var(--color-error-bg);   color: var(--color-error); }
.company-location { font-size: 12px; color: var(--color-text-secondary); display: flex; align-items: center; gap: 4px; }
.company-card-footer { display: flex; justify-content: flex-end; }

/* ── Tables ────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--color-border); }
.data-table { width: 100%; border-collapse: collapse; font-family: var(--font-data); }
.data-table th {
    background: var(--card-inner-bg); color: var(--color-text-secondary);
    font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
    padding: 10px 16px; border-bottom: 2px solid var(--color-border); text-align: start; white-space: nowrap;
}
.data-table td { padding: 10px 16px; font-size: 13px; border-bottom: 1px solid var(--table-border); color: var(--table-td-color); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--color-primary-light); }
.data-table tr:nth-child(even) td { background: var(--table-alt-bg); }
.data-table tr:nth-child(even):hover td { background: var(--color-primary-light); }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 20px; border-radius: var(--radius-md);
    font-size: 14px; font-weight: 500; font-family: var(--font-data);
    border: none; cursor: pointer; transition: background 0.15s;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: #1E4A8F; color: #fff; }
.btn-accent  { background: var(--color-accent); color: #fff; }
.btn-accent:hover { background: var(--color-accent-hover); color: #fff; }
.btn-ghost   { background: transparent; color: var(--color-primary); border: 1.5px solid var(--color-primary); }
.btn-ghost:hover { background: var(--color-primary-light); }
.btn-danger  { background: var(--color-error); color: #fff; }
.btn-sm { padding: 5px 14px; font-size: 13px; }
.btn-lg { padding: 11px 28px; font-size: 15px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Forms ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.form-control {
    width: 100%; padding: 9px 12px;
    border: 1.5px solid var(--color-border); border-radius: var(--radius-md);
    font-size: 14px; font-family: var(--font-data); background: var(--color-surface);
    color: var(--color-text-primary); transition: border-color 0.15s; outline: none;
}
.form-control:focus { border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(43,91,168,0.1); }
.form-control.is-invalid { border-color: var(--color-error); }
.field-error { font-size: 12px; color: var(--color-error); margin-top: 4px; }

/* ── Alerts ────────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: var(--radius-md); font-size: 13px; margin-bottom: 16px; }
.alert-error   { background: var(--color-error-bg);   color: var(--color-error);   border: 1px solid rgba(220,38,38,0.2); }
.alert-success { background: var(--color-success-bg); color: var(--color-success); border: 1px solid rgba(5,150,105,0.2); }
.alert-warning { background: var(--color-warning-bg); color: var(--color-warning); border: 1px solid rgba(217,119,6,0.2); }

/* ── Auth Pages ────────────────────────────────────────────── */
.auth-body {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--color-primary-dark) 0%, #1a3a6e 100%);
    padding: 24px;
}
.auth-card {
    background: var(--color-surface); border-radius: var(--radius-lg);
    padding: 40px; width: 100%; max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo img { width: 90px; }
.auth-title { font-family: var(--font-heading); font-size: 22px; font-weight: 700; text-align: center; margin-bottom: 4px; }
.auth-subtitle { font-size: 13px; color: var(--color-text-secondary); text-align: center; margin-bottom: 24px; }

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

/* ── Spinner ───────────────────────────────────────────────── */
.spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Page Heading ──────────────────────────────────────────── */
.page-heading { margin-bottom: 20px; }
.page-heading h1 { font-family: var(--font-heading); font-size: 22px; font-weight: 700; }
.page-heading p  { font-size: 13px; color: var(--color-text-secondary); margin-top: 2px; }

/* ── Utilities ─────────────────────────────────────────────── */
.text-muted { color: var(--color-text-secondary); }
.text-sm    { font-size: 12px; }
.fw-600     { font-weight: 600; }
.d-flex     { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mt-3 { margin-top: 12px; }
.w-100 { width: 100%; }

/* ── Hamburger / mobile sidebar toggle ─────────────────────── */
.hamburger-btn {
    display: none;
    background: none; border: none; cursor: pointer;
    color: var(--color-text-primary); font-size: 22px;
    padding: 4px 8px; border-radius: var(--radius-sm);
    line-height: 1;
}
.hamburger-btn:hover { background: var(--color-primary-light); }

/* ── Theme toggle button ────────────────────────────────────────── */
.theme-toggle-btn {
    background: none;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 5px 10px;
    font-size: 16px;
    cursor: pointer;
    color: var(--color-text-primary);
    transition: background 0.15s, border-color 0.15s;
    line-height: 1;
}
.theme-toggle-btn:hover { background: var(--color-primary-light); }

/* ── Sidebar overlay (mobile) ──────────────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}
.sidebar-overlay.visible { opacity: 1; pointer-events: auto; }

/* ── Disabled nav item ─────────────────────────────────────── */
.nav-item.disabled {
    opacity: 0.35; cursor: not-allowed; pointer-events: none;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(100%);
        transition: transform 0.3s ease;
        z-index: 100;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay { display: block; }
    .main-content { margin-right: 0; }
    .hamburger-btn { display: inline-flex; align-items: center; }
    .topbar { padding: 0 16px; }
    .page-body { padding: 16px; }
    .company-grid { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .auth-card { padding: 28px 20px; }
}
@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
}
