:root {
    /* --- Palette: Slate (Neutral) --- */
    --slate-50: #f8fafc;
    --slate-100: #f1f5f9;
    --slate-200: #e2e8f0;
    --slate-300: #cbd5e1;
    --slate-400: #94a3b8;
    --slate-500: #64748b;
    --slate-600: #475569;
    --slate-700: #334155;
    --slate-800: #1e293b;
    --slate-900: #0f172a;
    --slate-950: #020617;

    /* --- Palette: Indigo (Primary) --- */
    --indigo-50: #eef2ff;
    --indigo-100: #e0e7ff;
    --indigo-200: #c7d2fe;
    --indigo-300: #a5b4fc;
    --indigo-400: #818cf8;
    --indigo-500: #6366f1;
    --indigo-600: #4f46e5;
    --indigo-700: #4338ca;
    --indigo-800: #3730a3;
    --indigo-900: #312e81;
    --indigo-950: #1e1b4b;

    /* --- Semantic Colors (Light Mode) --- */
    --app-bg: var(--slate-50);
    --app-surface: #ffffff;
    --app-surface-hover: var(--slate-50);
    --app-border: var(--slate-200);
    --app-text: var(--slate-800);
    --app-text-muted: var(--slate-500);

    --app-primary: var(--indigo-600);
    --app-primary-hover: var(--indigo-700);
    --app-primary-fg: #ffffff;

    --app-danger: #ef4444;
    --app-danger-bg: #fef2f2;
    --app-success: #10b981;
    --app-success-bg: #ecfdf5;
    --app-warning: #f59e0b;
    --app-warning-bg: #fffbeb;

    /* --- UI Tokens --- */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;

    --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);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-display: 'Plus Jakarta Sans', system-ui, sans-serif;
}

[data-theme="dark"] {
    /* --- Semantic Colors (Dark Mode) --- */
    --app-bg: var(--slate-950);
    --app-surface: var(--slate-900);
    --app-surface-hover: var(--slate-800);
    --app-border: var(--slate-800);
    --app-text: var(--slate-100);
    --app-text-muted: var(--slate-400);

    --app-primary: var(--indigo-500);
    --app-primary-hover: var(--indigo-400);

    --app-danger: #f87171;
    --app-danger-bg: rgba(239, 68, 68, 0.2);
    --app-success: #34d399;
    --app-success-bg: rgba(16, 185, 129, 0.2);
    --app-warning: #fbbf24;
    --app-warning-bg: rgba(245, 158, 11, 0.2);
}

/* --- Global Reset & Typography --- */
body {
    background-color: var(--app-bg);
    color: var(--app-text);
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
}

h1,
h2,
h3,
h4,
h5,
h6,
.display-font {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: -0.025em;
    color: var(--app-text);
}

a {
    color: var(--app-primary);
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: var(--app-primary-hover);
}

/* --- Bootstrap Overrides --- */

/* Buttons */
.btn {
    border-radius: var(--radius-md);
    font-weight: 500;
    padding: 0.5rem 1rem;
    transition: all 0.2s;
}

.btn-primary {
    background-color: var(--app-primary);
    border-color: var(--app-primary);
    color: var(--app-primary-fg);
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
    background-color: var(--app-primary-hover) !important;
    border-color: var(--app-primary-hover) !important;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-outline-secondary {
    border-color: var(--app-border);
    color: var(--app-text);
    background: transparent;
}

.btn-outline-secondary:hover {
    background-color: var(--app-surface-hover);
    color: var(--app-text);
    border-color: var(--slate-300);
}

/* Cards */
.card {
    background-color: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
}

.card-header {
    background-color: transparent;
    border-bottom: 1px solid var(--app-border);
    padding: 1.25rem 1.5rem;
}

.card-body {
    padding: 1.5rem;
}

.card-footer {
    background-color: transparent;
    border-top: 1px solid var(--app-border);
    padding: 1rem 1.5rem;
}

/* Inputs */
.form-control,
.form-select {
    background-color: var(--app-bg);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    color: var(--app-text);
    padding: 0.625rem 0.875rem;
    font-size: 0.95rem;
    transition: all 0.2s;
}

.form-control:focus,
.form-select:focus {
    background-color: var(--app-surface);
    border-color: var(--app-primary);
    box-shadow: 0 0 0 3px var(--indigo-100);
}

[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus {
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.form-label {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--app-text-muted);
    margin-bottom: 0.375rem;
}

/* Tables */
.table {
    margin-bottom: 0;
    color: var(--app-text);
}

.table th {
    background-color: var(--slate-50);
    color: var(--slate-500);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--app-border);
}

[data-theme="dark"] .table th {
    background-color: var(--slate-900);
    color: var(--slate-400);
}

.table td {
    padding: 0.875rem 1rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--app-border);
}

.table-hover tbody tr:hover {
    background-color: var(--app-surface-hover);
}

/* Badges */
.badge {
    font-weight: 500;
    padding: 0.35em 0.65em;
    border-radius: 6px;
}

/* Navbar / Sidebar (Base structure overrides) */
.sidebar {
    background-color: var(--app-surface);
    border-right: 1px solid var(--app-border);
}

.topbar {
    background-color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--app-border);
    position: sticky;
    top: 0;
    z-index: 1030;
}

[data-theme="dark"] .topbar {
    background-color: rgba(15, 23, 42, 0.8);
}

/* --- Layout Refinements --- */
.app-shell {
    background-color: var(--app-bg);
}

/* Sidebar Modernization */
.sidebar {
    padding: 1.5rem 1rem;
    border-right: none;
    box-shadow: var(--shadow-xl);
    z-index: 1020;
}

.brand-link {
    font-family: var(--font-display);
    font-size: 1.25rem;
    color: var(--app-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.menu-link {
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    font-weight: 500;
    color: var(--app-text-muted);
    transition: all 0.2s ease;
}

.menu-link:hover {
    background-color: var(--indigo-50);
    color: var(--indigo-700);
}

.menu-link.active {
    background-color: var(--indigo-50);
    color: var(--indigo-700);
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--indigo-600);
}

[data-theme="dark"] .menu-link:hover,
[data-theme="dark"] .menu-link.active {
    background-color: rgba(99, 102, 241, 0.1);
    color: var(--indigo-300);
}

.menu-link i {
    color: var(--slate-400);
    transition: color 0.2s;
}

.menu-link:hover i,
.menu-link.active i {
    color: var(--indigo-500);
}

/* Sidebar Footer User Card */
.sidebar-footer .user-card {
    background: var(--slate-100);
    border: 1px solid var(--slate-200);
    border-radius: var(--radius-lg);
    padding: 0.75rem;
}

[data-theme="dark"] .sidebar-footer .user-card {
    background: var(--slate-800);
    border-color: var(--slate-700);
}

.user-avatar {
    background: var(--indigo-100);
    color: var(--indigo-700);
    border-radius: var(--radius-md);
    font-family: var(--font-display);
}

/* --- Component Overrides --- */

/* Ghost Button Modernization */
.btn-ghost {
    background: transparent;
    border: 1px solid transparent;
    color: var(--app-text-muted);
    border-radius: var(--radius-md);
    transition: all 0.2s;
}

.btn-ghost:hover {
    background: var(--slate-100);
    color: var(--indigo-700);
    border-color: transparent;
}

[data-theme="dark"] .btn-ghost:hover {
    background: var(--slate-800);
    color: var(--indigo-300);
}

/* Badges Modernization */
.badge.bg-light {
    background-color: var(--slate-100) !important;
    color: var(--slate-700) !important;
    border: 1px solid var(--slate-200) !important;
}

[data-theme="dark"] .badge.bg-light {
    background-color: var(--slate-800) !important;
    color: var(--slate-300) !important;
    border-color: var(--slate-700) !important;
}

/* Table Actions */
.table-actions .btn-icon-action {
    border-radius: var(--radius-md);
    transition: all 0.2s;
}

.table-actions .btn-icon-action:hover {
    background-color: var(--indigo-50);
    color: var(--indigo-700);
    transform: translateY(-1px);
}

/* Utilities */
.table-responsive.sticky-header {
    max-height: calc(100vh - 280px);
    overflow-y: auto;
}

.table-responsive.sticky-header thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 1px 0 var(--app-border);
}

.page-header {
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--app-text);
    margin: 0;
}

/* --- Toasts --- */
#appToastContainer {
    z-index: 1080;
}

.toast {
    background-color: var(--app-surface);
    color: var(--app-text);
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-lg);
    overflow: hidden;
    max-width: 400px;
    font-size: 0.95rem;
}

.toast-body {
    padding: 1rem;
    line-height: 1.4;
}

.toast-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Toast Variants */
.toast-success {
    border-left: 4px solid var(--app-success);
}

.toast-success .toast-icon i {
    color: var(--app-success);
}

.toast-danger {
    border-left: 4px solid var(--app-danger);
}

.toast-danger .toast-icon i {
    color: var(--app-danger);
}

.toast-warning {
    border-left: 4px solid var(--app-warning);
}

.toast-warning .toast-icon i {
    color: var(--app-warning);
}

.toast-info {
    border-left: 4px solid var(--app-primary);
}

.toast-info .toast-icon i {
    color: var(--app-primary);
}

.btn-close-white {
    filter: none;
    /* Reset bootstrap white filter since we use dark text usually */
    opacity: 0.4;
}

.btn-close-white:hover {
    opacity: 0.8;
}

[data-theme="dark"] .toast {
    background-color: var(--slate-800);
    border: 1px solid var(--slate-700);
}

[data-theme="dark"] .btn-close-white {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* Topbar dropdown stacking fix */
.topbar {
    overflow: visible;
    z-index: 1250;
}

.main,
.content {
    overflow: visible;
}

.topbar-right {
    position: relative;
    z-index: 1251;
}

.topbar .dropdown-menu {
    z-index: 1300;
}

.topbar .dropdown {
    position: relative;
    z-index: 1301;
}

.topbar .dropdown-menu .dropdown-item:focus-visible {
    outline: 2px solid var(--app-primary);
    outline-offset: -2px;
}

/* Table actions spacing hardening */
.table-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.45rem;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.table-actions .btn {
    min-width: auto;
}

.table-actions .btn:focus-visible {
    outline: 2px solid var(--app-primary);
    outline-offset: 2px;
}

td.text-end > .btn-group {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: nowrap;
}

td.text-end > .btn-group > .btn {
    border-radius: var(--radius-md) !important;
    margin-left: 0 !important;
}

/* GL documentos calendar */
.documentos-calendar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.documentos-calendar {
    overflow-x: auto;
}

.documentos-calendar-weekdays {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 0.4rem;
    margin-bottom: 0.4rem;
}

.documentos-calendar-weekday {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--app-text-muted);
    padding: 0.3rem 0.4rem;
}

.documentos-calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 0.4rem;
}

.documentos-calendar-day {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    min-height: 145px;
    padding: 0.45rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.documentos-calendar-day.is-outside {
    opacity: 0.66;
}

.documentos-calendar-day-number {
    font-weight: 600;
    font-size: 0.85rem;
}

.documentos-calendar-events {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.documentos-calendar-event {
    border: 1px solid var(--app-border);
    border-radius: var(--radius-sm);
    background: var(--slate-50);
    color: var(--app-text);
    padding: 0.3rem 0.45rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    font-size: 0.8rem;
    text-decoration: none;
}

.documentos-calendar-event:hover {
    border-color: var(--app-primary);
    background: var(--indigo-50);
}

.documentos-calendar-event-title {
    font-weight: 600;
    line-height: 1.2;
}

.documentos-calendar-event-status {
    color: var(--app-text-muted);
    font-size: 0.75rem;
}

.documentos-calendar-empty {
    color: var(--app-primary);
    font-size: 0.74rem;
    padding-top: 0.15rem;
    background: transparent;
    border: 0;
    cursor: pointer;
    text-align: left;
}

.documentos-calendar-empty:hover {
    color: var(--app-primary);
    text-decoration: underline;
}

[data-theme="dark"] .documentos-calendar-event {
    background: var(--slate-900);
    border-color: var(--slate-700);
}

[data-theme="dark"] .documentos-calendar-event:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--indigo-400);
}

@media (max-width: 992px) {
    .documentos-calendar-weekdays,
    .documentos-calendar-grid {
        grid-template-columns: repeat(7, minmax(118px, 1fr));
    }
}

/* GL documentos rich editor */
.glsp-rich-editor {
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--app-surface);
}

.glsp-rich-editor-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding: 0.45rem;
    border-bottom: 1px solid var(--app-border);
    background: var(--slate-50);
}

.glsp-rich-editor-select {
    width: auto;
    min-width: 170px;
}

.glsp-rich-editor-surface {
    min-height: 300px;
    padding: 0.8rem;
    outline: none;
    color: var(--app-text) !important;
    background: var(--app-surface);
    caret-color: var(--app-text);
}

.glsp-rich-editor-surface * {
    color: inherit;
}

.glsp-rich-editor-surface a {
    color: var(--app-primary);
}

.glsp-rich-editor-surface:focus {
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--app-primary) 35%, transparent);
}

.glsp-rich-editor-surface table {
    width: 100%;
    border-collapse: collapse;
}

.glsp-rich-editor-surface table th,
.glsp-rich-editor-surface table td {
    border: 1px solid var(--app-border);
    padding: 0.35rem 0.45rem;
}

.glsp-rich-preview {
    min-height: 220px;
}

[data-theme="dark"] .glsp-rich-editor-toolbar {
    background: var(--slate-900);
}

[data-theme="dark"] .glsp-rich-editor-surface {
    background: var(--slate-950);
    color: var(--app-text) !important;
}

[data-theme="dark"] .glsp-rich-preview {
    color: var(--app-text);
    background: var(--app-surface);
}

/* Calendario module contrast */
.calendario-form .form-control,
.calendario-form .form-select {
    color: var(--app-text);
    background: var(--app-surface);
}

.calendario-form textarea.form-control {
    min-height: 90px;
}

[data-theme="dark"] .calendario-form .form-control::placeholder {
    color: var(--app-text-muted);
    opacity: 1;
}

[data-theme="dark"] .calendario-form input[type="datetime-local"]::-webkit-calendar-picker-indicator {
    filter: invert(1) brightness(1.05);
    opacity: 0.9;
}
