:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --bg: #f1f5f9;
    --white: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
    --radius: 8px;
    --topbar-height: 56px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

/* Login */
.login-screen {
    display: flex; align-items: center; justify-content: center;
    min-height: 85vh; background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}
.login-card {
    background: var(--white); border-radius: 16px; padding: 48px 40px;
    width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo svg { margin-bottom: 16px; }
.login-logo h1 { font-size: 22px; font-weight: 700; color: var(--text); }
.login-logo p { font-size: 13px; color: var(--text-light); margin-top: 4px; }
.login-field { margin-bottom: 20px; }
.login-field label { display: block; font-size: 13px; font-weight: 500; color: var(--text-light); margin-bottom: 6px; }
.login-field input {
    width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius);
    font-size: 15px; color: var(--text); font-family: inherit; transition: border-color 0.2s;
}
.login-field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.login-btn { width: 100%; padding: 14px; font-size: 15px; margin-top: 8px; justify-content: center; }
.login-error { background: #fee2e2; color: #991b1b; padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 12px; }

/* App container */
#app-container { display: none; flex-direction: column; /*min-height: 100vh;*/ }
#app-container.visible { display: flex; }

/* Top bar */
.topbar {
    height: var(--topbar-height);
    background: linear-gradient(90deg, #1e293b 0%, #0f172a 100%);
    color: white;
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.topbar-brand {
    display: flex; align-items: center; gap: 10px;
    padding-right: 20px;
    border-right: 1px solid rgba(255,255,255,0.15);
    flex-shrink: 0;
}
.topbar-brand svg { color: var(--primary); }
.topbar-brand h1 { font-size: 15px; font-weight: 700; line-height: 1.2; }
.topbar-brand p { font-size: 10px; color: #94a3b8; }
.topbar-nav {
    display: flex; align-items: center; gap: 4px; flex: 1;
}
.topbar-nav .nav-item {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 14px;
    border: none; background: none;
    color: #94a3b8;
    font-size: 13px; font-weight: 500;
    cursor: pointer; border-radius: 6px;
    transition: all 0.2s;
    font-family: inherit;
    white-space: nowrap;
}
.topbar-nav .nav-item:hover { background: rgba(255,255,255,0.08); color: white; }
.topbar-nav .nav-item.active { background: rgba(37,99,235,0.25); color: white; }
.logout-btn {
    display: flex; align-items: center; gap: 6px;
    background: none; border: 1px solid rgba(255,255,255,0.15);
    color: #94a3b8; font-size: 12px; cursor: pointer;
    padding: 6px 12px; border-radius: 6px;
    font-family: inherit; transition: all 0.2s;
    flex-shrink: 0;
}
.logout-btn:hover { color: #ef4444; border-color: #ef4444; }

/* Main */
.main-content { flex: 1; padding: 20px 24px; }
.view { display: none; }
.view.active { display: block; }
.view-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.view-header h2 { font-size: 22px; font-weight: 700; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 18px;
    border: none; border-radius: var(--radius);
    font-size: 14px; font-weight: 500;
    cursor: pointer; transition: all 0.2s;
    text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-danger { background: #ef4444; color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-xs { padding: 4px 8px; font-size: 11px; border-radius: 4px; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card {
    background: var(--white); border-radius: var(--radius); padding: 18px;
    box-shadow: var(--shadow);
}
.stat-card .stat-label { font-size: 11px; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.stat-card .stat-value { font-size: 26px; font-weight: 700; margin-top: 4px; color: var(--text); }
.stat-card .stat-sub { font-size: 12px; color: var(--text-light); margin-top: 4px; }
.stat-card.blue { border-left: 4px solid var(--primary); }
.stat-card.green { border-left: 4px solid #10b981; }
.stat-card.orange { border-left: 4px solid #f59e0b; }
.stat-card.purple { border-left: 4px solid #8b5cf6; }

/* Charts */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.chart-card {
    background: var(--white); border-radius: var(--radius); padding: 20px;
    box-shadow: var(--shadow);
}
.chart-card h4 { font-size: 14px; font-weight: 600; margin-bottom: 16px; color: var(--text); }
.chart-bar-container { display: flex; flex-direction: column; gap: 10px; }
.chart-bar-row { display: flex; align-items: center; gap: 10px; }
.chart-bar-label { font-size: 12px; color: var(--text-light); width: 110px; flex-shrink: 0; text-align: right; }
.chart-bar-track { flex: 1; height: 28px; background: #f1f5f9; border-radius: 6px; overflow: hidden; position: relative; }
.chart-bar-fill { height: 100%; border-radius: 6px; display: flex; align-items: center; padding: 0 10px; font-size: 11px; font-weight: 600; color: white; min-width: 36px; transition: width 0.6s ease; }
.chart-bar-fill.borrador { background: linear-gradient(90deg, #f59e0b, #d97706); }
.chart-bar-fill.enviada { background: linear-gradient(90deg, #3b82f6, #2563eb); }
.chart-bar-fill.negociacion { background: linear-gradient(90deg, #6366f1, #4f46e5); }
.chart-bar-fill.ganada { background: linear-gradient(90deg, #10b981, #059669); }
.chart-bar-fill.perdida { background: linear-gradient(90deg, #ef4444, #dc2626); }
.chart-bar-value { font-size: 12px; color: var(--text); font-weight: 600; width: 80px; text-align: right; flex-shrink: 0; }

.chart-donut-wrap { display: flex; align-items: center; gap: 24px; }
.chart-donut-svg { width: 160px; height: 160px; flex-shrink: 0; }
.chart-legend { display: flex; flex-direction: column; gap: 8px; }
.chart-legend-item { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.chart-legend-dot { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.chart-legend-value { font-weight: 600; margin-left: auto; }

/* Kanban */
.kanban-board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 16px; min-height: calc(100vh - 160px); }
.kanban-column { flex: 1; min-width: 220px; max-width: 280px; display: flex; flex-direction: column; }
.kanban-header {
    padding: 10px 14px; border-radius: var(--radius) var(--radius) 0 0;
    font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
    display: flex; align-items: center; gap: 8px;
}
.kanban-header.borrador { background: #fef3c7; color: #92400e; }
.kanban-header.enviada { background: #dbeafe; color: #1e40af; }
.kanban-header.negociacion { background: #e0e7ff; color: #3730a3; }
.kanban-header.ganada { background: #d1fae5; color: #065f46; }
.kanban-header.perdida { background: #fee2e2; color: #991b1b; }
.kanban-count {
    display: inline-flex; align-items: center; justify-content: center;
    width: 22px; height: 22px; border-radius: 50%;
    background: rgba(0,0,0,0.15); font-size: 11px; font-weight: 700;
}
.kanban-cards {
    flex: 1; background: #f8fafc; border-radius: 0 0 var(--radius) var(--radius);
    padding: 8px; display: flex; flex-direction: column; gap: 8px;
    min-height: 150px;
}
.kanban-card {
    background: var(--white); border-radius: var(--radius); padding: 12px;
    box-shadow: var(--shadow); cursor: pointer; transition: all 0.2s;
    border-left: 3px solid transparent;
}
.kanban-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.kanban-card .card-title { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.kanban-card .card-client { font-size: 11px; color: var(--text-light); margin-bottom: 6px; }
.kanban-card .card-value { font-size: 15px; font-weight: 700; color: var(--primary); }
.kanban-card .card-date { font-size: 10px; color: var(--text-light); margin-top: 4px; }
.kanban-card .card-actions { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }

/* Tables */
.filter-bar { display: flex; gap: 12px; margin-bottom: 16px; }
.filter-bar input, .filter-bar select {
    padding: 8px 14px; border: 1px solid var(--border); border-radius: var(--radius);
    font-size: 14px; background: var(--white); color: var(--text);
}
.filter-bar input { flex: 1; max-width: 400px; }
.table-container { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { background: #f8fafc; padding: 10px 14px; text-align: left; font-size: 11px; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; border-bottom: 1px solid var(--border); }
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
.data-table tr:hover { background: #f8fafc; }
.data-table tr:last-child td { border-bottom: none; }

/* Status badges */
.badge {
    display: inline-block; padding: 3px 8px; border-radius: 20px;
    font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px;
}
.badge-borrador { background: #fef3c7; color: #92400e; }
.badge-enviada { background: #dbeafe; color: #1e40af; }
.badge-negociacion { background: #e0e7ff; color: #3730a3; }
.badge-ganada { background: #d1fae5; color: #065f46; }
.badge-perdida { background: #fee2e2; color: #991b1b; }

/* Modal */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 1000;
    justify-content: center; align-items: flex-start;
    padding: 30px 20px; overflow-y: auto;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--white); border-radius: 12px; width: 100%; max-width: 560px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3); animation: slideIn 0.2s ease;
}
.modal-large { max-width: 900px; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 18px 24px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 17px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-light); padding: 4px 8px; }
.modal-close:hover { color: var(--text); }
.modal form, .modal .modal-body { padding: 24px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 12px; padding: 14px 24px; border-top: 1px solid var(--border); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.full-width { grid-column: 1 / -1; }
.form-group label { font-size: 13px; font-weight: 500; color: var(--text-light); }
.form-group input, .form-group select, .form-group textarea {
    padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px;
    font-size: 14px; color: var(--text); font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* Lineas presupuesto */
.lineas-section { margin: 14px 0; background: #f8fafc; border-radius: var(--radius); padding: 14px; }
.lineas-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.lineas-header h4 { font-size: 14px; font-weight: 600; }
.lineas-table-wrap { overflow-x: auto; }
.lineas-table { width: 100%; border-collapse: collapse; background: var(--white); border-radius: 6px; overflow: hidden; }
.lineas-table th { padding: 8px 10px; font-size: 11px; text-transform: uppercase; color: var(--text-light); background: #f1f5f9; text-align: left; font-weight: 600; }
.lineas-table td { padding: 6px 4px; }
.lineas-table input { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px; }
.lineas-table .btn-remove { background: none; border: none; color: #ef4444; cursor: pointer; font-size: 18px; padding: 4px; }
.lineas-totals { display: flex; flex-direction: column; align-items: flex-end; margin-top: 10px; }
.total-row { display: flex; justify-content: space-between; width: 220px; padding: 4px 0; font-size: 14px; }
.total-row.total-final { font-weight: 700; font-size: 16px; color: var(--primary); border-top: 2px solid var(--primary); padding-top: 8px; margin-top: 4px; }

/* Detalle */
.detalle-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.detalle-info { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px; }
.detalle-box { background: #f8fafc; border-radius: var(--radius); padding: 14px; }
.detalle-box h4 { font-size: 11px; text-transform: uppercase; color: var(--text-light); letter-spacing: 0.5px; margin-bottom: 6px; font-weight: 600; }
.detalle-box p { font-size: 13px; line-height: 1.6; }
.detalle-estado-select { padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; font-weight: 500; }

/* Recent section */
.recent-section { margin-top: 20px; }
.recent-section h3 { font-size: 16px; font-weight: 600; margin-bottom: 12px; }

/* Responsive */
@media (max-width: 768px) {
    .topbar { flex-wrap: wrap; height: auto; padding: 10px; }
    .topbar-brand { border-right: none; padding-right: 0; }
    .topbar-nav { order: 3; width: 100%; overflow-x: auto; }
    .form-grid { grid-template-columns: 1fr; }
    .detalle-info { grid-template-columns: 1fr; }
    .charts-grid { grid-template-columns: 1fr; }
}

/* Toast */
.toast {
    position: fixed; bottom: 24px; right: 24px; z-index: 2000;
    background: #1e293b; color: white; padding: 12px 20px;
    border-radius: var(--radius); font-size: 14px;
    box-shadow: var(--shadow-lg);
    animation: slideInUp 0.3s ease;
}
.toast.success { background: #059669; }
.toast.error { background: #dc2626; }
@keyframes slideInUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Empty state */
.empty-state { text-align: center; padding: 30px; color: var(--text-light); }
.empty-state p { font-size: 13px; }
