:root {
    --primary:         #1d4ed8;
    --primary-dark:    #1e3a8a;
    --primary-mid:     #2563eb;
    --primary-light:   #dbeafe;
    --primary-xlight:  #eff6ff;
    --accent:          #0ea5e9;
    --success:         #16a34a;
    --success-light:   #dcfce7;
    --danger:          #dc2626;
    --danger-light:    #fee2e2;
    --warning:         #d97706;
    --warning-light:   #fef3c7;
    --text-main:       #0f172a;
    --text-muted:      #64748b;
    --text-light:      #94a3b8;
    --text-on-primary: #ffffff;
    --bg-body:         #f0f7ff;
    --bg-card:         #ffffff;
    --bg-subtle:       #f8fafc;
    --border:          #bfdbfe;
    --border-light:    #e0f2fe;
    --shadow-sm:       0 1px 3px rgba(29,78,216,0.08);
    --shadow-md:       0 4px 16px rgba(29,78,216,0.12);
    --shadow-lg:       0 8px 32px rgba(29,78,216,0.16);
    --radius-sm:       8px;
    --radius:          14px;
    --radius-lg:       20px;
    --font:            -apple-system, BlinkMacSystemFont, "Segoe UI",
                       Roboto, Inter, Arial, sans-serif;
    /* Legacy aliases for class names that referenced old vars */
    --font-main:       var(--font);
    --white:           var(--bg-card);
}

* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color:transparent; }

body {
    font-family: var(--font);
    background: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    padding-bottom: 80px;
}

a { color: var(--primary); }

/* --- Layout --- */
.container { max-width:600px; margin:0 auto; padding:16px; }

/* --- Unified primary header --- */
.header {
    background: var(--primary);
    color: var(--text-on-primary);
    padding: 14px 16px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-logo {
    width: 40px;
    height: 40px;
    background: rgba(255,255,255,0.18);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-logo svg { color: var(--text-on-primary); }

.header h1 {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-on-primary);
    letter-spacing: -0.03em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-right {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.18);
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-on-primary);
    text-decoration: none;
    transition: background .15s;
}
.header-right:hover { background: rgba(255,255,255,0.28); }

.header-login-btn {
    background: var(--text-on-primary);
    color: var(--primary);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 0.85rem;
    text-decoration: none;
    transition: background .15s;
}
.header-login-btn:hover { background: var(--primary-xlight); }

.user-chip-wrap { position: relative; }
.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.18);
    color: var(--text-on-primary);
    border: none;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background .15s;
}
.user-chip:hover { background: rgba(255,255,255,0.28); }

.user-menu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 180px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    z-index: 80;
}
.user-menu.open { display: block; }
.user-menu a {
    display: block;
    padding: 12px 16px;
    color: var(--text-main);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
}
.user-menu a:hover { background: var(--primary-xlight); color: var(--primary); }

/* Solid header retained for confirmation/error pages */
.header-solid {
    background: var(--primary);
    color: var(--text-on-primary);
    padding: 18px 16px;
    position: sticky; top:0; z-index:50;
    box-shadow: var(--shadow-md);
}
.header-solid h1 { font-size:1.2rem; font-weight:700; color: var(--text-on-primary); }

/* Page hero subtitle (below header) */
.page-hero {
    padding: 20px 16px 4px;
    max-width: 600px;
    margin: 0 auto;
}
.page-hero h2 {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.04em;
    line-height: 1.2;
}
.page-hero p {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* --- Auth pages (login / signup) --- */
.auth-bg {
    background: var(--primary-dark);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    padding-bottom: 20px;
}
.auth-card {
    width: 100%;
    max-width: 420px;
    padding: 32px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-light);
}
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-logo {
    width: 56px; height: 56px;
    border-radius: 16px;
    background: var(--primary);
    display: inline-flex; align-items: center; justify-content: center;
    margin-bottom: 12px;
}
.auth-brand h1 {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.02em;
}
.auth-brand p {
    margin-top: 4px;
    font-size: 0.88rem;
    color: var(--text-muted);
}
.auth-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0 18px;
    font-size: 0.88rem;
    color: var(--text-main);
    font-weight: 500;
    cursor: pointer;
}
.auth-check input { width: 16px; height: 16px; padding: 0; }
.auth-foot {
    margin-top: 18px;
    text-align: center;
    font-size: 0.88rem;
    color: var(--text-muted);
}
.auth-foot a {
    color: var(--primary);
    font-weight: 700;
    text-decoration: none;
    margin-left: 4px;
}
.auth-foot a:hover { text-decoration: underline; }
.auth-back { font-weight: 600; }
.auth-optional { color: var(--text-light); font-weight: 500; font-size: 0.82rem; }

/* --- Cards --- */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
}

.card-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--primary-dark);
}

/* --- Bus List Item --- */
.bus-item {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
    border: 2px solid transparent;
    transition: transform .2s, box-shadow .2s, border-color .2s;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.bus-item:active { transform: scale(0.98); }

.bus-item.selected {
    border-color: var(--primary);
    background: var(--primary-xlight);
    box-shadow: 0 0 0 4px rgba(29,78,216,0.12);
}

.bus-header { display:flex; justify-content:space-between; align-items:flex-start; margin-bottom:8px; }

.bus-time { font-size:1.5rem; font-weight:800; color:var(--primary); }

.bus-label {
    background: var(--primary-light);
    color: var(--primary-dark);
    padding: 4px 10px;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.bus-route { font-size:0.9rem; color:var(--text-muted); margin-bottom:12px; display:flex; align-items:center; }

.bus-footer {
    display:flex; justify-content:space-between; align-items:center;
    border-top:1px solid var(--border-light); padding-top:12px; margin-top:8px;
}

.seats-badge { font-size:.85rem; font-weight:600; }
.seats-badge.low { color: var(--danger); }
.seats-badge.ok  { color: var(--success); }

/* --- Seat Progress Bar --- */
.seat-progress-section {
    margin: 12px 0; padding: 12px 0;
    border-top: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
}

.seat-progress-bar {
    font-size:1.4rem; letter-spacing:2px;
    margin-bottom:8px; color:var(--primary);
    font-weight:600; text-align:left; word-break:break-all;
}

.seat-progress-info { display:flex; justify-content:space-between; align-items:center; font-size:.85rem; }
.seat-count { color:var(--text-main); font-weight:600; }

.seat-status {
    font-weight:700; padding:4px 10px; border-radius:99px;
    font-size:.75rem; text-transform:uppercase; letter-spacing:.5px;
}
.seat-status.full { background: var(--danger-light); color: var(--danger); }
.seat-status.available { background: var(--success-light); color: var(--success); }
.seat-status.almost { background: var(--warning-light); color: var(--warning); padding:3px 8px; border-radius:99px; font-weight:700; font-size:.72rem; }

.price-tag { font-weight:700; color:var(--text-main); }

/* --- Forms --- */
.form-group { margin-bottom:16px; }

label { display:block; margin-bottom:6px; font-size:.9rem; font-weight:500; color:var(--text-muted); }

input[type="text"],
input[type="tel"],
input[type="number"],
input[type="password"],
input[type="email"],
select,
textarea,
input[type="time"] {
    width:100%; padding:12px 16px;
    border:1px solid var(--border); border-radius: var(--radius-sm);
    font-size:1rem; transition:all .2s; background: var(--bg-card);
    color: var(--text-main);
    font-family: var(--font);
}

input:focus, select:focus, textarea:focus {
    outline:none;
    border-color: var(--primary);
    background: var(--bg-card);
    box-shadow: 0 0 0 3px rgba(29,78,216,0.15);
}

input[readonly] { background: var(--bg-subtle); color: var(--text-muted); }

/* --- Buttons --- */
.btn {
    display:inline-flex; justify-content:center; align-items:center;
    width:100%; padding:12px 24px; border:none; border-radius: var(--radius-sm);
    font-size:1rem; font-weight:600; cursor:pointer; transition:all .2s;
    text-decoration:none; gap:8px;
    font-family: var(--font);
}

.btn-primary {
    background: var(--primary);
    color: var(--text-on-primary);
    border: none;
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover  { background: var(--primary-dark); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { background: var(--text-light); cursor:not-allowed; box-shadow:none; }

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--primary);
    padding: 12px 24px;
    border-radius: var(--radius-sm);
}
.btn-secondary:hover { background: var(--primary-xlight); }

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--primary);
}
.btn-outline:hover { background: var(--primary-xlight); }

.btn-x { background:#000; color:#fff; margin-top:12px; }

.btn-whatsapp {
    background:#25D366;
    color:#fff;
    margin-top:10px;
}
.btn-whatsapp:hover { background:#1ebe57; }

/* --- Bottom Navigation --- */
.bottom-nav {
    position:fixed; bottom:0; left:0; width:100%;
    background: var(--bg-card);
    border-top:1px solid var(--border);
    display:flex; justify-content:space-around;
    padding:8px 0 max(8px, env(safe-area-inset-bottom));
    z-index:100;
}

.nav-item {
    text-decoration:none;
    color: var(--text-muted);
    font-size:.72rem;
    font-weight:600;
    display:flex; flex-direction:column; align-items:center; gap:3px;
    flex:1;
    transition: color .2s;
}

.nav-item.active { color: var(--primary); }

.nav-icon-wrap {
    width:46px; height:32px;
    border-radius:99px;
    display:flex; align-items:center; justify-content:center;
    transition: background .2s;
}

.nav-item.active .nav-icon-wrap { background: var(--primary-light); }

/* --- Attendant & Admin --- */
.attendant-header { background: var(--primary); color: var(--text-on-primary); }

.passenger-row {
    display:flex; justify-content:space-between; align-items:center;
    padding:16px 0; border-bottom:1px solid var(--border-light);
}

img[src="logo.png"] {
    width:48px; height:48px; padding:8px;
    background:rgba(255,255,255,0.15); border-radius:50%;
}

.check-btn {
    width:44px; height:44px; border-radius:50%;
    border:1px solid var(--border);
    display:flex; align-items:center; justify-content:center;
    background:transparent; cursor:pointer; font-size:1.2rem;
    color: var(--text-light); transition:all .2s;
}
.check-btn.checked { background: var(--success); border-color: var(--success); color: var(--text-on-primary); }

/* --- Ticket lookup tabs --- */
.lookup-tabs {
    display:flex; gap:0; border-radius: var(--radius-sm); overflow:hidden;
    border:1px solid var(--border); margin-bottom:16px;
}
.lookup-tab {
    flex:1; padding:10px; background:transparent;
    border:none; font-size:.875rem; font-weight:600;
    cursor:pointer; color: var(--text-muted);
    transition:all .2s;
}
.lookup-tab.active { background: var(--primary); color: var(--text-on-primary); }

/* --- My bookings card (logged-in users) --- */
.my-booking-card { border-left: 4px solid var(--primary); }
.my-booking-head { display:flex; justify-content:space-between; align-items:flex-start; }
.my-booking-code { font-family: monospace; font-weight:800; font-size:1.05rem; color: var(--primary); }
.my-booking-meta { font-size: .85rem; color: var(--text-muted); margin-top: 4px; }
.my-booking-row { display:flex; justify-content:space-between; gap:12px; }

/* --- Badges --- */
.badge {
    display:inline-block;
    font-size:.72rem; font-weight:700;
    padding:4px 10px; border-radius:99px;
    text-transform:uppercase; letter-spacing:.04em;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger  { background: var(--danger-light);  color: var(--danger); }
.badge-info    { background: var(--primary-light); color: var(--primary-dark); }
.badge-warning { background: var(--warning-light); color: var(--warning); }

/* --- Utilities --- */
.text-center { text-align:center; }
.mt-4 { margin-top:16px; }
.mb-2 { margin-bottom:8px; }
.hidden { display:none; }

/* --- PWA Install Banner --- */
.pwa-install {
    background: var(--bg-card); padding:16px; border-radius:var(--radius);
    box-shadow: var(--shadow-md); margin-bottom:20px;
    display:none; text-align:center; border:1px solid var(--border-light);
}

/* --- Alerts --- */
.alert { padding:12px 16px; border-radius: var(--radius-sm); margin-bottom:16px; font-size:.9rem; }
.alert-error   { background: var(--danger-light);  color: var(--danger); }
.alert-success { background: var(--success-light); color: var(--success); }
.alert-info    { background: var(--primary-light); color: var(--primary-dark); }

/* --- Animations --- */
@keyframes fadeIn { from{opacity:0;transform:translateY(10px)} to{opacity:1;transform:translateY(0)} }
.fade-in { animation:fadeIn .3s ease-out forwards; }

/* Share section */
.share-btns { display:flex; flex-direction:column; gap:10px; }

/* --- Staff drawer --- */
.staff-drawer {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-light);
    overflow: hidden;
    max-height: 0;
    transition: max-height .25s ease, box-shadow .25s;
}
.staff-drawer.open {
    max-height: 220px;
    box-shadow: var(--shadow-sm);
}
.staff-drawer-inner {
    padding: 12px 16px 14px;
    max-width: 600px;
    margin: 0 auto;
}
.staff-drawer-label {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
    margin-bottom: 10px;
}
.staff-drawer-links {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.staff-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--primary-light);
    color: var(--primary-dark);
    border-radius: var(--radius-sm);
    font-size: .85rem;
    font-weight: 600;
    text-decoration: none;
    transition: background .15s;
}
.staff-link:hover { background: #c7dafb; }

/* --- Route tabs (index) --- */
.route-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
}
.route-tabs::-webkit-scrollbar { display: none; }
.route-tab {
    white-space: nowrap;
    padding: 7px 14px;
    border-radius: 99px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    font-size: .82rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all .15s;
}
.route-tab.active { background: var(--primary); color: var(--text-on-primary); border-color: var(--primary); }
.route-tab-count {
    background: rgba(255,255,255,.25);
    border-radius: 99px;
    padding: 0 6px;
    font-size: .72rem;
}
.route-tab:not(.active) .route-tab-count { background: var(--primary-light); color: var(--primary); }

/* --- Improved bus card internals --- */
.bus-route-inline {
    display: flex;
    align-items: center;
    font-size: .82rem;
    color: var(--text-muted);
    margin-top: 2px;
    font-weight: 500;
}

.cap-bar-wrap { margin: 12px 0; }
.cap-bar {
    height: 6px;
    background: var(--bg-subtle);
    border-radius: 99px;
    overflow: hidden;
    margin-bottom: 6px;
}
.cap-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 99px;
    transition: width .3s;
}
.cap-bar-fill.warn   { background: var(--warning); }
.cap-bar-fill.danger { background: var(--danger); }
.cap-bar-info {
    display: flex;
    justify-content: space-between;
    font-size: .78rem;
    color: var(--text-muted);
}

.book-cta { font-size:.8rem; color: var(--primary); font-weight:600; }

/* Selected bus banner */
.selected-bus-banner {
    background: var(--primary-light);
    color: var(--primary-dark);
    font-size: .82rem;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.selected-bus-banner:empty { display: none; }

/* Pay notice */
.pay-notice {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    background: var(--success-light);
    color: var(--success);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-size: .85rem;
    font-weight: 500;
    margin-bottom: 14px;
    line-height: 1.4;
}
.pay-notice svg { flex-shrink:0; margin-top:1px; }

/* --- Admin status pills --- */
.status-pill {
    padding: 3px 10px; border-radius: 99px;
    font-size: .72rem; font-weight: 700; text-transform: uppercase;
    white-space: nowrap;
}
.status-open     { background: var(--success-light); color: var(--success); }
.status-departed { background: var(--warning-light); color: var(--warning); }
.status-closed   { background: var(--danger-light);  color: var(--danger); }
.status-cancelled{ background: var(--bg-subtle);     color: var(--text-muted); }
