/* ============================================
   TransitPlan — Single CSS file, no preprocessor
   ============================================ */

/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #F3F4F6;
    --bg-white: #FFFFFF;
    --sidebar-bg: #1F2937;
    --sidebar-hover: #374151;
    --sidebar-active: #3B82F6;
    --text: #111827;
    --text-light: #6B7280;
    --text-white: #F9FAFB;
    --accent: #3B82F6;
    --accent-hover: #2563EB;
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
    --border: #E5E7EB;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 56px;
    --header-height: 56px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html { font-size: 14px; }
body { font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.app-body { display: flex; min-height: 100vh; }

.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--text-white);
    display: flex; flex-direction: column;
    transition: width 0.2s ease;
    z-index: 100;
    overflow-x: hidden;
}
.sidebar-collapsed { width: var(--sidebar-collapsed-width); }

.sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px; height: var(--header-height);
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-logo { font-weight: 700; font-size: 1.2rem; white-space: nowrap; }
.sidebar-toggle {
    background: none; border: none; color: var(--text-white);
    cursor: pointer; padding: 4px; border-radius: 4px;
    display: flex; align-items: center;
}
.sidebar-toggle:hover { background: var(--sidebar-hover); }

.sidebar-nav { flex: 1; padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: var(--radius);
    color: var(--text-white); white-space: nowrap;
    transition: background 0.15s;
}
.nav-item:hover { background: var(--sidebar-hover); text-decoration: none; }
.nav-item.active { background: var(--sidebar-active); }
.nav-item svg { flex-shrink: 0; }
.nav-divider { border-top: 1px solid rgba(255,255,255,0.1); margin: 8px 0; }

.main-wrapper {
    margin-left: var(--sidebar-width);
    flex: 1; display: flex; flex-direction: column;
    transition: margin-left 0.2s ease;
    min-height: 100vh;
}
.main-expanded { margin-left: var(--sidebar-collapsed-width); }

.top-header {
    height: var(--header-height);
    background: var(--bg-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;
}
.breadcrumb { color: var(--text-light); font-size: 0.9rem; }
.header-right { display: flex; align-items: center; gap: 12px; }
.user-name { color: var(--text); font-weight: 500; }

.content { padding: 24px; flex: 1; }

/* Auth layout */
.auth-wrapper {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-height: 100vh; padding: 24px;
}

/* Flash messages */
.flash-container { padding: 0 24px; margin-top: 16px; }
.flash {
    padding: 12px 16px; border-radius: var(--radius);
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 8px; font-weight: 500;
}
.flash-success { background: #D1FAE5; color: #065F46; }
.flash-error { background: #FEE2E2; color: #991B1B; }
.flash-warning { background: #FEF3C7; color: #92400E; }
.flash-info { background: #DBEAFE; color: #1E40AF; }
.flash-close { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: inherit; padding: 0 0 0 12px; }

/* Cards */
.card {
    background: var(--bg-white); border-radius: var(--radius);
    box-shadow: var(--shadow); border: 1px solid var(--border);
}
.card-header {
    padding: 16px 20px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.card-header h2 { font-size: 1.1rem; font-weight: 600; }
.card-body { padding: 20px; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: var(--radius);
    font-size: 0.9rem; font-weight: 500;
    border: 1px solid transparent; cursor: pointer;
    transition: all 0.15s; white-space: nowrap;
    font-family: var(--font);
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #DC2626; }
.btn-warning { background: var(--warning); color: white; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 4px; font-weight: 500; color: var(--text); }
.form-input, .form-select, .form-textarea {
    width: 100%; padding: 8px 12px;
    border: 1px solid var(--border); border-radius: var(--radius);
    font-size: 0.9rem; font-family: var(--font);
    background: var(--bg-white); color: var(--text);
    transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-error { color: var(--danger); font-size: 0.8rem; margin-top: 4px; }
.form-hint { color: var(--text-light); font-size: 0.8rem; margin-top: 4px; }
.form-row { display: flex; gap: 16px; }
.form-row > * { flex: 1; }
.form-check { display: flex; align-items: center; gap: 8px; }
.form-check input[type="checkbox"] { width: 16px; height: 16px; }

/* Tables */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--text-light); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; background: #F9FAFB; }
tr:hover td { background: #F9FAFB; }
td { font-size: 0.9rem; }

/* Badges */
.badge {
    display: inline-block; padding: 2px 8px;
    border-radius: 12px; font-size: 0.75rem; font-weight: 600;
}
.badge-blue { background: #DBEAFE; color: #1E40AF; }
.badge-green { background: #D1FAE5; color: #065F46; }
.badge-yellow { background: #FEF3C7; color: #92400E; }
.badge-red { background: #FEE2E2; color: #991B1B; }
.badge-gray { background: #F3F4F6; color: #4B5563; }

/* Stats cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--bg-white); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px;
    box-shadow: var(--shadow);
}
.stat-value { font-size: 2rem; font-weight: 700; color: var(--text); }
.stat-label { font-size: 0.85rem; color: var(--text-light); margin-top: 4px; }
.stat-card.stat-danger { border-left: 4px solid var(--danger); }
.stat-card.stat-success { border-left: 4px solid var(--success); }
.stat-card.stat-warning { border-left: 4px solid var(--warning); }
.stat-card.stat-info { border-left: 4px solid var(--accent); }

/* Auth form */
.auth-card {
    background: var(--bg-white); border-radius: var(--radius);
    box-shadow: var(--shadow-md); padding: 40px;
    width: 100%; max-width: 400px;
}
.auth-card h1 { font-size: 1.5rem; margin-bottom: 8px; text-align: center; }
.auth-card .subtitle { color: var(--text-light); text-align: center; margin-bottom: 24px; }

/* Modal */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.4);
    display: flex; align-items: center; justify-content: center;
    z-index: 200; padding: 24px;
}
.modal {
    background: var(--bg-white); border-radius: var(--radius);
    box-shadow: var(--shadow-md); width: 100%; max-width: 500px;
    max-height: 90vh; overflow-y: auto;
}
.modal-header {
    padding: 16px 20px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 1.1rem; }
.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* Page header */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 24px;
}
.page-header h1 { font-size: 1.5rem; font-weight: 700; }

/* Color dot */
.color-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: middle; margin-right: 6px; }

/* Empty state */
.empty-state {
    text-align: center; padding: 60px 20px; color: var(--text-light);
}
.empty-state svg { margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 { font-size: 1.1rem; color: var(--text); margin-bottom: 8px; }

/* Gantt container */
.gantt-container { position: relative; overflow: auto; background: var(--bg-white); border: 1px solid var(--border); border-radius: var(--radius); }

/* Calendar grid */
.calendar-grid {
    display: grid;
    grid-template-columns: 150px repeat(7, 1fr);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.calendar-cell {
    padding: 8px; border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border); min-height: 60px;
    font-size: 0.85rem;
}
.calendar-header { background: #F9FAFB; font-weight: 600; text-align: center; }
.calendar-driver { background: #F9FAFB; font-weight: 500; display: flex; align-items: center; }
.calendar-shift { border-radius: 4px; padding: 4px 6px; font-size: 0.8rem; }
.shift-morning { background: #DBEAFE; color: #1E40AF; }
.shift-afternoon { background: #FEF3C7; color: #92400E; }
.shift-night { background: #E9D5FF; color: #6B21A8; }
.shift-rest { background: #D1FAE5; color: #065F46; }

/* Loading spinner */
.spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar:not(.sidebar-collapsed) { transform: translateX(0); width: var(--sidebar-width); }
    .main-wrapper { margin-left: 0 !important; }
    .form-row { flex-direction: column; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
}

/* Utility */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-light { color: var(--text-light); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.gap-1 { gap: 8px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.hidden { display: none; }
.w-full { width: 100%; }

/* ============================================
   Reactive Gantt & Detail Panel
   ============================================ */

/* Violation pulse */
.gantt-violation {
    border: 2px solid var(--danger) !important;
    animation: pulse-violation 1.5s infinite;
}
@keyframes pulse-violation {
    0%, 100% { border-color: var(--danger); }
    50% { border-color: #FCA5A5; }
}

/* Detail panel (slide-in from right) */
.detail-panel {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: 320px; max-width: 90vw;
    background: var(--bg-white);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 12px rgba(0,0,0,0.1);
    z-index: 200;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
}
.detail-panel.open { transform: translateX(0); }
.detail-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 0; border-bottom: 1px solid #f3f4f6;
    font-size: 0.9rem;
}

/* Toast notifications */
.toast-msg {
    padding: 10px 16px; border-radius: var(--radius);
    font-size: 0.85rem; font-weight: 500;
    cursor: pointer; min-width: 240px; max-width: 400px;
    box-shadow: var(--shadow-md);
}
.toast-success { background: #065F46; color: white; }
.toast-error { background: #991B1B; color: white; }
.toast-warning { background: #92400E; color: white; }
.toast-info { background: #1E40AF; color: white; }

/* Chart containers */
.chart-container {
    position: relative; width: 100%;
}
.chart-container canvas { width: 100% !important; }

/* Context menu */
[x-cloak] { display: none !important; }

/* SVG timetable */
.td-trip-line { transition: stroke-width 0.15s, opacity 0.15s; }
.td-trip-line:hover { stroke-width: 3 !important; }

/* Vehicle map marker */
.vehicle-map-marker { background: transparent !important; border: none !important; }

/* Print styles */
@media print {
    .sidebar, .top-header, .flash-container, .detail-panel,
    .toast-msg, [data-confirm] { display: none !important; }
    .main-wrapper { margin-left: 0 !important; }
    .card { break-inside: avoid; box-shadow: none; border: 1px solid #ddd; }
}
