:root {
    --sidebar-width: 250px;
    --topbar-height: 56px;

    /* Base - Modern Light */
    --bg: #f3f4f6;
    --surface: #ffffff;
    --surface-hover: #f9fafb;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --text: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;

    /* Branding - Rich Orange */
    --accent: #ea580c;
    --accent-hover: #c2410c;
    --accent-light: #fff7ed;
    --accent-soft: rgba(234, 88, 12, 0.08);

    /* Semantic Action Colors */
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --danger-bg: #fef2f2;
    --danger-border: #fecaca;
    --danger-soft: rgba(220, 38, 38, 0.08);

    --success: #059669;
    --success-hover: #047857;
    --success-bg: #f0fdf4;
    --success-border: #bbf7d0;
    --success-soft: rgba(5, 150, 105, 0.08);

    --info: #2563eb;
    --info-hover: #1d4ed8;
    --info-bg: #eff6ff;
    --info-border: #bfdbfe;
    --info-soft: rgba(37, 99, 235, 0.08);

    --warning: #d97706;
    --warning-hover: #b45309;
    --warning-bg: #fffbeb;
    --warning-border: #fde68a;
    --warning-soft: rgba(217, 119, 6, 0.08);

    /* Sidebar - Modern Dark */
    --sidebar-bg: #111827;
    --sidebar-surface: #1f2937;
    --sidebar-text: #94a3b8;
    --sidebar-text-hover: #e2e8f0;
    --sidebar-active: var(--accent);
    --sidebar-active-bg: rgba(234, 88, 12, 0.15);

    /* Misc */
    --radius: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --font: 'Ubuntu', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body { font-family: var(--font); font-size: 14px; line-height: 1.6; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body.auth-page { overflow: auto; }
h1, h2, h3, h4, h5, h6 { font-weight: 500; color: var(--text); letter-spacing: -0.025em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.875rem; }
p, span, div, li, td, th, label, input, select, textarea, button, a { font-size: 0.875rem; }
small { font-size: 0.75rem; }
a { color: var(--accent); text-decoration: none; transition: color 0.2s ease; }
a:hover { color: var(--accent-hover); }

.app-layout { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar - Modern Dark */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
    border-right: 1px solid var(--sidebar-surface);
}
.sidebar-brand {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--sidebar-surface);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}
.sidebar-brand .logo {
    width: 32px; height: 32px;
    background: var(--accent);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: 0.8rem;
    box-shadow: 0 2px 4px rgba(234, 88, 12, 0.3);
}
.sidebar-brand h5 { color: #f8fafc; margin: 0; font-size: 0.9rem; font-weight: 500; }
.sidebar-brand small { color: #64748b; font-size: 0.65rem; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 0.75rem; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 4px; }
.nav-section { margin-bottom: 1.25rem; }
.nav-section-title {
    font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.08em;
    color: #475569; padding: 0 0.75rem; margin-bottom: 0.5rem; font-weight: 600;
}
.sidebar-nav .nav-link {
    color: var(--sidebar-text);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.8rem;
    display: flex; align-items: center; gap: 0.65rem;
    margin-bottom: 2px;
    transition: all 0.2s ease;
    font-weight: 400;
}
.sidebar-nav .nav-link:hover { background: var(--sidebar-surface); color: var(--sidebar-text-hover); text-decoration: none; }
.sidebar-nav .nav-link.active { background: var(--sidebar-active-bg); color: var(--sidebar-active); font-weight: 500; }
.sidebar-nav .nav-link i { width: 16px; text-align: center; font-size: 0.75rem; }
.sidebar-nav .nav-link .pending-badge {
    margin-left: auto;
    background: var(--accent);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
    animation: badgePulse 2s infinite;
}
.sidebar-footer {
    padding: 0.75rem;
    border-top: 1px solid var(--sidebar-surface);
    flex-shrink: 0;
    background: var(--sidebar-bg);
}
.user-info { flex: 1; min-width: 0; }
.user-name { color: #e2e8f0; font-size: 0.75rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role-badge { display: inline-block; padding: 2px 6px; border-radius: 4px; font-size: 0.6rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.role-super-admin { background: #ef4444; color: #fff; }
.role-admin { background: #f59e0b; color: #fff; }
.role-jefe-area { background: #8b5cf6; color: #fff; }
.role-jefe-proyecto { background: #10b981; color: #fff; }
.role-miembro { background: #3b82f6; color: #fff; }

.main-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* Topbar */
.top-bar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border-light);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.page-content { flex: 1; overflow-y: auto; padding: 1.5rem; }
.page-content::-webkit-scrollbar { width: 6px; }
.page-content::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
.page-content::-webkit-scrollbar-track { background: transparent; }

/* Cards - Modern */
.card { border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); background: var(--surface); transition: box-shadow 0.2s ease, transform 0.2s ease; display: flex; flex-direction: column; }
.card:hover { box-shadow: var(--shadow-md); }
.card-header { background: var(--surface); border-bottom: 1px solid var(--border-light); padding: 0.75rem 1rem; border-radius: var(--radius-lg) var(--radius-lg) 0 0; flex-shrink: 0; }
.card-header h6 { font-weight: 600; font-size: 0.9rem; }
.card-body { padding: 1rem; }
.card-body-scroll { padding: 0; flex: 1; overflow-y: auto; max-height: 400px; }
.card-body-scroll::-webkit-scrollbar { width: 5px; }
.card-body-scroll::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* Tables */
.table { font-size: 0.8rem; margin-bottom: 0; }
.table th { font-weight: 600; color: var(--text-secondary); text-transform: uppercase; font-size: 0.65rem; letter-spacing: 0.06em; border-bottom-width: 1px; padding: 0.75rem 1rem; }
.table td { vertical-align: middle; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border-light); }
.table-hover tbody tr:hover { background: var(--surface-hover); }
.table tbody tr:last-child td { border-bottom: none; }

/* Stat Cards */
.stat-card { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); padding: 1rem; box-shadow: var(--shadow-sm); transition: box-shadow 0.2s ease, transform 0.2s ease; }
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.stat-card .stat-icon { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 0.85rem; background: var(--accent-soft); color: var(--accent); margin-bottom: 0.75rem; }
.stat-value { font-size: 1.5rem; font-weight: 600; color: var(--text); line-height: 1.2; }
.stat-label { font-size: 0.7rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 0.25rem; font-weight: 500; }

/* Badges */
.badge { font-size: 0.65rem; font-weight: 600; padding: 0.25em 0.65em; border-radius: 4px; border: none; letter-spacing: 0.02em; }
.badge-status-active { background: var(--success-soft); color: var(--success); }
.badge-status-planned { background: var(--warning-soft); color: var(--warning); }
.badge-status-completed { background: var(--info-soft); color: var(--info); }
.badge-status-paused { background: var(--bg); color: var(--text-secondary); }
.badge-status-backlog { background: var(--bg); color: var(--text-secondary); }
.badge-status-todo { background: var(--warning-soft); color: var(--warning); }
.badge-status-in-progress { background: var(--info-soft); color: var(--info); }
.badge-status-done { background: var(--success-soft); color: var(--success); }
.badge-status-new { background: var(--info-soft); color: var(--info); }
.badge-status-reviewing { background: var(--warning-soft); color: var(--warning); }
.badge-type-story { background: var(--success-soft); color: var(--success); }
.badge-type-task { background: var(--info-soft); color: var(--info); }
.badge-type-bug { background: var(--danger-soft); color: var(--danger); }
.badge-type-epic { background: #f5f3ff; color: #7c3aed; }

.priority-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.priority-high { background: var(--danger); }
.priority-medium { background: var(--warning); }
.priority-low { background: var(--success); }

/* Buttons - Modern */
.btn { font-size: 0.8rem; font-weight: 500; border-radius: 6px; padding: 0.4rem 0.8rem; border: 1px solid transparent; transition: all 0.2s ease; display: inline-flex; align-items: center; gap: 0.4rem; }
.btn-sm { font-size: 0.75rem; padding: 0.3rem 0.6rem; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(234, 88, 12, 0.2); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; box-shadow: 0 2px 4px rgba(234, 88, 12, 0.3); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); color: #fff; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: var(--success-hover); border-color: var(--success-hover); color: #fff; }
.btn-info { background: var(--info); border-color: var(--info); color: #fff; }
.btn-info:hover { background: var(--info-hover); border-color: var(--info-hover); color: #fff; }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn-warning:hover { background: var(--warning-hover); border-color: var(--warning-hover); color: #fff; }

.btn-outline-danger { border-color: var(--danger-border); color: var(--danger); background: transparent; }
.btn-outline-danger:hover { background: var(--danger-bg); border-color: var(--danger); }
.btn-outline-success { border-color: var(--success-border); color: var(--success); background: transparent; }
.btn-outline-success:hover { background: var(--success-bg); border-color: var(--success); }
.btn-outline-info { border-color: var(--info-border); color: var(--info); background: transparent; }
.btn-outline-info:hover { background: var(--info-bg); border-color: var(--info); }
.btn-outline-warning { border-color: var(--warning-border); color: var(--warning); background: transparent; }
.btn-outline-warning:hover { background: var(--warning-bg); border-color: var(--warning); }
.btn-outline-primary { border-color: var(--border); color: var(--text-secondary); background: transparent; }
.btn-outline-primary:hover { background: var(--bg); border-color: var(--text-secondary); color: var(--text); }
.btn-outline-secondary { border-color: var(--border); color: var(--text-secondary); background: transparent; }
.btn-outline-secondary:hover { background: var(--bg); border-color: var(--text-secondary); }

.btn-ghost { background: transparent; color: var(--text-secondary); border: none; }
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.entity-icon {
    width: 36px; height: 36px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg); color: var(--text-secondary); font-size: 0.9rem;
}

/* Forms */
.form-control, .form-select { font-size: 0.85rem; border-radius: 6px; border: 1px solid var(--border); padding: 0.5rem 0.75rem; background: var(--surface); color: var(--text); transition: border-color 0.2s ease, box-shadow 0.2s ease; }
.form-control:focus, .form-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.15); outline: none; }
.form-control::placeholder { color: var(--text-muted); }
.form-label { font-size: 0.8rem; font-weight: 500; color: var(--text-secondary); margin-bottom: 0.35rem; }

/* Toasts */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; pointer-events: none; max-width: 380px; }
.toast-notification {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 18px;
    font-size: 0.85rem;
    box-shadow: var(--shadow-lg);
    opacity: 0; transform: translateY(16px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: auto;
    display: flex; align-items: flex-start; gap: 12px;
    position: relative; overflow: hidden;
}
.toast-notification.show { opacity: 1; transform: translateY(0); }
.toast-notification::after {
    content: ''; position: absolute; bottom: 0; left: 0; height: 3px;
    border-radius: 0 2px 2px 0;
    animation: toastTimer 4s linear forwards;
}
@keyframes toastTimer { from { width: 100%; } to { width: 0%; } }
@keyframes badgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}
.toast-notification.success { border-left: 3px solid var(--success); }
.toast-notification.success::after { background: var(--success); }
.toast-notification.error { border-left: 3px solid var(--danger); }
.toast-notification.error::after { background: var(--danger); }
.toast-notification.warning { border-left: 3px solid var(--warning); }
.toast-notification.warning::after { background: var(--warning); }
.toast-notification.info { border-left: 3px solid var(--info); }
.toast-notification.info::after { background: var(--info); }
.toast-notification i { font-size: 0.9rem; margin-top: 1px; flex-shrink: 0; }
.toast-notification.success i { color: var(--success); }
.toast-notification.error i { color: var(--danger); }
.toast-notification.warning i { color: var(--warning); }
.toast-notification.info i { color: var(--info); }
.toast-notification span { flex: 1; line-height: 1.5; }

/* Progress bars */
.progress { background: var(--border-light); border-radius: 4px; overflow: hidden; }
.progress-bar { background: var(--accent); border-radius: 4px; }

/* Dropdowns */
.dropdown-menu { border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); background: var(--surface); padding: 0.5rem; }
.dropdown-item { font-size: 0.8rem; padding: 0.5rem 0.75rem; border-radius: 4px; color: var(--text); transition: background 0.15s ease; }
.dropdown-item:hover { background: var(--bg); color: var(--text); }
.dropdown-item i { width: 16px; text-align: center; margin-right: 0.5rem; color: var(--text-muted); }

/* Modals */
.modal-content { border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.modal-header { border-bottom: 1px solid var(--border-light); padding: 1rem; }
.modal-body { padding: 1rem; }
.modal-footer { border-top: 1px solid var(--border-light); padding: 0.75rem 1rem; }
@media (max-width: 768px) {
    .sidebar { position: fixed; left: 0; top: 0; height: 100vh; transform: translateX(-100%); z-index: 1050; transition: transform 0.2s ease; }
    .sidebar.show { transform: translateX(0); }

    .page-content { padding: 1rem; }
    .top-bar { padding: 0 1rem; }
    .top-bar #globalSearch { width: 120px !important; }

    .row > [class*="col-"] { margin-bottom: 0.75rem; }
    .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table { font-size: 0.75rem; }
    .table th, .table td { white-space: nowrap; }

    .d-flex.flex-wrap { gap: 0.5rem !important; }
    .btn-sm { padding: 0.25rem 0.5rem; font-size: 0.7rem; }

    .stat-card { padding: 0.75rem; }
    .stat-value { font-size: 1.25rem; }

    .card-body { padding: 0.75rem; }
    .card-header { padding: 0.75rem; }

    .toast-container { bottom: 10px; right: 10px; left: 10px; max-width: none; }
    .toast-notification { font-size: 0.8rem; padding: 12px 14px; }

    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }
    h3 { font-size: 1.1rem; }

    .form-control, .form-select { font-size: 0.8rem; padding: 0.4rem 0.6rem; }

    .dropdown-menu { max-width: 90vw; }
}

@media (max-width: 576px) {
    .page-content { padding: 0.75rem; }
    .top-bar { padding: 0 0.75rem; }
    .top-bar #globalSearch { display: none; }

    .table th:nth-child(n+4),
    .table td:nth-child(n+4) { display: none; }

    .btn-group-sm > .btn { padding: 0.2rem 0.4rem; }

    .stat-card .stat-icon { width: 28px; height: 28px; font-size: 0.75rem; }
    .stat-value { font-size: 1.1rem; }
    .stat-label { font-size: 0.6rem; }

    .modal-dialog { margin: 0.5rem; }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .sidebar { width: 220px; }
    :root { --sidebar-width: 220px; }
    .sidebar-nav .nav-link { font-size: 0.75rem; padding: 0.4rem 0.6rem; }
}

@media print {
    .sidebar, .top-bar, .btn, .toast-container { display: none !important; }
    .main-area { margin: 0 !important; }
    .page-content { overflow: visible !important; padding: 0 !important; }
    body { background: #fff; color: #000; }
    .card { border: 1px solid #ccc; box-shadow: none; }
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--accent);
    color: #fff;
    padding: 8px 16px;
    z-index: 10000;
    font-size: 0.85rem;
    text-decoration: none;
    border-radius: 0 0 4px 0;
    transition: top 0.2s;
}
.skip-link:focus {
    top: 0;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
    animation: fadeIn 0.3s ease forwards;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
