@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

html, body { overflow-x: hidden; max-width: 100vw; }

:root {
    --primary: #1e3a5f;
    --primary-light: #2d5a8e;
    --primary-dark: #0f1f33;
    --accent: #e63946;
    --accent-light: #ff6b6b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --bg: #f0f4f8;
    --bg-card: #ffffff;
    --text: #1a202c;
    --text-light: #64748b;
    --text-lighter: #94a3b8;
    --border: #e2e8f0;
    --sidebar-w: 260px;
    --header-h: 64px;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --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);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Inter', -apple-system, sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; }
a { color: var(--info); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-lighter); border-radius: 3px; }

/* Login */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%); position: relative; overflow: hidden; }
.login-page::before { content: ''; position: absolute; width: 400px; height: 400px; border-radius: 50%; background: rgba(255,255,255,0.03); top: -100px; right: -100px; }
.login-page::after { content: ''; position: absolute; width: 300px; height: 300px; border-radius: 50%; background: rgba(255,255,255,0.02); bottom: -50px; left: -50px; }
.login-card { background: white; border-radius: 20px; padding: 48px 40px; width: 420px; max-width: 90vw; box-shadow: var(--shadow-lg); position: relative; z-index: 1; }
.login-card img { height: 50px; display: block; margin: 0 auto 32px; }
.login-card h2 { text-align: center; font-size: 1.5rem; color: var(--primary); margin-bottom: 8px; }
.login-card p { text-align: center; color: var(--text-light); margin-bottom: 32px; font-size: 0.9rem; }

/* Forms */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.form-control { width: 100%; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 0.95rem; transition: all 0.2s; background: white; color: var(--text); }
.form-control:focus { outline: none; border-color: var(--info); box-shadow: 0 0 0 3px rgba(59,130,246,0.15); }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 20px; border-radius: 8px; font-size: 0.9rem; font-weight: 500; border: none; transition: all 0.2s; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { background: var(--accent-light); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; }
.btn-warning { background: var(--warning); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-info { background: var(--info); color: white; }
.btn-info:hover { background: #2563eb; }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: rgba(30,58,95,0.05); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon { width: 36px; height: 36px; padding: 0; justify-content: center; border-radius: 8px; }
.btn-group { display: flex; gap: 8px; }

/* Layout */
.app-layout { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--primary-dark); color: white; position: fixed; top: 0; left: 0; height: 100vh; z-index: 100; display: flex; flex-direction: column; transition: transform 0.3s; overflow-y: auto; }
.sidebar-header { padding: 16px 20px; display: flex; align-items: center; justify-content: center; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-header img { max-height: 42px; width: auto; filter: brightness(0) invert(1); }
.sidebar-nav { flex: 1; padding: 16px 12px; }
.sidebar-section { margin-bottom: 24px; }
.sidebar-section-title { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 1.5px; color: rgba(255,255,255,0.4); padding: 0 12px; margin-bottom: 8px; }
.sidebar-link { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; color: rgba(255,255,255,0.7); font-size: 0.9rem; transition: all 0.2s; }
.sidebar-link:hover { background: rgba(255,255,255,0.1); color: white; }
.sidebar-link.active { background: rgba(255,255,255,0.15); color: white; font-weight: 500; }
.sidebar-link .icon { width: 20px; text-align: center; font-size: 1.1rem; }
.sidebar-link .badge { margin-left: auto; background: var(--accent); color: white; font-size: 0.7rem; padding: 2px 8px; border-radius: 10px; font-weight: 600; }
.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,0.1); }
.sidebar-user { display: flex; align-items: center; gap: 10px; }
.sidebar-user .avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary-light); display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 0.85rem; }
.sidebar-user .info { flex: 1; }
.sidebar-user .info .name { font-size: 0.85rem; font-weight: 500; }
.sidebar-user .info .role { font-size: 0.7rem; color: rgba(255,255,255,0.5); }

.main-content { flex: 1; margin-left: var(--sidebar-w); max-width: 100vw; overflow-x: hidden; }
.header { height: var(--header-h); background: white; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; position: sticky; top: 0; z-index: 50; }
.header-left { display: flex; align-items: center; gap: 16px; min-width: 0; }
.header-left h1 { font-size: 1.25rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-right { display: flex; align-items: center; gap: 12px; }
.page-content { padding: 24px; max-width: 100%; overflow-x: hidden; }
.menu-toggle { display: none; background: none; border: none; font-size: 1.5rem; color: var(--text); }

/* KPI Cards */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.kpi-card { background: white; border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 14px; transition: all 0.2s; min-width: 0; }
.kpi-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.kpi-icon { width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; }
.kpi-icon.blue { background: #dbeafe; color: #2563eb; }
.kpi-icon.green { background: #d1fae5; color: #059669; }
.kpi-icon.amber { background: #fef3c7; color: #d97706; }
.kpi-icon.red { background: #fee2e2; color: #dc2626; }
.kpi-icon.purple { background: #ede9fe; color: #7c3aed; }
.kpi-icon.indigo { background: #e0e7ff; color: #4f46e5; }
.kpi-info { flex: 1; min-width: 0; overflow: hidden; }
.kpi-info .label { font-size: 0.78rem; color: var(--text-light); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-info .value { font-size: 1.35rem; font-weight: 700; color: var(--text); margin: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-info .change { font-size: 0.75rem; font-weight: 500; }
.kpi-info .change.up { color: var(--success); }
.kpi-info .change.down { color: var(--danger); }

/* Cards */
.card { background: white; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 20px; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-header h3 { font-size: 1rem; font-weight: 600; }
.card-body { padding: 20px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; }
.card-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }

/* Tables */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
table { width: 100%; border-collapse: collapse; table-layout: auto; }
th { text-align: left; padding: 8px 10px; font-size: 0.75rem; font-weight: 600; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.5px; background: #f8fafc; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 8px 10px; font-size: 0.85rem; border-bottom: 1px solid var(--border); }
tr:hover td { background: #f8fafc; }
tr:last-child td { border-bottom: none; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-purple { background: #ede9fe; color: #5b21b6; }

/* Filters Bar */
.filters-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.filters-bar .form-control { width: auto; min-width: 150px; padding: 8px 12px; font-size: 0.85rem; }
.search-input { position: relative; flex: 1; min-width: 200px; }
.search-input input { padding-left: 36px; position: relative; z-index: 0; width: 100%; }
.search-input .search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-lighter); pointer-events: none; z-index: 1; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 20px; backdrop-filter: blur(4px); }
.modal { background: white; border-radius: 16px; width: 100%; max-width: 600px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal-lg { max-width: 800px; }
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 1.1rem; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 1.5rem; color: var(--text-light); padding: 4px; }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* Route specific */
.route-timeline { position: relative; padding-left: 24px; }
.route-timeline::before { content: ''; position: absolute; left: 11px; top: 0; bottom: 0; width: 2px; background: var(--border); }
.route-stop { position: relative; padding: 12px 0 12px 24px; }
.route-stop .stop-marker { position: absolute; left: -24px; top: 16px; width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.7rem; font-weight: 700; color: white; z-index: 1; }
.route-stop .stop-marker.pending { background: var(--text-lighter); }
.route-stop .stop-marker.active { background: var(--info); animation: pulse 2s infinite; }
.route-stop .stop-marker.done { background: var(--success); }
.route-stop .stop-marker.skipped { background: var(--danger); }
.stop-card { background: #f8fafc; border-radius: 10px; padding: 14px 16px; border: 1px solid var(--border); transition: all 0.2s; }
.stop-card:hover { border-color: var(--info); box-shadow: var(--shadow); }
.stop-card .stop-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.stop-card .stop-name { font-weight: 600; font-size: 0.95rem; }
.stop-card .stop-time { font-size: 0.8rem; color: var(--text-light); font-weight: 500; }
.stop-card .stop-address { font-size: 0.8rem; color: var(--text-light); margin-bottom: 4px; }
.stop-card .stop-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.stop-card .suggestion-tag { font-size: 0.7rem; background: #e0f2fe; color: #0369a1; padding: 2px 8px; border-radius: 4px; }

/* Map placeholder */
.map-container { width: 100%; height: 400px; background: #e2e8f0; border-radius: var(--radius); display: flex; align-items: center; justify-content: center; color: var(--text-light); position: relative; overflow: hidden; }
.map-container iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: none; border-radius: var(--radius); }

/* Calendar */
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.calendar-header { text-align: center; font-size: 0.75rem; font-weight: 600; color: var(--text-light); padding: 8px; text-transform: uppercase; }
.calendar-day { min-height: 80px; padding: 6px; border-radius: 8px; background: #f8fafc; border: 1px solid transparent; transition: all 0.2s; }
.calendar-day:hover { border-color: var(--info); }
.calendar-day.today { background: #eff6ff; border-color: var(--info); }
.calendar-day.other-month { opacity: 0.4; }
.calendar-day .day-num { font-size: 0.8rem; font-weight: 600; color: var(--text-light); margin-bottom: 4px; }
.calendar-day .day-event { font-size: 0.65rem; padding: 2px 4px; border-radius: 3px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: white; font-weight: 500; }

/* AI Panel */
.ai-card { border-left: 4px solid var(--info); }
.ai-suggestion { display: flex; gap: 12px; padding: 12px; background: #f0f9ff; border-radius: 8px; margin-bottom: 8px; }
.ai-suggestion .ai-icon { font-size: 1.5rem; }
.ai-suggestion .ai-text h4 { font-size: 0.9rem; font-weight: 600; margin-bottom: 2px; }
.ai-suggestion .ai-text p { font-size: 0.8rem; color: var(--text-light); }

/* Risk indicator */
.risk-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.risk-dot.bajo { background: var(--success); }
.risk-dot.medio { background: var(--warning); }
.risk-dot.alto { background: #f97316; }
.risk-dot.critico { background: var(--danger); }
.risk-dot.dormido { background: var(--text-lighter); }

/* Animations */
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(59,130,246,0.4); } 50% { box-shadow: 0 0 0 8px rgba(59,130,246,0); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn 0.3s ease; }

/* Loading */
.spinner { width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state { text-align: center; padding: 48px 20px; }
.empty-state .icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state h3 { font-size: 1.1rem; margin-bottom: 8px; }
.empty-state p { color: var(--text-light); font-size: 0.9rem; margin-bottom: 20px; }

/* Toast */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 20px; border-radius: 8px; color: white; font-size: 0.9rem; font-weight: 500; box-shadow: var(--shadow-lg); animation: slideIn 0.3s ease; min-width: 280px; display: flex; align-items: center; gap: 8px; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--info); }
@keyframes slideIn { from { opacity: 0; transform: translateX(100px); } to { opacity: 1; transform: translateX(0); } }

/* Drag handle */
.drag-handle { cursor: grab; color: var(--text-lighter); font-size: 1.2rem; }
.drag-handle:active { cursor: grabbing; }

/* Priority colors */
.priority-urgente { color: var(--danger); font-weight: 600; }
.priority-alta { color: #f97316; font-weight: 500; }
.priority-normal { color: var(--text-light); }
.priority-baja { color: var(--text-lighter); }

/* Responsive */
@media (max-width: 1100px) {
    .kpi-grid { grid-template-columns: repeat(3, 1fr); }
    .card-grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; max-width: 100vw; }
    .menu-toggle { display: block; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .card-grid { grid-template-columns: 1fr; }
    .card-grid-3 { grid-template-columns: 1fr; }
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
    .filters-bar { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px; }
    .filters-bar .form-control { min-width: auto; flex: 1 1 120px; padding: 6px 10px; font-size: 0.8rem; }
    .filters-bar .search-input { flex: 1 1 100%; }
    .page-content { padding: 12px; }
    th { padding: 6px 6px; font-size: 0.65rem; }
    td { padding: 6px 6px; font-size: 0.78rem; }
    .kpi-card { padding: 12px; gap: 10px; }
    .kpi-icon { width: 36px; height: 36px; font-size: 1rem; }
    .kpi-info .value { font-size: 1.15rem; }
    .card-body { padding: 12px; }
    .calendar-grid { font-size: 0.75rem; }
    .calendar-day { min-height: 50px; }
}

/* Tabs */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab { padding: 10px 20px; font-size: 0.9rem; font-weight: 500; color: var(--text-light); border-bottom: 2px solid transparent; margin-bottom: -2px; cursor: pointer; transition: all 0.2s; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Progress bar */
.progress { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 4px; transition: width 0.3s; }
.progress-bar.green { background: var(--success); }
.progress-bar.blue { background: var(--info); }
.progress-bar.amber { background: var(--warning); }
.progress-bar.red { background: var(--danger); }

/* Stat inline */
.stat-inline { display: flex; align-items: center; gap: 8px; }
.stat-inline .stat-value { font-size: 1.2rem; font-weight: 700; }
.stat-inline .stat-label { font-size: 0.8rem; color: var(--text-light); }

/* Chart container */
.chart-container { position: relative; height: 280px; }

/* Score badges */
.score-critico { background: #fecaca !important; color: #991b1b !important; }
.score-alto { background: #fed7aa !important; color: #9a3412 !important; }
.score-medio { background: #fef3c7 !important; color: #92400e !important; }
.score-bajo { background: #d1fae5 !important; color: #065f46 !important; }

/* Frequency badges */
.badge-purple { background: #ede9fe; color: #6d28d9; }

/* Toggle switch */
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: #cbd5e1; border-radius: 24px; transition: 0.3s; }
.toggle-slider::before { content: ''; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: 0.3s; }
.toggle-switch input:checked + .toggle-slider { background: var(--success); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }
.toggle-switch input:disabled + .toggle-slider { opacity: 0.5; cursor: not-allowed; }
