:root {
    --primary-color: #0F2C59; /* Deep Navy */
    --secondary-color: #4F709C; /* Steel Blue */
    --background: #F4F6F9;
    --surface: #FFFFFF;
    --text-main: #333333;
    --text-light: #7A7A7A;
    --error: #D32F2F;
    --success: #2E7D32;
    --border-radius: 6px;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
body { background-color: var(--background); color: var(--text-main); overflow: hidden; }
.view { display: none; }
.view.active { display: flex; height: 100vh; height: 100dvh; width: 100vw; overflow: hidden; }
.hidden { display: none !important; }

/* LOGIN SCREEN */
#login-view { align-items: center; justify-content: center; background-color: var(--primary-color); }
.login-card { background: var(--surface); padding: 40px; border-radius: var(--border-radius); box-shadow: 0 10px 25px rgba(0,0,0,0.2); width: 100%; max-width: 400px; text-align: center; }
.login-card h2 { margin-bottom: 5px; color: var(--primary-color); }
.login-card p { color: var(--text-light); margin-bottom: 25px; font-size: 0.9em; }

.form-group { margin-bottom: 15px; text-align: left; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 600; font-size: 0.85em; color: var(--primary-color); }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: var(--border-radius); outline: none; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--secondary-color); }

.btn { width: 100%; padding: 10px 15px; border: none; border-radius: var(--border-radius); cursor: pointer; font-weight: bold; transition: background 0.2s; }
.btn-primary { background: var(--primary-color); color: white; }
.btn-primary:hover { background: var(--secondary-color); }
.btn-secondary { background: #e0e0e0; color: var(--text-main); }
.btn-small { width: auto; padding: 5px 10px; font-size: 0.85em; }

.error-text { color: var(--error); font-size: 0.85em; margin-bottom: 10px; }
.text-success { color: var(--success); font-weight: bold; }

/* APP LAYOUT */
.sidebar { width: 250px; background: var(--primary-color); color: white; display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sidebar .brand-logo { padding: 20px; font-size: 1.2em; font-weight: bold; border-bottom: 1px solid rgba(255,255,255,0.1); flex-shrink: 0; }
.nav-item { padding: 15px 20px; color: #cfd8dc; text-decoration: none; display: block; transition: 0.2s; border-left: 3px solid transparent; flex-shrink: 0; }
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,0.1); color: white; border-left: 3px solid var(--secondary-color); }

.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.top-header { height: 60px; background: white; border-bottom: 1px solid #e0e0e0; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; }
.header-title { font-weight: 600; color: var(--text-light); }
.user-menu { display: flex; align-items: center; gap: 15px; }
.badge-role { background: var(--secondary-color); color: white; padding: 3px 8px; border-radius: 12px; font-size: 0.75em; }

.content-area { padding: 20px; overflow-y: auto; overflow-x: hidden; flex: 1; -webkit-overflow-scrolling: touch; }
.content-section { display: none; }
.content-section.active { display: block; }
.content-section h2 { margin-bottom: 20px; color: var(--primary-color); }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 20px; }
.stat-card, .form-card { background: white; padding: 20px; border-radius: var(--border-radius); box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.stat-card h3 { font-size: 0.9em; color: var(--text-light); margin-bottom: 10px; }
.stat-card p { font-size: 1.8em; font-weight: bold; color: var(--primary-color); }

/* UI CLEANUP: Remove old teal and yellow colors */
.summary-box { background: var(--surface); color: var(--text-main); padding: 20px; border-radius: 8px; border: 1px solid #ddd; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.summary-label { color: var(--secondary-color); font-weight: bold; width: 140px; display: inline-block; text-align: right; margin-right: 10px; }
.summary-val { color: var(--text-main); font-weight: 500; }
.log-box { background: #f8f9fa; padding: 15px; border-radius: 6px; margin-bottom: 10px; color: var(--text-main); font-family: monospace; border-left: 4px solid var(--secondary-color); border: 1px solid #eee; }
.madad-box { background: #fff3e0; color: var(--text-main); padding: 10px; border-radius: 6px; margin-top: 10px; font-weight: bold; border-left: 5px solid #e65100; border: 1px solid #ffe0b2; }

/* ==========================================
   RESPONSIVE MOBILE UI FIXES
========================================== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.menu-toggle-btn { display: none; background: none; border: none; font-size: 1.5em; cursor: pointer; color: var(--primary-color); margin-right: 10px; padding: 0; }
.mobile-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 1500; }

@media (max-width: 768px) {
    .form-grid, .summary-grid, .grid-4 { grid-template-columns: 1fr !important; }
    .sidebar { position: fixed; left: -260px; top: 0; bottom: 0; z-index: 2000; transition: left 0.3s ease; box-shadow: 2px 0 10px rgba(0,0,0,0.2); }
    .sidebar.open { left: 0; }
    .mobile-overlay.active { display: block; }
    .menu-toggle-btn { display: block; }
    .header-title { font-size: 0.9em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
    .user-info #user-display-name { display: none; }
    .top-header { padding: 0 10px; }
    .content-area { padding: 10px; }
    .summary-box, .form-card { padding: 15px; }
    input[type="text"], input[type="time"], input[type="date"], input[type="tel"], input[type="email"], input[type="password"], select, textarea { font-size: 16px; }
    table th, table td { padding: 8px !important; font-size: 0.85em; }
    .summary-label { width: 110px; font-size: 0.85em; }
    .summary-val { font-size: 0.85em; }
}

/* ==========================================
   PRINT STYLES (For generating clean reports)
========================================== */
@media print {
    .sidebar, .top-header, .mobile-overlay, .print-btn, .menu-toggle-btn { display: none !important; }
    .view.active, .main-content, .content-area { display: block !important; height: auto !important; width: 100% !important; overflow: visible !important; margin: 0 !important; padding: 0 !important; }
    .content-section { display: none !important; }
    .content-section.active { display: block !important; }
    body { background-color: white !important; color: black !important; }
    table { width: 100% !important; border-collapse: collapse !important; }
    th { border: 1px solid #ccc !important; color: white !important; padding: 8px !important; }
    td { border: 1px solid #ccc !important; color: black !important; padding: 8px !important; }
    .stat-card, .form-card { box-shadow: none !important; border: 1px solid #ccc !important; break-inside: avoid; }
    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
    
    /* Hide everything except the data table in print */
    #dashboard .card-grid, .hover-stat-grid, .dashboard-circles { display: none !important; }
    #dashboard > div:first-of-type { display: none !important; } /* Hides date picker and title */
    #dashboard > h3 { display: none !important; } /* Hides 'Scheduled Trains' text */
    
    /* Smart column hiding based on print selection */
    body.print-escorting .col-maintenance { display: none !important; }
    body.print-maintenance .col-escorting { display: none !important; }
}