/**
 * Inventario Clínico — Tema ERP hospitalario
 * Paleta: azul clínico (#0d6efd), grises administrativos, acentos semánticos
 */

:root,
[data-theme="light"] {
    --sidebar-bg: #1e3a5f;
    --sidebar-text: #e8eef4;
    --sidebar-hover: #2a5082;
    --sidebar-active: #0d6efd;
    --topbar-bg: #ffffff;
    --body-bg: #f0f4f8;
    --card-bg: #ffffff;
    --text-primary: #1a2b3c;
    --text-muted: #6c757d;
    --border-color: #dee2e6;
    --accent-primary: #0d6efd;
    --accent-success: #198754;
    --accent-warning: #ffc107;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] {
    --sidebar-bg: #0f1923;
    --sidebar-text: #c8d6e5;
    --sidebar-hover: #1a2b3c;
    --sidebar-active: #3d8bfd;
    --topbar-bg: #1a2332;
    --body-bg: #121a24;
    --card-bg: #1a2332;
    --text-primary: #e8eef4;
    --text-muted: #8b9cb3;
    --border-color: #2a3a4d;
    --accent-primary: #3d8bfd;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

body {
    background: var(--body-bg);
    color: var(--text-primary);
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

/* Layout */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1040;
    overflow-y: auto;
    transition: transform 0.25s ease;
}

.sidebar-brand {
    padding: 1.25rem 1.5rem;
    font-size: 1.15rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-brand i {
    color: #ff6b8a;
    font-size: 1.4rem;
}

.sidebar-nav {
    padding: 1rem 0.75rem;
    flex: 1;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.65rem 1rem;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 0.5rem;
    margin-bottom: 0.15rem;
    transition: background 0.15s;
}

.sidebar-nav .nav-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.sidebar-nav .nav-link.active {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 500;
}

.nav-section {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.45);
    padding: 1rem 1rem 0.35rem;
}

.app-main {
    flex: 1;
    margin-left: 260px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-topbar {
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 0.85rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1030;
    box-shadow: var(--shadow);
}

.app-content {
    flex: 1;
}

/* Cards & stats */
.card {
    background: var(--card-bg);
    border-color: var(--border-color);
    box-shadow: var(--shadow);
}

.card-header {
    background: transparent;
    border-bottom-color: var(--border-color);
    font-weight: 500;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Tables */
.table {
    color: var(--text-primary);
    --bs-table-bg: transparent;
    --bs-table-color: var(--text-primary);
    --bs-table-border-color: var(--border-color);
    --bs-table-hover-bg: rgba(13, 110, 253, 0.05);
    --bs-table-hover-color: var(--text-primary);
}

[data-theme="dark"] .table,
[data-theme="dark"] .table > :not(caption) > * > * {
    --bs-table-color: #e8eef4;
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--border-color);
    --bs-table-striped-color: #e8eef4;
    --bs-table-striped-bg: rgba(255, 255, 255, 0.03);
    --bs-table-hover-color: #ffffff;
    --bs-table-hover-bg: rgba(61, 139, 253, 0.12);
    --bs-table-active-color: #ffffff;
    --bs-table-active-bg: rgba(61, 139, 253, 0.16);
    color: #e8eef4;
}

[data-theme="dark"] .table thead th,
[data-theme="dark"] .table tbody td,
[data-theme="dark"] .table tbody th {
    color: #e8eef4;
    border-color: var(--border-color);
}

[data-theme="dark"] .table tbody tr:hover td,
[data-theme="dark"] .table tbody tr:hover th {
    color: #ffffff;
}

[data-theme="dark"] .table code {
    color: #9ec5fe;
}

[data-theme="dark"] .table .text-muted,
[data-theme="dark"] .table small.text-muted {
    color: var(--text-muted) !important;
}

[data-theme="dark"] .table-warning {
    --bs-table-bg: rgba(255, 193, 7, 0.15);
    --bs-table-color: #e8eef4;
    --bs-table-hover-color: #ffffff;
}

[data-theme="dark"] .table-filter-row th {
    background: var(--body-bg);
}

.table-filter-row th {
    padding: 0.5rem 0.75rem;
    background: var(--body-bg);
    border: none;
}

/* Badges */
.badge-tipo-entrada { background: #198754; }
.badge-tipo-salida { background: #dc3545; }
.badge-tipo-devolucion { background: #0dcaf0; color: #000; }
.badge-tipo-ajuste { background: #6c757d; }

/* Forms */
.form-control,
.form-select {
    background: var(--card-bg);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.form-control:focus,
.form-select:focus {
    background: var(--card-bg);
    color: var(--text-primary);
}

[data-theme="dark"] .btn-outline-secondary {
    color: var(--text-muted);
    border-color: var(--border-color);
}

[data-theme="dark"] .accordion-item {
    background: var(--card-bg);
    border-color: var(--border-color);
    color: var(--text-primary);
}

[data-theme="dark"] .accordion-button {
    background: var(--card-bg);
    color: var(--text-primary);
}

[data-theme="dark"] .accordion-button:not(.collapsed) {
    background: rgba(61, 139, 253, 0.12);
    color: #ffffff;
}

[data-theme="dark"] .accordion-body {
    background: var(--card-bg);
    color: var(--text-primary);
}

[data-theme="dark"] .form-check-label,
[data-theme="dark"] .form-label {
    color: var(--text-primary);
}

[data-theme="dark"] .app-topbar .h5,
[data-theme="dark"] .card-header {
    color: var(--text-primary);
}

[data-theme="dark"] .card,
[data-theme="dark"] .card-body {
    color: var(--text-primary);
}

[data-theme="dark"] .card-body h6,
[data-theme="dark"] .card h6 {
    color: #ffffff;
}

[data-theme="dark"] .card-body p,
[data-theme="dark"] .card-body span,
[data-theme="dark"] .card-body .border-top {
    color: #ffffff;
}

[data-theme="dark"] .text-muted,
[data-theme="dark"] .card-body .text-muted,
[data-theme="dark"] small.text-muted {
    color: var(--text-muted) !important;
}

/* Login */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e3a5f 0%, #0d6efd 100%);
}

[data-theme="dark"] .login-page {
    background: linear-gradient(135deg, #0f1923 0%, #1a2b3c 100%);
}

.login-card {
    width: 100%;
    max-width: 420px;
    border: none;
    background: var(--card-bg);
}

.login-logo {
    font-size: 2.5rem;
    color: #ff6b8a;
}

/* Sidebar — botón cerrar (solo móvil) */
.sidebar-close-btn {
    display: none;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 1.35rem;
    line-height: 1;
    padding: 0;
    margin-left: auto;
    cursor: pointer;
    flex-shrink: 0;
}

.sidebar-close-btn:hover {
    color: #fff;
}

/* Overlay oscuro detrás del sidebar en móvil */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1039;
    cursor: pointer;
}

/* Responsive */
@media (max-width: 767.98px) {
    .app-sidebar {
        transform: translateX(-100%);
    }

    .app-sidebar.app-sidebar--open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
    }

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

    .sidebar-close-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

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

    /* Impedir scroll del body mientras el sidebar está abierto */
    body.sidebar-is-open {
        overflow: hidden;
    }
}
