/* =============================================================
   main.css — Mapas Compras & Vendas
   Design System: Dark Premium Theme
   ============================================================= */

/* ---- CSS Variables / Design Tokens ---- */
:root {
    /* Colors */
    --color-bg-primary: #0d0d1a;
    --color-bg-secondary: #12121f;
    --color-bg-card: #1a1a2e;
    --color-bg-card-hover: #1f1f38;
    --color-sidebar: #0f0f1e;
    --color-topbar: #12121f;

    /* Accent / Brand */
    --color-accent: #6366f1;
    --color-accent-light: #818cf8;
    --color-accent-dark: #4f46e5;
    --color-accent-glow: rgba(99, 102, 241, 0.25);

    /* Status colors */
    --color-success: #10b981;
    --color-success-bg: rgba(16, 185, 129, 0.12);
    --color-danger: #ef4444;
    --color-danger-bg: rgba(239, 68, 68, 0.12);
    --color-warning: #f59e0b;
    --color-warning-bg: rgba(245, 158, 11, 0.12);
    --color-info: #3b82f6;
    --color-info-bg: rgba(59, 130, 246, 0.12);

    /* Text */
    --color-text-primary: #e2e8f0;
    --color-text-secondary: #94a3b8;
    --color-text-muted: #64748b;

    /* Borders */
    --color-border: rgba(255, 255, 255, 0.06);
    --color-border-active: rgba(99, 102, 241, 0.5);

    /* Layout */
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;
    --topbar-height: 60px;

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.25s ease;
    --transition-slow: 0.4s ease;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--color-accent-glow);

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;
}

/* ---- Reset & Base ---- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-family);
    background-color: var(--color-bg-primary);
    color: var(--color-text-primary);
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
    font-size: 0.9rem;
    line-height: 1.6;
}

/* ============================================================
   SIDEBAR
============================================================ */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: var(--sidebar-width);
    background: var(--color-sidebar);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform var(--transition-base), width var(--transition-base);
    overflow: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 16px;
    border-bottom: 1px solid var(--color-border);
    min-height: var(--topbar-height);
}

.brand-logo {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--color-accent), var(--color-accent-dark));
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: white;
    flex-shrink: 0;
    box-shadow: var(--shadow-glow);
}

.brand-text {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.brand-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text-primary);
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.brand-subtitle {
    font-size: 0.65rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 0;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
}

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

.nav-section {
    padding: 4px 0 8px;
}

.nav-section-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--color-text-muted);
    padding: 8px 20px 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all var(--transition-fast);
    position: relative;
    white-space: nowrap;
}

.nav-item:hover {
    color: var(--color-text-primary);
    background: rgba(255, 255, 255, 0.04);
}

.nav-item.active {
    color: var(--color-accent-light);
    background: linear-gradient(90deg, rgba(99, 102, 241, 0.12) 0%, transparent 100%);
    border-left-color: var(--color-accent);
    font-weight: 600;
}

.nav-icon {
    width: 18px;
    text-align: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    overflow: hidden;
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--color-accent), #8b5cf6);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.user-details {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.user-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.68rem;
    color: var(--color-text-muted);
    text-transform: capitalize;
}

.logout-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    text-decoration: none;
    flex-shrink: 0;
}

.logout-btn:hover {
    color: var(--color-danger);
    background: var(--color-danger-bg);
}

/* ============================================================
   MAIN WRAPPER
============================================================ */
.main-wrapper {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0;
    transition: margin-left var(--transition-base);
}

/* ============================================================
   TOPBAR
============================================================ */
.topbar {
    height: var(--topbar-height);
    background: var(--color-topbar);
    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: 900;
    gap: 16px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-toggle {
    background: none;
    border: none;
    color: var(--color-text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    display: none;
}

.topbar-toggle:hover {
    color: var(--color-text-primary);
    background: rgba(255, 255, 255, 0.06);
}

.topbar-date {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
}

.topbar-btn {
    font-size: 0.8rem !important;
}

/* Breadcrumb */
.breadcrumb {
    background: none;
    margin: 0;
    padding: 0;
    font-size: 0.8rem;
}

.breadcrumb-item a {
    color: var(--color-text-muted);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.breadcrumb-item a:hover { color: var(--color-accent-light); }
.breadcrumb-item.active { color: var(--color-text-secondary); }
.breadcrumb-item + .breadcrumb-item::before { color: var(--color-text-muted); }

/* ============================================================
   PAGE CONTENT
============================================================ */
.page-content {
    flex: 1;
    padding: 24px;
    min-width: 0;
}

.page-header {
    margin-bottom: 28px;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text-primary);
    margin-bottom: 4px;
    letter-spacing: -0.3px;
}

.page-subtitle {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

/* ============================================================
   CARDS
============================================================ */
.card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-base);
}

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

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--color-border);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0;
}

.card-body {
    padding: 20px;
}

/* ============================================================
   KPI CARDS
============================================================ */
.kpi-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--kpi-accent, var(--color-accent));
    opacity: 0;
    transition: opacity var(--transition-base);
}

.kpi-card:hover::before { opacity: 1; }
.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: rgba(99, 102, 241, 0.2);
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.kpi-icon.success { background: var(--color-success-bg); color: var(--color-success); }
.kpi-icon.danger  { background: var(--color-danger-bg);  color: var(--color-danger);  }
.kpi-icon.info    { background: var(--color-info-bg);    color: var(--color-info);    }
.kpi-icon.warning { background: var(--color-warning-bg); color: var(--color-warning); }
.kpi-icon.accent  { background: var(--color-accent-glow); color: var(--color-accent-light); }

.kpi-content { flex: 1; }

.kpi-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 6px;
}

.kpi-value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--color-text-primary);
    letter-spacing: -0.5px;
    line-height: 1;
    margin-bottom: 8px;
}

.kpi-change {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-full);
}

.kpi-change.up {
    color: var(--color-success);
    background: var(--color-success-bg);
}

.kpi-change.down {
    color: var(--color-danger);
    background: var(--color-danger-bg);
}

.kpi-change.neutral {
    color: var(--color-text-muted);
    background: rgba(255, 255, 255, 0.05);
}

/* ============================================================
   TABLES
============================================================ */
.table-modern {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.table-modern thead th {
    background: rgba(255, 255, 255, 0.03);
    color: var(--color-text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

.table-modern tbody tr {
    transition: background var(--transition-fast);
}

.table-modern tbody tr:hover td {
    background: rgba(255, 255, 255, 0.03);
}

.table-modern tbody td {
    padding: 12px 16px;
    color: var(--color-text-secondary);
    font-size: 0.875rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

.table-modern tbody tr:last-child td {
    border-bottom: none;
}

/* ============================================================
   BADGES & STATUS
============================================================ */
.badge-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 0.72rem;
    font-weight: 600;
}

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

.badge-confirmado { color: var(--color-success); background: var(--color-success-bg); }
.badge-rascunho   { color: var(--color-warning); background: var(--color-warning-bg); }
.badge-fechado    { color: var(--color-text-muted); background: rgba(255,255,255,0.05); }

/* ============================================================
   BUTTONS
============================================================ */
.btn {
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    font-size: 0.85rem;
}

.btn-primary {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: white;
}

.btn-primary:hover {
    background: var(--color-accent-dark);
    border-color: var(--color-accent-dark);
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}

.btn-outline-secondary {
    border-color: var(--color-border);
    color: var(--color-text-secondary);
    background: transparent;
}

.btn-outline-secondary:hover {
    background: rgba(255,255,255,0.06);
    color: var(--color-text-primary);
    border-color: rgba(255,255,255,0.15);
}

/* ============================================================
   FORMS
============================================================ */
.form-control, .form-select {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    color: var(--color-text-primary);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 0.875rem;
    transition: all var(--transition-fast);
}

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

.form-control::placeholder { color: var(--color-text-muted); }
.form-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: 6px;
}

/* ============================================================
   CHARTS WRAPPER
============================================================ */
.chart-wrapper {
    position: relative;
    height: 280px;
}

.chart-wrapper canvas {
    max-height: 280px !important;
}

/* ============================================================
   ALERTS
============================================================ */
.messages-container {
    padding: 16px 24px 0;
}

.alert-custom {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    color: var(--color-text-primary);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
}

.alert-success.alert-custom { border-left: 3px solid var(--color-success); }
.alert-danger.alert-custom  { border-left: 3px solid var(--color-danger); }
.alert-warning.alert-custom { border-left: 3px solid var(--color-warning); }
.alert-info.alert-custom    { border-left: 3px solid var(--color-info); }

/* ============================================================
   LOGIN PAGE
============================================================ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-primary);
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.login-page::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(ellipse at 60% 40%, rgba(99, 102, 241, 0.08) 0%, transparent 60%),
                radial-gradient(ellipse at 20% 80%, rgba(139, 92, 246, 0.06) 0%, transparent 50%);
    pointer-events: none;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    padding: 40px;
    box-shadow: var(--shadow-lg);
    position: relative;
    z-index: 1;
}

.login-logo {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--color-accent), #8b5cf6);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    margin: 0 auto 20px;
    box-shadow: var(--shadow-glow);
}

/* ============================================================
   PAGE FOOTER
============================================================ */
.page-footer {
    padding: 12px 24px;
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

/* ============================================================
   ESTABLISHMENT COLOR DOT
============================================================ */
.est-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

/* ============================================================
   EMPTY STATE
============================================================ */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--color-text-muted);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 8px;
}

/* ============================================================
   RESPONSIVE
============================================================ */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .main-wrapper {
        margin-left: 0;
    }

    .topbar-toggle {
        display: flex;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 999;
        backdrop-filter: blur(2px);
    }

    .sidebar-overlay.active {
        display: block;
    }

    .page-content {
        padding: 16px;
    }
}

@media (max-width: 575.98px) {
    .kpi-value { font-size: 1.4rem; }
    .topbar-date { display: none; }
}

/* ============================================================
   UTILITIES
============================================================ */
.text-success { color: var(--color-success) !important; }
.text-danger  { color: var(--color-danger) !important; }
.text-warning { color: var(--color-warning) !important; }
.text-info    { color: var(--color-info) !important; }
.text-muted   { color: var(--color-text-muted) !important; }
.text-accent  { color: var(--color-accent-light) !important; }

.bg-card { background: var(--color-bg-card) !important; }
.border-subtle { border-color: var(--color-border) !important; }

.font-mono {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.85em;
}

/* Scrollbar global */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.15);
}

/* Loading skeleton */
.skeleton {
    background: linear-gradient(90deg,
        rgba(255,255,255,0.04) 0%,
        rgba(255,255,255,0.08) 50%,
        rgba(255,255,255,0.04) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: var(--radius-sm);
}

@keyframes skeleton-loading {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Fade-in animation */
.fade-in {
    animation: fadeIn 0.4s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Number formatting */
.currency::before { content: '€ '; font-size: 0.75em; }
.pct::after       { content: '%'; font-size: 0.75em; }
