/* ==============================================================================
   FLOWGENCE BUDGET - SISTEMA DE DISEÑO CLARO, MINIMALISTA Y ELEGANTE
   Inspirado en la interfaz corporativa de Flowgence / Imagining Agency
   ============================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800&family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
    /* Paleta Principal Flowgence (Púrpura / Violeta / Acento) */
    --primary-color: #8b5cf6;
    --primary-hover: #7c3aed;
    --primary-light: rgba(139, 92, 246, 0.08);
    --primary-gradient: linear-gradient(135deg, #9333ea, #7c3aed);

    --accent-color: #06b6d4;
    --accent-hover: #0891b2;
    --accent-light: rgba(6, 182, 212, 0.08);

    /* Estados Planos y Minimalistas */
    --status-presented: #3b82f6;
    --status-presented-bg: #eff6ff;
    --status-approved: #10b981;
    --status-approved-bg: #ecfdf5;
    --status-billed: #8b5cf6;
    --status-billed-bg: #f5f3ff;
    --status-postponed: #f59e0b;
    --status-postponed-bg: #fffbeb;
    --status-cancelled: #ef4444;
    --status-cancelled-bg: #fef2f2;

    /* TEMA CLARO PREDETERMINADO (Clean Minimalist White) */
    --bg-body: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-elevated: #f1f5f9;
    --bg-surface-glass: rgba(255, 255, 255, 0.95);
    --border-color: #e2e8f0;
    --border-color-light: #f1f5f9;
    --border-color-focus: rgba(139, 92, 246, 0.4);
    --text-main: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    /* Sidebar Oscuro Minimalista */
    --sidebar-bg: #090d16;
    --sidebar-text: #94a3b8;
    --sidebar-text-hover: #ffffff;
    --sidebar-border: rgba(255, 255, 255, 0.06);

    --card-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.04), 0 1px 2px -1px rgba(0, 0, 0, 0.04);
    --card-shadow-hover: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;
}

[data-theme="dark"] {
    --bg-body: #0b0f19;
    --bg-surface: #111827;
    --bg-surface-elevated: #1e293b;
    --bg-surface-glass: rgba(17, 24, 39, 0.92);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-color-light: rgba(255, 255, 255, 0.04);
    --border-color-focus: rgba(139, 92, 246, 0.5);
    --text-main: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --sidebar-bg: #070a12;
    --card-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    --card-shadow-hover: 0 14px 30px -5px rgba(0, 0, 0, 0.6);
}

/* ==============================================================================
   RESET & BASE STYLES
   ============================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
    line-height: 1.5;
    font-size: 0.92rem;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.02em;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.15s ease;
}

a:hover {
    color: var(--primary-hover);
}

/* SVG Helpers */
svg.icon {
    width: 18px;
    height: 18px;
    vertical-align: middle;
    flex-shrink: 0;
}

/* ==============================================================================
   LAYOUT & SIDEBAR (DARK MINIMALIST)
   ============================================================================== */
.app-container {
    display: flex;
    width: 100vw;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 40;
    transition: all 0.25s ease;
}

.sidebar-header {
    padding: 24px 20px 20px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand-logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    width: 100%;
}

.brand-logo img {
    width: auto;
    max-width: 100%;
    object-fit: contain;
}

.sidebar-nav {
    flex: 1;
    padding: 10px 14px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-section-title {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #475569;
    padding: 14px 12px 6px 12px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    color: var(--sidebar-text);
    font-weight: 500;
    font-size: 0.88rem;
    transition: all 0.15s ease;
    text-decoration: none;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: #ffffff;
}

.nav-item.active {
    background: var(--primary-gradient);
    color: #ffffff;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(139, 92, 246, 0.35);
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 16px 14px;
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.user-profile-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-full);
    background: var(--primary-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #ffffff;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-weight: 600;
    font-size: 0.84rem;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role-tag {
    font-size: 0.7rem;
    color: #a78bfa;
    text-transform: capitalize;
}

.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-body);
}

/* ==============================================================================
   TOPBAR (CLEAN WHITE)
   ============================================================================== */
.topbar {
    height: 68px;
    padding: 0 32px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 30;
}

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

.page-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.page-subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 400;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.content-area {
    flex: 1;
    padding: 28px 32px;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
}

/* ==============================================================================
   ALERTA / BANNER SUPERIOR INFORMATIVO
   ============================================================================== */
.alert-banner {
    background: linear-gradient(90deg, #fff1f2, #fdf4ff);
    border: 1px solid #fecdd3;
    border-radius: var(--radius-lg);
    padding: 12px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    font-size: 0.86rem;
    color: #9f1239;
}

[data-theme="dark"] .alert-banner {
    background: rgba(225, 29, 72, 0.1);
    border-color: rgba(225, 29, 72, 0.25);
    color: #fda4af;
}

/* ==============================================================================
   BANNER DE RECUPERACIÓN DE BORRADORES AUTOGUARDADOS
   ============================================================================== */
.draft-recovery-banner {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.08), rgba(217, 119, 6, 0.04));
    border: 1px solid rgba(245, 158, 11, 0.35);
    border-left: 5px solid #f59e0b;
    border-radius: var(--radius-lg);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    animation: draftBannerSlide 0.3s ease-out forwards;
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.08);
}

[data-theme="dark"] .draft-recovery-banner {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.15), rgba(0, 0, 0, 0.25));
    border-color: rgba(245, 158, 11, 0.4);
    border-left-color: #fbbf24;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

@keyframes draftBannerSlide {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.draft-recovery-info {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
}

.draft-recovery-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(245, 158, 11, 0.15);
    color: #d97706;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

[data-theme="dark"] .draft-recovery-icon {
    background: rgba(245, 158, 11, 0.25);
    color: #fbbf24;
}

.draft-recovery-text h4 {
    margin: 0 0 3px 0;
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text-main);
}

.draft-recovery-text p {
    margin: 0;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.draft-recovery-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

/* ==============================================================================
   BADGE DE ESTADO DE AUTOGUARDADO
   ============================================================================== */
.autosave-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.76rem;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 9999px;
    transition: all 0.25s ease;
    user-select: none;
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-muted);
    border: 1px solid transparent;
}

[data-theme="dark"] .autosave-badge {
    background: rgba(255, 255, 255, 0.06);
}

.autosave-badge.saving {
    background: rgba(245, 158, 11, 0.12);
    color: #b45309;
    border-color: rgba(245, 158, 11, 0.25);
}

[data-theme="dark"] .autosave-badge.saving {
    background: rgba(245, 158, 11, 0.2);
    color: #fbbf24;
}

.autosave-badge.saved {
    background: rgba(16, 185, 129, 0.12);
    color: #047857;
    border-color: rgba(16, 185, 129, 0.25);
}

[data-theme="dark"] .autosave-badge.saved {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
}

.autosave-badge.error {
    background: rgba(239, 68, 68, 0.12);
    color: #b91c1c;
    border-color: rgba(239, 68, 68, 0.25);
}

[data-theme="dark"] .autosave-badge.error {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
}

.autosave-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.autosave-badge.saving .autosave-dot {
    animation: autosavePulse 1s infinite alternate;
}

@keyframes autosavePulse {
    from { opacity: 0.3; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1.2); }
}

/* ==============================================================================
   CARDS & CONTAINERS
   ============================================================================== */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--card-shadow);
    padding: 22px;
    position: relative;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color-light);
}

.card-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ==============================================================================
   METRIC KPI CARDS (CLEAN WHITE CON ICONOS PASTEL)
   ============================================================================== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    box-shadow: var(--card-shadow);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

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

.kpi-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.kpi-icon.purple  { background: #f5f3ff; color: #8b5cf6; }
.kpi-icon.blue    { background: #eff6ff; color: #3b82f6; }
.kpi-icon.pink    { background: #fdf2f8; color: #ec4899; }
.kpi-icon.green   { background: #ecfdf5; color: #10b981; }
.kpi-icon.amber   { background: #fffbeb; color: #f59e0b; }

[data-theme="dark"] .kpi-icon.purple { background: rgba(139, 92, 246, 0.15); }
[data-theme="dark"] .kpi-icon.blue   { background: rgba(59, 130, 246, 0.15); }
[data-theme="dark"] .kpi-icon.pink   { background: rgba(236, 72, 153, 0.15); }
[data-theme="dark"] .kpi-icon.green  { background: rgba(16, 185, 129, 0.15); }
[data-theme="dark"] .kpi-icon.amber  { background: rgba(245, 158, 11, 0.15); }

.kpi-content {
    flex: 1;
    min-width: 0;
}

.kpi-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
}

.kpi-value {
    font-family: 'Outfit', sans-serif;
    font-size: 1.55rem;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1.15;
}

.kpi-subtext {
    font-size: 0.72rem;
    color: #10b981;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
}

/* ==============================================================================
   BUTTONS & INPUTS
   ============================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 18px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.86rem;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s ease;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary-gradient);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 4px 14px rgba(139, 92, 246, 0.45);
    transform: translateY(-1px);
    color: #ffffff;
}

.btn-secondary {
    background: var(--bg-surface-elevated);
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.btn-secondary:hover {
    background: #e2e8f0;
    color: var(--text-main);
}

[data-theme="dark"] .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.btn-outline {
    background: #ffffff;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

[data-theme="dark"] .btn-outline {
    background: var(--bg-surface);
}

.btn-outline:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: var(--primary-light);
}

.btn-danger {
    background: #fef2f2;
    border: 1px solid #fee2e2;
    color: #ef4444;
}

.btn-danger:hover {
    background: #ef4444;
    color: #ffffff;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.78rem;
    border-radius: var(--radius-sm);
}

.btn-icon {
    padding: 8px;
    border-radius: var(--radius-md);
}

.btn-sm.btn-icon {
    padding: 4px;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

/* Formularios */
.form-group {
    margin-bottom: 18px;
}

.form-label {
    display: block;
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-label .required {
    color: #ef4444;
}

.form-control, .form-select, textarea {
    width: 100%;
    padding: 9px 12px;
    border-radius: var(--radius-md);
    background: #ffffff;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.88rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

[data-theme="dark"] .form-control, [data-theme="dark"] .form-select, [data-theme="dark"] textarea {
    background: var(--bg-surface-elevated);
}

.form-control:focus, .form-select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--border-color-focus);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
}

/* ==============================================================================
   TABLES & LISTS
   ============================================================================== */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.86rem;
}

.data-table th {
    background: var(--bg-surface-elevated);
    padding: 12px 16px;
    font-weight: 700;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color-light);
    color: var(--text-secondary);
    vertical-align: middle;
}

.data-table tbody tr {
    transition: background 0.1s ease;
}

.data-table tbody tr:hover {
    background: #f8fafc;
}

[data-theme="dark"] .data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.data-table td strong {
    color: var(--text-main);
}

/* ==============================================================================
   STATUS BADGES (PLANOS & MINIMALISTAS)
   ============================================================================== */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}

.badge-info    { background: var(--status-presented-bg); color: var(--status-presented); }
.badge-info .badge-dot { background: var(--status-presented); }

.badge-success { background: var(--status-approved-bg); color: var(--status-approved); }
.badge-success .badge-dot { background: var(--status-approved); }

.badge-primary { background: var(--status-billed-bg); color: var(--status-billed); }
.badge-primary .badge-dot { background: var(--status-billed); }

.badge-warning { background: var(--status-postponed-bg); color: var(--status-postponed); }
.badge-warning .badge-dot { background: var(--status-postponed); }

.badge-danger  { background: var(--status-cancelled-bg); color: var(--status-cancelled); }
.badge-danger .badge-dot { background: var(--status-cancelled); }

.badge-secondary { background: #f1f5f9; color: #64748b; }
.badge-secondary .badge-dot { background: #64748b; }

/* ==============================================================================
   BUDGET BUILDER
   ============================================================================== */
.budget-builder-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 120px;
}

.phase-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--card-shadow);
    overflow: hidden;
}

.phase-header {
    background: #f8fafc;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    gap: 12px;
}

[data-theme="dark"] .phase-header {
    background: rgba(255, 255, 255, 0.03);
}

.phase-title-input {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1.05rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-main);
    padding: 4px 8px;
    flex: 1;
}

.phase-title-input:hover, .phase-title-input:focus {
    background: #ffffff;
    border-color: var(--border-color-focus);
}

[data-theme="dark"] .phase-title-input:hover, [data-theme="dark"] .phase-title-input:focus {
    background: var(--bg-surface-elevated);
}

.phase-body {
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.rubro-card {
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--primary-color);
    border-radius: var(--radius-md);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

[data-theme="dark"] .rubro-card {
    background: var(--bg-surface-elevated);
}

.rubro-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.rubro-title-input {
    font-weight: 600;
    font-size: 0.95rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--primary-color);
    padding: 4px 8px;
    flex: 1;
}

.items-table-wrapper {
    overflow-x: auto;
    background: #ffffff;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .items-table-wrapper {
    background: var(--bg-surface);
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
}

.items-table th {
    background: #f8fafc;
    padding: 9px 10px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

[data-theme="dark"] .items-table th {
    background: rgba(0, 0, 0, 0.2);
}

.items-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-color-light);
    vertical-align: top;
}

.item-calc-output {
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
    text-align: right;
    padding: 8px 10px;
    white-space: nowrap;
}

.item-agency-private {
    color: var(--text-muted);
    background: #fdf4ff;
}

[data-theme="dark"] .item-agency-private {
    background: rgba(0, 0, 0, 0.15);
}

/* ==============================================================================
   DRAG AND DROP JERÁRQUICO (FASES -> RUBROS -> ÍTEMS)
   ============================================================================== */
.drag-handle-cell {
    width: 36px;
    min-width: 36px;
    max-width: 36px;
    padding: 8px 4px !important;
    text-align: center;
    vertical-align: middle !important;
    user-select: none;
    -webkit-user-select: none;
}

.drag-handle {
    cursor: grab;
    cursor: -webkit-grab;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm, 6px);
    color: var(--text-muted);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.drag-handle:active {
    cursor: grabbing;
    cursor: -webkit-grabbing;
}

/* Handle de Fase */
.drag-handle-phase {
    width: 30px;
    height: 30px;
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--border-color);
}

.drag-handle-phase:hover {
    background-color: var(--accent-light, rgba(245, 158, 11, 0.15));
    color: var(--accent-color);
    border-color: var(--accent-color);
    transform: scale(1.08);
}

.phase-card.sortable-chosen .drag-handle-phase,
.phase-card.phase-sortable-chosen .drag-handle-phase {
    color: var(--accent-color);
    cursor: grabbing;
    cursor: -webkit-grabbing;
}

/* Handle de Rubro */
.drag-handle-rubro {
    width: 26px;
    height: 26px;
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--border-color);
}

.drag-handle-rubro:hover {
    background-color: var(--primary-light, rgba(139, 92, 246, 0.12));
    color: var(--primary-color);
    border-color: var(--primary-color);
    transform: scale(1.08);
}

.rubro-card.sortable-chosen .drag-handle-rubro,
.rubro-card.rubro-sortable-chosen .drag-handle-rubro {
    color: var(--primary-color);
    cursor: grabbing;
    cursor: -webkit-grabbing;
}

/* Handle de Ítem */
.drag-handle-item {
    width: 26px;
    height: 26px;
}

.drag-handle-item:hover,
.drag-handle:not(.drag-handle-phase):not(.drag-handle-rubro):hover {
    background-color: var(--primary-light, rgba(139, 92, 246, 0.12));
    color: var(--primary-color);
    transform: scale(1.1);
}

.drag-handle-item:active,
tr.sortable-chosen .drag-handle-item {
    cursor: grabbing;
    cursor: -webkit-grabbing;
    color: var(--primary-color);
}

/* ==============================================================================
   SortableJS Estados Visuales - Fases
   ============================================================================== */
.phase-card.sortable-ghost,
.phase-card.phase-sortable-ghost {
    opacity: 0.35 !important;
    background: rgba(245, 158, 11, 0.05) !important;
    border: 2px dashed var(--accent-color) !important;
    box-shadow: none !important;
    outline: none !important;
}

.phase-card.sortable-chosen,
.phase-card.phase-sortable-chosen {
    background: var(--bg-surface) !important;
    box-shadow: 0 16px 36px -6px rgba(0, 0, 0, 0.2), 0 6px 14px -4px rgba(0, 0, 0, 0.08) !important;
    border-color: var(--accent-color) !important;
}

.phase-card.sortable-drag,
.phase-card.phase-sortable-drag {
    opacity: 0.98 !important;
    cursor: grabbing !important;
    box-shadow: 0 25px 45px -10px rgba(0, 0, 0, 0.28), 0 12px 18px -6px rgba(0, 0, 0, 0.12) !important;
}

/* ==============================================================================
   SortableJS Estados Visuales - Rubros
   ============================================================================== */
.rubro-card.sortable-ghost,
.rubro-card.rubro-sortable-ghost {
    opacity: 0.35 !important;
    background: var(--primary-light, rgba(139, 92, 246, 0.08)) !important;
    border: 2px dashed var(--primary-color) !important;
    box-shadow: none !important;
    outline: none !important;
}

.rubro-card.sortable-chosen,
.rubro-card.rubro-sortable-chosen {
    background: var(--bg-surface) !important;
    box-shadow: 0 12px 28px -6px rgba(0, 0, 0, 0.18), 0 4px 10px -3px rgba(0, 0, 0, 0.08) !important;
    border-color: var(--primary-color) !important;
}

.rubro-card.sortable-drag,
.rubro-card.rubro-sortable-drag {
    opacity: 0.98 !important;
    cursor: grabbing !important;
    box-shadow: 0 20px 35px -8px rgba(0, 0, 0, 0.25) !important;
}

/* ==============================================================================
   SortableJS Estados Visuales - Ítems
   ============================================================================== */
tr.sortable-ghost,
tr.item-sortable-ghost {
    opacity: 0.35 !important;
    background: var(--primary-light, rgba(139, 92, 246, 0.08)) !important;
    outline: 2px dashed var(--primary-color) !important;
    outline-offset: -2px;
}

tr.sortable-chosen,
tr.item-sortable-chosen {
    background: var(--bg-surface, #ffffff) !important;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.08);
}

tr.sortable-drag,
tr.item-sortable-drag {
    opacity: 0.98 !important;
    background: var(--bg-surface, #ffffff) !important;
    box-shadow: 0 20px 30px -10px rgba(0, 0, 0, 0.25), 0 10px 15px -5px rgba(0, 0, 0, 0.1) !important;
    cursor: grabbing !important;
}

/* Modo Oscuro - Drag and Drop */
[data-theme="dark"] .drag-handle-phase,
[data-theme="dark"] .drag-handle-rubro {
    background: rgba(255, 255, 255, 0.04);
}

[data-theme="dark"] .phase-card.sortable-chosen,
[data-theme="dark"] .phase-card.phase-sortable-chosen,
[data-theme="dark"] .phase-card.sortable-drag,
[data-theme="dark"] .phase-card.phase-sortable-drag {
    background: var(--bg-surface-elevated, #1e293b) !important;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.55) !important;
}

[data-theme="dark"] .rubro-card.sortable-chosen,
[data-theme="dark"] .rubro-card.rubro-sortable-chosen,
[data-theme="dark"] .rubro-card.sortable-drag,
[data-theme="dark"] .rubro-card.rubro-sortable-drag {
    background: var(--bg-surface-elevated, #1e293b) !important;
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.5) !important;
}

[data-theme="dark"] tr.sortable-chosen,
[data-theme="dark"] tr.sortable-drag,
[data-theme="dark"] tr.item-sortable-chosen,
[data-theme="dark"] tr.item-sortable-drag {
    background: var(--bg-surface, #1e293b) !important;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5) !important;
}

/* Fallback Nativo HTML5 */
.native-dragging {
    opacity: 0.4 !important;
    background: var(--primary-light, rgba(139, 92, 246, 0.1)) !important;
}

tr.native-drag-over-top {
    border-top: 2px solid var(--primary-color) !important;
}

tr.native-drag-over-bottom {
    border-bottom: 2px solid var(--primary-color) !important;
}

.items-table tbody tr {
    transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

.items-table tbody tr:hover .drag-handle {
    color: var(--text-secondary);
}

.items-table tbody:empty {
    min-height: 48px;
    display: table-row-group;
}

/* Área de soltado para contenedor de rubros vacío */
.phase-body:empty {
    min-height: 75px;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.015);
    position: relative;
    transition: all 0.2s ease;
}

.phase-body:empty::after {
    content: "Arrastra un rubro aquí o haz clic en '+ Rubro'";
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

[data-theme="dark"] .phase-body:empty {
    background: rgba(255, 255, 255, 0.02);
    border-color: rgba(255, 255, 255, 0.1);
}


/* Barra Flotante de Totales */
.financial-sticky-bar {
    position: fixed;
    bottom: 0;
    left: 260px;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.06);
    padding: 14px 32px;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    transition: left 0.25s ease;
}

[data-theme="dark"] .financial-sticky-bar {
    background: rgba(17, 24, 39, 0.95);
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
}

.financial-group {
    display: flex;
    align-items: center;
    gap: 24px;
}

.finance-metric {
    display: flex;
    flex-direction: column;
}

.finance-metric-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.finance-metric-val {
    font-family: 'Outfit', sans-serif;
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text-main);
}

.finance-metric-val.client-total {
    color: var(--primary-color);
    font-size: 1.35rem;
}

.agency-private-box {
    background: #fdf4ff;
    border: 1px dashed #d8b4fe;
    border-radius: var(--radius-md);
    padding: 5px 12px;
    display: flex;
    align-items: center;
    gap: 14px;
}

[data-theme="dark"] .agency-private-box {
    background: rgba(139, 92, 246, 0.08);
    border-color: rgba(139, 92, 246, 0.3);
}

/* Modales */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.15);
    width: 90%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-body {
    padding: 22px;
}

.modal-footer {
    padding: 16px 22px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

/* Toasts */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 200;
}

.toast {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    padding: 12px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-main);
    font-weight: 500;
    font-size: 0.86rem;
}

.toast.success { border-left: 4px solid #10b981; }
.toast.danger  { border-left: 4px solid #ef4444; }
.toast.warning { border-left: 4px solid #f59e0b; }
.toast.info    { border-left: 4px solid #3b82f6; }

/* ==============================================================================
   SIDEBAR COLLAPSED STATE (DESKTOP)
   ============================================================================== */
.sidebar.collapsed {
    width: 72px;
}

.sidebar.collapsed .sidebar-header {
    padding: 20px 12px 16px 12px;
    justify-content: center;
}

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

.sidebar.collapsed .brand-logo::after {
    content: '';
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: var(--primary-gradient);
    display: block;
    flex-shrink: 0;
}

.sidebar.collapsed .sidebar-nav {
    padding: 10px 8px;
}

.sidebar.collapsed .nav-section-title {
    font-size: 0;
    padding: 8px 0;
    text-align: center;
    overflow: hidden;
    height: 8px;
}

.sidebar.collapsed .nav-section-title::after {
    content: '';
    display: block;
    width: 24px;
    height: 1px;
    background: var(--sidebar-border);
    margin: 0 auto;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 10px;
    position: relative;
}

.sidebar.collapsed .nav-item span {
    display: none;
}

.sidebar.collapsed .nav-item svg {
    width: 20px;
    height: 20px;
}

/* Tooltip en hover cuando está colapsado */
.sidebar.collapsed .nav-item::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: #1e293b;
    color: #ffffff;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 60;
}

.sidebar.collapsed .nav-item:hover::after {
    opacity: 1;
}

.sidebar.collapsed .sidebar-footer {
    padding: 12px 8px;
}

.sidebar.collapsed .user-info {
    display: none;
}

.sidebar.collapsed .user-profile-badge {
    justify-content: center;
    padding: 6px 0;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.sidebar.collapsed .user-profile-badge .btn-icon {
    margin: 0;
}

/* Sidebar collapse toggle button in sidebar */
.sidebar-collapse-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #94a3b8;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
    padding: 0;
}

.sidebar-collapse-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
}

.sidebar.collapsed .sidebar-collapse-btn {
    margin: 0 auto;
}

.sidebar.collapsed .sidebar-collapse-btn svg {
    transform: rotate(180deg);
}

/* Adjust main content and financial bar when sidebar collapses */
.app-container.sidebar-collapsed .main-wrapper {
    /* This is handled by flex, sidebar shrinks so main grows */
}

.app-container.sidebar-collapsed .financial-sticky-bar {
    left: 72px;
}

/* Sidebar mobile overlay backdrop */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 39;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.sidebar-backdrop.active {
    display: block;
    opacity: 1;
}

/* ==============================================================================
   RESPONSIVE: TABLET (max-width: 1024px)
   ============================================================================== */
@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        left: -260px;
        width: 260px !important;
        z-index: 40;
    }

    .sidebar.open {
        left: 0;
    }

    /* Reset collapsed state on mobile - always show full sidebar when open */
    .sidebar.collapsed {
        width: 260px;
        left: -260px;
    }

    .sidebar.collapsed.open {
        left: 0;
    }

    .sidebar.collapsed .brand-logo img,
    .sidebar.collapsed .brand-logo svg {
        display: block;
    }

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

    .sidebar.collapsed .nav-section-title {
        font-size: 0.68rem;
        height: auto;
        padding: 14px 12px 6px 12px;
    }

    .sidebar.collapsed .nav-section-title::after {
        display: none;
    }

    .sidebar.collapsed .nav-item {
        justify-content: flex-start;
        padding: 10px 14px;
    }

    .sidebar.collapsed .nav-item span {
        display: inline;
    }

    .sidebar.collapsed .nav-item::after {
        display: none;
    }

    .sidebar.collapsed .user-info {
        display: block;
    }

    .sidebar.collapsed .user-profile-badge {
        flex-direction: row;
        padding: 6px 8px;
    }

    .sidebar.collapsed .sidebar-header {
        padding: 24px 20px 20px 20px;
        justify-content: space-between;
    }

    .sidebar.collapsed .sidebar-nav {
        padding: 10px 14px;
    }

    .sidebar.collapsed .sidebar-footer {
        padding: 16px 14px;
    }

    /* Hide desktop collapse button on mobile */
    .sidebar-collapse-btn {
        display: none;
    }

    .financial-sticky-bar {
        left: 0;
    }

    /* Show mobile toggle */
    #btnToggleSidebar {
        display: inline-flex !important;
    }

    /* Dashboard grids */
    .dashboard-chart-grid {
        grid-template-columns: 1fr !important;
    }

    .dashboard-bottom-grid {
        grid-template-columns: 1fr !important;
    }

    .topbar {
        padding: 0 20px;
    }

    .content-area {
        padding: 20px;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ==============================================================================
   RESPONSIVE: MOBILE (max-width: 768px)
   ============================================================================== */
@media (max-width: 768px) {
    .topbar {
        height: 56px;
        padding: 0 14px;
        gap: 8px;
    }

    .page-title {
        font-size: 1rem;
    }

    .page-subtitle {
        display: none;
    }

    .topbar-actions {
        gap: 6px;
    }

    .topbar-actions .btn-primary span {
        display: none;
    }

    .topbar-actions .btn-primary {
        padding: 8px;
    }

    .content-area {
        padding: 14px;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .kpi-card {
        padding: 14px;
        gap: 10px;
    }

    .kpi-icon {
        width: 36px;
        height: 36px;
    }

    .kpi-value {
        font-size: 1.2rem;
    }

    .kpi-label {
        font-size: 0.65rem;
    }

    /* Cards */
    .card {
        padding: 16px;
    }

    .card-header {
        flex-wrap: wrap;
        gap: 8px;
    }

    /* Financial sticky bar */
    .financial-sticky-bar {
        padding: 10px 14px;
        gap: 10px;
        flex-wrap: wrap;
    }

    .financial-group {
        gap: 12px;
        flex-wrap: wrap;
    }

    .finance-metric-val {
        font-size: 0.95rem;
    }

    .finance-metric-val.client-total {
        font-size: 1.1rem;
    }

    .agency-private-box {
        gap: 8px;
        flex-wrap: wrap;
        padding: 4px 8px;
    }

    /* Budget builder */
    .budget-builder-container {
        margin-bottom: 160px;
    }

    .phase-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 12px 14px;
    }

    .phase-header > div:last-child {
        justify-content: flex-end;
    }

    .rubro-header {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .rubro-header > div:last-child {
        justify-content: flex-end;
    }

    .items-table-wrapper {
        margin: 0 -14px;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .rubro-card {
        padding: 10px;
    }

    .phase-body {
        padding: 12px;
    }

    /* Tables */
    .data-table th,
    .data-table td {
        padding: 10px 12px;
        font-size: 0.82rem;
    }

    /* Modal */
    .modal-card {
        width: 95%;
        max-width: none;
        margin: 10px;
    }

    /* Forms */
    .form-row {
        grid-template-columns: 1fr;
    }

    /* Alert banner */
    .alert-banner {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
        font-size: 0.82rem;
        padding: 10px 14px;
    }

    /* Configuracion grid adjustments */
    .config-logo-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ==============================================================================
   RESPONSIVE: SMALL MOBILE (max-width: 480px)
   ============================================================================== */
@media (max-width: 480px) {
    .topbar {
        height: 50px;
        padding: 0 10px;
    }

    .page-title {
        font-size: 0.9rem;
    }

    .content-area {
        padding: 10px;
    }

    .kpi-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .kpi-card {
        padding: 12px;
    }

    .kpi-value {
        font-size: 1.1rem;
    }

    .card {
        padding: 12px;
        border-radius: var(--radius-md);
    }

    .card-header {
        margin-bottom: 12px;
        padding-bottom: 8px;
    }

    .card-title {
        font-size: 0.92rem;
    }

    /* Financial bar - stack vertically */
    .financial-sticky-bar {
        flex-direction: column;
        align-items: stretch;
        padding: 8px 10px;
        gap: 6px;
    }

    .financial-group {
        justify-content: space-between;
    }

    .finance-metric-label {
        font-size: 0.62rem;
    }

    .finance-metric-val {
        font-size: 0.85rem;
    }

    .finance-metric-val.client-total {
        font-size: 1rem;
    }

    .agency-private-box {
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
    }

    /* Budget builder margins */
    .budget-builder-container {
        margin-bottom: 200px;
    }

    .phase-title-input {
        font-size: 0.92rem;
    }

    .btn-sm {
        padding: 5px 8px;
        font-size: 0.72rem;
    }

    /* Table and items */
    .items-table {
        font-size: 0.76rem;
    }

    .items-table th {
        font-size: 0.64rem;
        padding: 6px 4px;
    }

    .items-table td {
        padding: 6px 4px;
    }

    .item-calc-output {
        font-size: 0.78rem;
        padding: 6px 4px;
    }

    .data-table th,
    .data-table td {
        padding: 8px;
        font-size: 0.78rem;
    }

    /* Toast */
    .toast-container {
        left: 10px;
        right: 10px;
        bottom: 10px;
    }

    .toast {
        font-size: 0.82rem;
        padding: 10px 14px;
    }

    /* Modal full width */
    .modal-card {
        width: 100%;
        max-height: 100vh;
        border-radius: var(--radius-md);
        margin: 5px;
    }

    .modal-header {
        padding: 14px;
    }

    .modal-body {
        padding: 14px;
    }

    .modal-footer {
        padding: 12px 14px;
    }

    /* Hide non-essential table columns on very small screens */
    .hide-mobile {
        display: none !important;
    }
}

/* ==============================================================================
   DUPLICACIÓN DE FASES, RUBROS E ÍTEMS (FEEDBACK VISUAL & ACCIONES)
   ============================================================================== */
@keyframes cloneHighlight {
    0% {
        box-shadow: 0 0 0 2px var(--primary-color), 0 4px 16px rgba(99, 102, 241, 0.3);
    }
    100% {
        box-shadow: none;
    }
}

.phase-card.clone-highlight,
.rubro-card.clone-highlight {
    animation: cloneHighlight 1.3s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

tr.clone-highlight td {
    background-color: rgba(99, 102, 241, 0.15) !important;
    transition: background-color 1.3s ease;
}

.phase-number-badge {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--primary-color);
    min-width: 28px;
    display: inline-block;
}

