:root {
    --bg-base: #f8fafc;
    --bg-surface: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --success: #10b981;
    --success-light: #ecfdf5;
    --border: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --border-radius: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-base);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* Navbar */
.navbar {
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.navbar-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--primary);
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
}

.highlight {
    color: var(--primary);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--success);
    background-color: var(--success-light);
    padding: 0.375rem 0.75rem;
    border-radius: 9999px;
    border: 1px solid #d1fae5;
}

.indicator-danger {
    color: var(--danger);
    background-color: var(--danger-light);
    border-color: #fee2e2;
}

.dot {
    width: 8px;
    height: 8px;
    background-color: currentColor;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
    70% { opacity: 0.5; box-shadow: 0 0 0 4px rgba(16, 185, 129, 0); }
    100% { opacity: 1; box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Main Dashboard Layout */
main {
    padding: 2.5rem 1.5rem;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 2rem;
}

.dashboard-header h2 {
    font-size: 1.875rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.subtitle {
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.stats-card {
    background: var(--bg-surface);
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    text-align: right;
    display: flex;
    flex-direction: column;
}

.stats-value {
    font-size: 2.25rem;
    font-weight: 800;
    line-height: 1;
}

.stats-value.danger { color: var(--danger); }
.stats-value.success { color: var(--success); }

.stats-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.dashboard-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.btn-refresh {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background-color: var(--bg-surface);
    color: var(--text-main);
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    box-shadow: var(--shadow-sm);
}

.btn-refresh:hover {
    background-color: #f1f5f9;
    color: var(--primary);
    border-color: #cbd5e1;
}

.last-updated {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Empty State */
.empty-state {
    background: var(--bg-surface);
    border-radius: var(--border-radius);
    padding: 4rem 2rem;
    text-align: center;
    border: 1px dashed #cbd5e1;
}

.empty-icon {
    width: 64px;
    height: 64px;
    background-color: var(--success-light);
    color: var(--success);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
    margin: 0 auto 1.5rem;
}

.empty-state h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: var(--text-muted);
}

/* Cards & Tables */
.companies-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.company-card {
    background: var(--bg-surface);
    border-radius: var(--border-radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.company-card:hover {
    box-shadow: var(--shadow-lg);
}

.company-header {
    background-color: #f8fafc;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.company-title {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.company-id {
    background-color: var(--text-main);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
}

.company-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-main);
}

.badge {
    background-color: var(--danger-light);
    color: var(--danger);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    border: 1px solid #fecaca;
}

.table-responsive {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.data-table th {
    background-color: var(--bg-surface);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 1rem 1.5rem;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

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

.data-table tbody tr:hover {
    background-color: #f8fafc;
}

.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.text-danger { color: var(--danger); }

.datetime-cell {
    display: flex;
    flex-direction: column;
}

.datetime-cell .time {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 0.125rem;
}

.tag-placa {
    display: inline-block;
    background-color: #f1f5f9;
    border: 1px solid #cbd5e1;
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #475569;
}

.obs-cell {
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-muted);
}

.obs-cell:hover {
    white-space: normal;
    word-break: break-word;
}

/* Footer */
footer {
    border-top: 1px solid var(--border);
    padding: 2rem 0;
    margin-top: 2rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Responsive */
@media (max-width: 768px) {
    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    .stats-card {
        width: 100%;
        text-align: left;
    }
    .company-title {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
}

/* ==========================================================================
   SIDEBAR LAYOUT & RESPONSIVENESS
   ========================================================================== */

/* Main layout wrapper */
.app-layout {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* Sidebar styles */
.sidebar {
    width: 280px;
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border);
    padding: 2.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-top {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--primary);
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-brand h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
}

.sidebar-menu {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    overflow-y: auto;
    padding-right: 4px;
}

.sidebar-menu::-webkit-scrollbar {
    width: 5px;
}

.sidebar-menu::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-menu::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 99px;
}

.sidebar-menu::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius);
    color: var(--text-muted);
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;
}

.sidebar-link:hover {
    background-color: #f1f5f9;
    color: var(--text-main);
}

.sidebar-link.active {
    background-color: rgba(59, 130, 246, 0.08);
    color: var(--primary);
    font-weight: 700;
}

.sidebar-link svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.sidebar-bottom {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.sidebar .status-indicator {
    justify-content: center;
    width: 100%;
}

.sidebar .btn-logout {
    display: block;
    width: 100%;
    text-align: center;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    transition: all 0.2s;
}

.sidebar .btn-logout:hover {
    background-color: var(--danger-light);
    color: var(--danger);
    border-color: #fecaca;
}

/* Main Content Area */
.main-content {
    flex: 1;
    margin-left: 280px;
    padding: 2.5rem 3rem;
    background-color: var(--bg-base);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.main-content main {
    padding: 0;
    flex: 1;
}

.main-content footer {
    margin-top: 4rem;
    padding: 1.5rem 0 0 0;
}

/* Mobile Header & Overlay */
.mobile-header {
    display: none;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    padding: 0.875rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 90;
    box-shadow: var(--shadow-sm);
    width: 100%;
}

.btn-menu-toggle {
    background: none;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    padding: 0.35rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid var(--border);
    transition: background-color 0.2s;
}

.btn-menu-toggle:hover {
    background-color: #f1f5f9;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(15, 23, 42, 0.3);
    backdrop-filter: blur(4px);
    z-index: 95;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .mobile-header {
        display: flex;
    }
    
    .sidebar {
        transform: translateX(-100%);
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 100;
        box-shadow: var(--shadow-lg);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .sidebar-overlay {
        display: block;
    }
    
    .main-content {
        margin-left: 0;
        padding: 2rem 1.5rem;
    }
}

/* Asynchronous loading container and progress bar styles */
.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 5rem 2rem;
    text-align: center;
    background: var(--bg-surface);
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    margin: 2rem 0;
}

.loading-spinner-wrapper {
    position: relative;
    width: 60px;
    height: 60px;
    margin-bottom: 1.5rem;
}

.loading-spinner {
    width: 100%;
    height: 100%;
    border: 4px solid rgba(59, 130, 246, 0.1);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-message {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.loading-subtext {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.progress-bar-container {
    width: 100%;
    max-width: 320px;
    height: 8px;
    background-color: var(--border);
    border-radius: 99px;
    overflow: hidden;
    position: relative;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background-color: var(--primary);
    border-radius: 99px;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
