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

:root {
    /* Brand Colors - Insus */
    --brand-primary: #1e1b4b; /* Deep Blue/Indigo */
    --brand-primary-light: #3730a3;
    --brand-accent: #8b5cf6; /* Violet 500 */
    --brand-accent-hover: #7c3aed; /* Violet 600 */

    /* Semantic Colors */
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
    --color-info: #3b82f6;

    /* Light Theme (Default) */
    --bg-body: #f1f5f9; /* Darker Slate 100 for better contrast */
    --bg-surface: #ffffff;
    --bg-surface-glass: rgba(255, 255, 255, 0.85);
    --bg-sidebar: #0f172a; /* Slate 900 */
    --bg-sidebar-hover: #1e293b;

    --text-primary: #0f172a;
    --text-secondary: #475569; /* Darker secondary text */
    --text-muted: #94a3b8;
    --text-inverse: #ffffff;

    --border-color: #cbd5e1; /* Darker Slate 300 for visible borders */
    --border-color-glass: rgba(203, 213, 225, 0.8);
    
    --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);

    /* Typography & Layout */
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --border-radius-sm: 8px;
    --border-radius-md: 16px;
    --border-radius-lg: 24px;
    
    --sidebar-width: 260px;
    --sidebar-width-collapsed: 80px;
    --topbar-height: 70px;
    --transition-speed: 0.3s;
}

/* Dark Theme Variables */
[data-theme="dark"] {
    --brand-primary: #818cf8; /* Indigo 400 para contraste */
    --brand-primary-light: #a5b4fc;
    --brand-accent: #a78bfa; /* Violet 400 */
    --brand-accent-hover: #8b5cf6; /* Violet 500 */

    --bg-body: #0f172a; /* Slate 900 */
    --bg-surface: #1e293b; /* Slate 800 */
    --bg-surface-glass: rgba(30, 41, 59, 0.85);
    --bg-sidebar: #020617; /* Slate 950 */
    --bg-sidebar-hover: #0f172a;

    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --text-inverse: #ffffff;

    --border-color: #334155;
    --border-color-glass: rgba(51, 65, 85, 0.5);

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.4);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5), 0 4px 6px -4px rgb(0 0 0 / 0.5);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --brand-primary: #818cf8;
        --brand-primary-light: #a5b4fc;
        --brand-accent: #a78bfa;
        --brand-accent-hover: #8b5cf6;

        --bg-body: #0f172a;
        --bg-surface: #1e293b;
        --bg-surface-glass: rgba(30, 41, 59, 0.85);
        --bg-sidebar: #020617;
        --bg-sidebar-hover: #0f172a;

        --text-primary: #f8fafc;
        --text-secondary: #cbd5e1;
        --text-muted: #64748b;
        --text-inverse: #ffffff;

        --border-color: #334155;
        --border-color-glass: rgba(51, 65, 85, 0.5);
    }
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-body);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

a {
    color: var(--brand-accent);
    text-decoration: none;
    transition: color 0.2s;
}

/* =========================================
   Layout Shell
   ========================================= */
.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    color: var(--text-inverse);
    transition: width var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    z-index: 100;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar.collapsed {
    width: var(--sidebar-width-collapsed);
}

.sidebar-header {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.brand-logo {
    font-weight: 700;
    font-size: 1.25rem;
    white-space: nowrap;
    overflow: hidden;
    color: var(--text-inverse);
    background: linear-gradient(90deg, #ffffff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar.collapsed .brand-logo {
    display: none;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none;  /* IE and Edge */
}

/* Hide scrollbar for Chrome, Safari and Opera in sidebar only */
.sidebar-nav::-webkit-scrollbar {
    display: none;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--text-muted);
    transition: all 0.3s ease;
    cursor: pointer;
    border-left: 3px solid transparent;
    margin: 4px 12px;
    border-radius: var(--border-radius-sm);
}

.nav-item:hover, .nav-item.active {
    background-color: rgba(255, 255, 255, 0.08);
    color: var(--text-inverse);
    transform: translateX(4px);
}

.nav-item.active {
    background-color: var(--brand-primary-light);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(55, 48, 163, 0.4);
}

.nav-icon {
    font-size: 1.25rem;
    min-width: 24px;
    margin-right: 12px;
    text-align: center;
    transition: transform 0.3s ease;
}

.nav-item:hover .nav-icon {
    transform: scale(1.1);
}

.sidebar.collapsed .nav-text {
    display: none;
}
.sidebar.collapsed .nav-item {
    margin: 4px 8px;
    justify-content: center;
    padding: 12px;
}
.sidebar.collapsed .nav-icon {
    margin-right: 0;
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--bg-body);
}

/* Topbar with Glassmorphism */
.topbar {
    height: var(--topbar-height);
    background-color: var(--bg-surface-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color-glass);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    z-index: 10;
}

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

.toggle-sidebar-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--border-radius-sm);
    transition: background-color 0.2s, color 0.2s;
}
.toggle-sidebar-btn:hover {
    background-color: var(--bg-body);
    color: var(--text-primary);
}

.page-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Page Body */
.page-body {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    scroll-behavior: smooth;
}

/* =========================================
   Components (Cards, Buttons, Badges)
   ========================================= */
/* Cards */
.card {
    background-color: var(--bg-surface);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-sm);
    padding: 24px;
    border: 1px solid var(--border-color);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: var(--border-radius-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    gap: 8px;
    font-family: var(--font-family);
    box-shadow: var(--shadow-sm);
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background-color: var(--brand-primary);
    color: white;
}
.btn-primary:hover {
    background-color: var(--brand-primary-light);
    box-shadow: 0 4px 12px rgba(30, 27, 75, 0.3);
}

.btn-accent {
    background-color: var(--brand-accent);
    color: white;
}
.btn-accent:hover {
    background-color: var(--brand-accent-hover);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-outline {
    background-color: transparent;
    border-color: var(--border-color);
    color: var(--text-primary);
    box-shadow: none;
}
.btn-outline:hover {
    background-color: var(--bg-body);
    border-color: var(--text-secondary);
}

/* Badges / Tags */
.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.badge-warning { background-color: rgba(245, 158, 11, 0.15); color: var(--color-warning); }
.badge-success { background-color: rgba(16, 185, 129, 0.15); color: var(--color-success); }
.badge-info { background-color: rgba(59, 130, 246, 0.15); color: var(--color-info); }

/* Grid System */
.grid { display: grid; }
.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }

/* Metrics */
.metric-value {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 8px 0;
    letter-spacing: -1px;
}
.metric-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}
.metric-trend {
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}
.trend-up { color: var(--color-success); }
.trend-down { color: var(--color-danger); }

/* Inputs */
input, select, textarea {
    background-color: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

/* =========================================
   Responsive
   ========================================= */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -var(--sidebar-width);
        height: 100%;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open {
        left: 0;
    }
    .grid-cols-3, .grid-cols-4 {
        grid-template-columns: repeat(1, minmax(0, 1fr));
    }
    .topbar {
        padding: 0 16px;
    }
}

/* =========================================
   Custom Scrollbar (Global)
   ========================================= */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.3);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 0.6);
}

/* =========================================
   Blazor Framework Elements
   ========================================= */
#blazor-error-ui {
    background: #fee2e2;
    color: #991b1b;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.loading-progress {
    position: relative;
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 20vh auto 1rem auto;
}
.loading-progress circle {
    fill: none;
    stroke: var(--border-color);
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}
.loading-progress circle:last-child {
    stroke: var(--brand-primary);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}
.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
    color: var(--brand-primary);
}
.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Iniciando Insus Pro...");
}
