/* RESET & VARIABLES */
:root {
    --primary: #4F46E5;
    /* Indigo 600 */
    --primary-light: #EEF2FF;
    /* Indigo 50 */
    --text-main: #1F2937;
    /* Gray 800 */
    --text-secondary: #6B7280;
    /* Gray 500 */
    --bg-body: #F9FAFB;
    /* Gray 50 */
    --bg-card: #FFFFFF;
    --border: #F3F4F6;
    /* Gray 100 */
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background-color: #f0f2f5;
    /* Slightly darker than body for desktop contrast */
    color: var(--text-main);
    line-height: 1.5;
    height: 100vh;
    display: flex;
    justify-content: center;
}

/* APP SHELL (Mobile Container) */
.app-shell {
    width: 100%;
    max-width: 480px;
    height: 100%;
    /* Full viewport height */
    background: var(--bg-body);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.05);
}

/* APP HEADER */
.app-header {
    height: 64px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card);
    position: sticky;
    top: 0;
    z-index: 50;
    /* Removed confusing border, using subtle shadow instead */
    /* border-bottom: 1px solid var(--border); */
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: rgb(235, 250, 255);
    color: white;
    display: flex;
    /* Ensure center alignment for the image or placeholder */
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.logo-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.logo-text h1 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.025em;
}

.logo-text span {
    display: none;
    /* Hide subtitle for cleaner look */
}

.header-actions {
    display: flex;
    gap: 8px;
}

/* GENERIC BUTTONS */
.icon-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    /* Removed border */
    background: transparent;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.2s;
}

.icon-button:hover {
    background: var(--border);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-xl);
    padding: 12px 24px;
    font-weight: 600;
    font-size: 0.95rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    gap: 8px;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 6px 16px rgba(79, 70, 229, 0.4);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--border);
    color: var(--text-main);
}

.btn-block {
    width: 100%;
}

.text-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.85rem;
}

.btn-text {
    background: none;
    border: none;
    padding: 0;
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: none;
    display: inline-block;
    vertical-align: baseline;
}

.btn-text:hover {
    text-decoration: underline;
}

/* MAIN CONTENT AREA */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px 100px;
    /* Extra bottom padding for floating nav */
    scroll-behavior: smooth;
    /* Hide scrollbar for cleaner look */
    scrollbar-width: none;
    /* Firefox */
}

.main-content::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

/* VIEW SWITCHING */
.view {
    animation: fadeIn 0.3s ease-out;
}

.view.hidden {
    display: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* AUTH FORMS */
.auth-container {
    padding: 24px 4px;
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.auth-header h2 {
    font-size: 1.75rem;
    font-weight: 800;
    margin-bottom: 8px;
    color: var(--text-main);
    letter-spacing: -0.03em;
}

.auth-header p {
    color: var(--text-secondary);
}

.auth-tabs {
    background: var(--border);
    padding: 4px;
    border-radius: var(--radius-xl);
    display: flex;
    margin-bottom: 24px;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
    animation: fadeIn 0.3s ease-out;
}

.tab-btn {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    border-radius: var(--radius-lg);
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn.active {
    background: white;
    color: var(--text-main);
    box-shadow: var(--shadow-sm);
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-main);
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    width: auto;
    font-weight: 500;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    margin: 0;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 14px 16px;
    border-radius: var(--radius-lg);
    border: 1px solid #E5E7EB;
    /* Lighter border */
    background: var(--bg-card);
    font-size: 1rem;
    color: var(--text-main);
    transition: all 0.2s;
    outline: none;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-light);
}

.role-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.role-option {
    border: 1px solid #E5E7EB;
    background: white;
    border-radius: var(--radius-lg);
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.role-option i {
    font-size: 1.5rem;
    color: var(--text-secondary);
}

.role-option.active {
    border-color: var(--primary);
    background: var(--primary-light);
}

.role-option.active i,
.role-option.active span {
    color: var(--primary);
    font-weight: 600;
}

/* SIDEBAR / DRAWER */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 80%;
    /* Wider on mobile, but max-width constrained */
    max-width: 320px;
    background: white;
    /* LIGHT THEME! */
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    padding: 24px;
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 24px;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--bg-body);
    border-radius: var(--radius-xl);
    margin-bottom: 32px;
}

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1.2rem;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 700;
    color: var(--text-main);
}

.user-role {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 16px;
    border-radius: var(--radius-lg);
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s;
}

.sidebar-nav .nav-link i {
    width: 24px;
    font-size: 1.1rem;
    text-align: center;
}

.sidebar-nav .nav-link.active,
.sidebar-nav .nav-link:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    /* Darker backdrop */
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* DASHBOARD & STATS */
.dashboard-header {
    margin-bottom: 24px;
}

.dashboard-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

.quick-actions h3,
.section-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text-main);
}

.quick-actions-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    /* 4 cols for small icons */
    gap: 12px;
    margin-bottom: 32px;
}

.quick-action-btn {
    aspect-ratio: 1;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}

.quick-action-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-light);
}

.quick-action-btn i {
    font-size: 1.25rem;
    color: var(--primary);
}

.quick-action-btn span {
    font-size: 0.7rem;
    font-weight: 500;
    text-align: center;
    line-height: 1.1;
    color: var(--text-secondary);
}

.stats {
    display: grid;
    grid-template-columns: 1fr;
    /* Stack on very small, but maybe 3 cols fits */
    gap: 12px;
    margin-bottom: 32px;
}

@media (min-width: 360px) {
    .stats {
        grid-template-columns: repeat(3, 1fr);
    }
}

.stat-card {
    background: white;
    padding: 16px 12px;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
}

.stat-icon {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 4px;
}

.stat-icon.vehicles {
    background: #E0F2FE;
    color: #0284C7;
}

.stat-icon.routes {
    background: #DCFCE7;
    color: #16A34A;
}

.stat-icon.incidents {
    background: #FEE2E2;
    color: #DC2626;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* LISTS (Incidencias / Rutas) */
.list-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: transparent;
    padding: 0;
    box-shadow: none;
}

/* IMPROVED LIST CARDS */
.route-card {
    background: white;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s;
}

.route-card:active {
    transform: scale(0.98);
}

.route-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.route-id {
    font-weight: 700;
    color: var(--text-main);
    font-family: monospace;
    font-size: 1.1rem;
}

.route-status-badge {
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 600;
}

.route-status-badge.active {
    background: #DCFCE7;
    color: #15803D;
}

.route-status-badge.pending {
    background: #FEF3C7;
    color: #B45309;
}

.route-status-badge.completed {
    background: #F3F4F6;
    color: #4B5563;
}

.route-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-left: 4px;
    position: relative;
}

.route-point {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    color: var(--text-main);
    word-break: break-word;
    /* Prevent overflow */
}

.route-line {
    position: absolute;
    left: 7px;
    top: 18px;
    bottom: 18px;
    width: 2px;
    background: #E5E7EB;
    z-index: 0;
}

.text-green {
    color: #10B981;
}

.text-red {
    color: #EF4444;
}

.route-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border);
    padding-top: 10px;
    margin-top: 4px;
}

.route-meta-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.route-actions {
    display: flex;
    gap: 8px;
}

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s;
}

.btn-icon.primary {
    background: #E0F2FE;
    color: var(--primary);
}

.btn-icon.danger {
    background: #FEE2E2;
    color: var(--danger);
}

.btn-icon:hover {
    opacity: 0.8;
}

/* INCIDENTS (Legacy Compact) */
.incident-item {
    background: white;
    padding: 16px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
    /* Allow wrapping */
}

/* BOTTOM NAVIGATION */
.bottom-nav {
    position: absolute;
    bottom: 0px;
    left: 0;
    width: 100%;
    height: 72px;
    /* Taller for modern look */
    background: white;
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid var(--border);
    padding-bottom: 12px;
    /* iOS Home indicator safe areaish */
    z-index: 40;
}

.nav-item {
    background: transparent;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: #9CA3AF;
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    width: 60px;
}

.nav-item i {
    font-size: 1.4rem;
    margin-bottom: 2px;
    transition: transform 0.2s;
}

.nav-item.active {
    color: var(--primary);
}

.nav-item.active i {
    transform: translateY(-2px);
}

/* MAP VIEW */
.map-wrapper {
    position: relative;
    width: 100%;
    height: calc(100vh - 64px - 72px);
    /* Adjust based on header/nav height if needed, or flex:1 */
    height: 100%;
    /* If parent is flex/grid */
    min-height: 400px;
    overflow: hidden;
}

#viewDiv {
    padding: 0;
    margin: 0;
    height: 100%;
    width: 100%;
}

/* MAP UTIL BUTTONS */
.planner-toggle-btn {
    position: absolute;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    z-index: 10;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.planner-toggle-btn:hover {
    transform: scale(1.1);
}

.planner-toggle-btn:active {
    transform: scale(0.95);
}

/* ROUTE PLANNER PANEL (Bottom Sheet) */
.route-planner-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: 20px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    z-index: 20;
    transform: translateY(110%);
    /* Hidden by default */
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);

    /* MOBILE FIXES */
    max-height: 85vh;
    /* Increase height */
    overflow-y: auto;
    /* Enable scrolling */
    padding-bottom: 40px;
    /* Safe area for scrolling */

    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Ensure actions stick or are visible */
.route-actions {
    padding-bottom: 10px;
}

/* Fix Forms */
textarea,
select,
input {
    font-family: 'Inter', sans-serif;
}

textarea {
    width: 100%;
    min-height: 100px;
    padding: 12px;
    border-radius: var(--radius-md);
    border: 1px solid #D1D5DB;
    resize: vertical;
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.1);
}

.route-planner-panel.active {
    transform: translateY(0);
}

.panel-handle {
    width: 40px;
    height: 4px;
    background: #E5E7EB;
    border-radius: 2px;
    margin: 0 auto 8px;
}

.planner-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.planner-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
}

.route-actions {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 12px;
    margin-top: 8px;
}

.route-result-actions {
    background: #F0FDF4;
    border: 1px solid #DCFCE7;
    border-radius: var(--radius-md);
    padding: 12px;
    animation: fadeIn 0.3s ease-out;
}

/* UTILS */
.hidden {
    display: none !important;
}