:root {
    --sw-primary: #3085d6;
    --sw-primary-hover: #2674c0;
    --sw-success: #a5dc86;
    --sw-warning: #f8bb86;
    --sw-error: #f27474;
    --sw-info: #3fc3ee;
    --sw-dark: #545454;
    --sw-light: #f0f4f8;
    --white: #ffffff;
    --text-primary: #2c3e50;
    --text-secondary: #7f8c8d;
    --border: #e0e6ed;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--sw-light);
    color: var(--text-primary);
    min-height: 100vh;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    inset: 0;
    background: var(--sw-light);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.4s ease;
}
.loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}
.loading-content {
    text-align: center;
}
.loading-logo {
    margin-bottom: 2rem;
    filter: drop-shadow(0 2px 8px rgba(48,133,214,0.2));
}
.loading-spinner {
    width: 40px; height: 40px;
    margin: 0 auto 1rem;
    border: 3px solid var(--border);
    border-top-color: var(--sw-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Login */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 1rem;
}
.login-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
}
.login-logo {
    text-align: center;
    margin-bottom: 2rem;
}
.login-logo img { height: 48px; }
.login-logo h1 {
    font-size: 1.5rem;
    color: var(--sw-primary);
    margin-top: 0.5rem;
}
.form-group {
    margin-bottom: 1.25rem;
}
.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.4rem;
}
.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}
.form-group input:focus {
    border-color: var(--sw-primary);
    box-shadow: 0 0 0 3px rgba(48,133,214,0.15);
}
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}
.btn-primary {
    background: var(--sw-primary);
    color: var(--white);
}
.btn-primary:hover { background: var(--sw-primary-hover); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

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

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}
.sidebar-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.sidebar-header img { height: 32px; }
.sidebar-header span { font-weight: 700; color: var(--sw-primary); font-size: 1.1rem; }
.sidebar-user {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}
.sidebar-user-name { font-weight: 600; color: var(--text-primary); }
.sidebar-user-rol { color: var(--text-secondary); font-size: 0.8rem; }
.sidebar-nav { flex: 1; padding: 0.75rem; overflow-y: auto; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    font-size: 0.9rem;
}
.sidebar-nav a:hover { background: var(--sw-light); }
.sidebar-nav a.active { 
    background: rgba(48,133,214,0.1); 
    color: var(--sw-primary);
    font-weight: 600;
}
.sidebar-nav a .icon { 
    width: 20px; text-align: center; 
    font-size: 1.1rem;
}

/* Main content */
.main {
    flex: 1;
    margin-left: 260px;
    display: flex;
    flex-direction: column;
}
.topbar {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-title {
    font-size: 1.1rem;
    font-weight: 600;
}
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.topbar-actions button {
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: all 0.2s;
}
.topbar-actions button:hover { background: var(--sw-light); color: var(--text-primary); }
.content {
    padding: 1.5rem;
    flex: 1;
}

/* Cards */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.card-title {
    font-size: 1rem;
    font-weight: 600;
}

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
    transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.stat-card .stat-icon {
    width: 44px; height: 44px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    margin-bottom: 0.75rem;
}
.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}
.stat-card .stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Table */
.table-container {
    overflow-x: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
}
table th, table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
table tr:hover td { background: rgba(48,133,214,0.02); }

/* Badge */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-primary { background: rgba(48,133,214,0.1); color: var(--sw-primary); }
.badge-success { background: rgba(165,220,134,0.2); color: #529944; }
.badge-warning { background: rgba(248,187,134,0.2); color: #c7772a; }
.badge-error { background: rgba(242,116,116,0.15); color: #c0392b; }
.badge-info { background: rgba(63,195,238,0.15); color: #1a8ab5; }

/* Context selector */
.context-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 1rem;
}
.context-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 500px;
}
.context-btn {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    padding: 1rem 1.25rem;
    margin-bottom: 0.75rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--white);
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    font-size: 0.95rem;
    color: var(--text-primary);
}
.context-btn:hover {
    border-color: var(--accent, var(--sw-primary));
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, var(--sw-primary)) 15%, transparent);
    transform: translateY(-1px);
}
.context-btn-icon {
    font-size: 1.5rem;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--sw-light);
    border-radius: var(--radius-sm);
}

/* Logout button */
.btn-logout {
    width: 100%;
    padding: 0.6rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--white);
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    transition: all 0.2s;
}
.btn-logout:hover {
    background: rgba(242,116,116,0.08);
    color: var(--sw-error);
    border-color: var(--sw-error);
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 0.3rem;
}

/* Hamburger */
.hamburger {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    color: var(--text-primary);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main {
        margin-left: 0;
    }
    .hamburger {
        display: block;
    }
    .stats-grid {
        grid-template-columns: 1fr;
    }
}
