/* ── GLOBAL RESETS & VARIABLES ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    /* Page 1 Variables */
    --p1-red: #B3261E;
    --p1-red-dark: #8C1D18;
    --p1-red-light: #C94040;
    --p1-teal: #00897B;
    --p1-bg: #EDEDED;
    --p1-card: #F3F3F3;
    --p1-input: #E4E4E4;
    --p1-txt: #111;
    --p1-sub: #6D6D6D;
    --p1-border: #CECECE;
    --p1-shadow: rgba(0,0,0,0.09);
    
    /* Page 2 & 3 Variables */
    --p2-red: #bb1919;
    --p2-text-main: #222222;
    --p2-text-muted: #666666;
    --p2-card-bg: #f2f2f2;
    --p2-divider: #cccccc;
}

html, body {
    height: 100%; width: 100%;
    overflow: hidden;
    background: #222;
    display: flex;
    justify-content: center;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
}

/* ── APP SHELL & NAVIGATION ── */
.shell {
    width: 100%;
    max-width: 390px;
    height: 100vh;
    height: 100dvh;
    max-height: 844px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--p1-red);
    position: relative;
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
}

.page {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(20px) scale(0.98);
    filter: blur(4px);
    transition: 
        opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1),
        filter 0.4s ease,
        visibility 0.4s;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1;
}
.page.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
    filter: blur(0);
    z-index: 2;
}

/* =========================================
   PAGE 1: BUY TICKETS
   ========================================= */
#page1 {
    font-family: 'Noto Sans', sans-serif;
    background: var(--p1-red);
}

#page1 header {
    flex-shrink: 0;
    height: 52px;
    display: flex;
    align-items: center;
    padding: 0 14px;
    position: relative;
}
#page1 .back-btn {
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none; cursor: pointer;
    color: #fff; border-radius: 50%;
    transition: background 150ms;
    position: relative; z-index: 1;
}
#page1 .back-btn:hover { background: rgba(255,255,255,0.13); }
#page1 header h1 {
    position: absolute; left: 0; right: 0;
    text-align: center;
    font-size: 19px; font-weight: 500;
    color: #fff; letter-spacing: 0.1px;
    pointer-events: none;
}
#page1 .header-action-btn {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none; cursor: pointer;
    border-radius: 50%;
    transition: background 150ms;
}
#page1 .header-action-btn:hover { background: rgba(255,255,255,0.13); }
#page1 .header-action-btn:active { transform: translateY(-50%) scale(0.9); }

#page1 .badge {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 9px;
    height: 9px;
    background: #FFEB3B; /* Bright yellow dot */
    border: 1.5px solid var(--p1-red);
    border-radius: 50%;
    transition: opacity 300ms, transform 300ms;
}
#page1 .badge.empty { opacity: 0; transform: scale(0); }

#page1 .badge::after {
    content: '';
    position: absolute;
    top: -1.5px; left: -1.5px; bottom: -1.5px; right: -1.5px;
    border-radius: 50%;
    background: inherit;
    opacity: 0.4;
    animation: badge-pulse 1.8s infinite;
}

@keyframes badge-pulse {
    0% { transform: scale(1); opacity: 0.6; }
    100% { transform: scale(2.4); opacity: 0; }
}
#page1 .body {
    flex: 1; 
    display: flex; 
    flex-direction: column;
    overflow: hidden; 
    padding: 12px 14px 0;
}
#page1 .card {
    background: var(--p1-card); border-radius: 16px;
    padding: 14px 14px 14px; box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    flex-shrink: 0;
}
#page1 .card-title {
    font-size: 15px; font-weight: 600;
    color: var(--p1-txt); margin-bottom: 10px;
}
#page1 .irow {
    background: var(--p1-input); border-radius: 10px;
    height: 46px; display: flex; align-items: center;
    padding: 0 12px; gap: 10px; position: relative;
    transition: box-shadow 180ms, background 180ms;
}
#page1 .irow:focus-within { 
    box-shadow: 0 0 0 2px var(--p1-teal); 
    background: #f0f0f0;
}
#page1 .accent {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    width: 2.5px; height: 42%; background: var(--p1-teal); border-radius: 2px;
}
#page1 .irow.accented { padding-left: 22px; }
#page1 .irow.accented .ico { margin-left: 4px; }
#page1 .irow input {
    flex: 1; background: none; border: none; outline: none;
    font-family: 'Noto Sans', sans-serif;
    font-size: 14px; color: var(--p1-txt);
}
#page1 .irow input::placeholder { color: var(--p1-sub); }
#page1 .ico {
    flex-shrink: 0; color: var(--p1-txt);
    display: flex; align-items: center;
}
#page1 .lbl {
    font-size: 13px; font-weight: 500; color: var(--p1-txt);
    margin: 9px 0 7px;
}
#page1 .pair { 
    display: flex; flex-direction: column; gap: 7px;
    position: relative;
}

/* Swap Button */
.swap-btn {
    width: 32px; height: 32px;
    border-radius: 50%;
    border: 1.5px solid var(--p1-border);
    background: white;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    align-self: center;
    color: var(--p1-sub);
    transition: background 200ms, color 200ms, transform 200ms, box-shadow 200ms;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin: -2px 0;
    flex-shrink: 0;
}
.swap-btn:hover { 
    background: var(--p1-red); color: #fff; 
    border-color: var(--p1-red);
    box-shadow: 0 2px 8px rgba(179,38,30,0.25);
}
.swap-btn:active { transform: rotate(180deg) scale(0.9); }

#page1 .bus-row { display: flex; gap: 8px; }
#page1 .bus-btn {
    height: 36px; padding: 0 16px; border-radius: 9px;
    border: 1.5px solid transparent; font-family: 'Noto Sans', sans-serif;
    font-size: 13px; font-weight: 500; cursor: pointer;
    transition: background 150ms, color 150ms, border-color 150ms, transform 80ms;
    display: flex; align-items: center; gap: 6px;
}
#page1 .bus-btn.active { background: var(--p1-red); color: #fff; border-color: var(--p1-red); }
#page1 .bus-btn.inactive { background: #F0F0F0; color: var(--p1-txt); border-color: var(--p1-border); }
#page1 .bus-btn:active { transform: scale(0.96); }
#page1 .panel {
    background: #FFFFFF;
    margin: auto -14px 0;
    padding: 12px 20px 18px;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 15px rgba(0,0,0,0.04);
    display: flex;
    flex-direction: column;
}
#page1 .qty-lbl {
    font-size: 14px;
    font-weight: 500;
    color: #111;
    margin-bottom: 8px;
}
#page1 .qty-row { display: flex; gap: 10px; }
#page1 .qty-btn {
    width: 54px;
    height: 44px;
    border-radius: 10px;
    border: 1px solid #E0E0E0;
    background: #FFFFFF;
    font-family: 'Noto Sans', sans-serif;
    font-size: 18px;
    font-weight: 500;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 150ms ease;
    color: #333;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
#page1 .qty-btn.active {
    background: #C6372C;
    color: #fff;
    border-color: #C6372C;
    box-shadow: 0 3px 6px rgba(198,55,44,0.25);
}
#page1 .qty-btn:active { transform: scale(0.96); }

/* Amount Card */
#page1 .amt-card {
    margin-top: 14px;
    background: transparent;
    padding: 0;
}
#page1 .amt-card.empty { 
    opacity: 0; transform: translateY(8px); height: 0; margin-top: 0; overflow: hidden;
}
#page1 .amt-row {
    display: flex; align-items: center; justify-content: space-between;
}
#page1 .amt-lbl {
    font-size: 15px; font-weight: 500; color: #111;
}
#page1 .price-container {
    display: flex; align-items: baseline; gap: 10px;
}
#page1 .amt-val {
    font-size: 28px; font-weight: 600; color: #C6372C; line-height: 1;
}
#page1 .amt-val.empty { opacity: 0; }

#page1 .amt-original {
    font-size: 24px; font-weight: 400; color: #111; text-decoration: line-through; opacity: 0.8;
}
#page1 .amt-original.empty { opacity: 0; }

.discount-badge {
    background: #00B359; color: white; font-size: 14px; font-weight: 500;
    padding: 6px 12px; border-radius: 6px;
}
.discount-badge.empty { opacity: 0; }

#page1 .buy-wrap { margin-top: 16px; }
#page1 .buy-btn {
    width: 100%; height: 48px; background: #C6372C; color: #fff; border: none;
    border-radius: 4px; font-family: 'Noto Sans', sans-serif; font-size: 16px; font-weight: 700;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15); transition: all 150ms ease; letter-spacing: 0.5px;
}
#page1 .buy-btn:hover { background: #B02F25; }
#page1 .buy-btn:active { transform: scale(0.98); }
#page1 .buy-btn:disabled { background: #E0E0E0; color: #909090; box-shadow: none; }

@keyframes p1-pop { from { opacity: 0; transform: scale(0.90); } to { opacity: 1; transform: scale(1); } }
#page1 .qty-btn.active, #page1 .bus-btn.active { animation: p1-pop 160ms ease; }


/* =========================================
   PAGE 2 & 3: COMMON HEADER & TICKETS
   ========================================= */
#page2, #page3 {
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--p2-red);
    color: white;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}
#page3 {
    user-select: none;
}

/* Unified Header for Page 2 and Page 3 */
#page2 .header, #page3 .header {
    display: flex; justify-content: space-between; align-items: center; padding: 12px 16px;
}
#page2 .close-btn, #page3 .close-btn {
    background: none; border: none; color: white; cursor: pointer;
    display: flex; align-items: center; padding: 5px;
}
#page2 .all-tickets, #page3 .all-tickets {
    display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 500; cursor: pointer;
}

#page2 .content, #page3 .content {
    flex: 1; padding: 0 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; margin-top: 1rem;
}

#page2 .ticket-card {
    background-color: var(--p2-card-bg); width: 100%; border-radius: 5px; padding: 20px;
    color: var(--p2-text-main); box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); margin-top: 15px;
    animation: p2-fadeIn 0.3s ease-out;
}
#page2 .dept-title {
    text-align: center; font-size: 17px; font-weight: 500; color: #000000; margin-bottom: 20px;
}
#page2 .status-row {
    display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px;
}
#page2 .validated-tag {
    font-size: 18px; color: var(--p2-text-muted); letter-spacing: 0.5px;
}
#page2 .total-amount {
    font-size: 19px; font-weight: 500;
}
#page2 .divider {
    height: 1px; background-color: var(--p2-divider); margin: 12px 0 20px 0; border: none;
}
#page2 .info-grid {
    display: grid; grid-template-columns: auto auto; justify-content: space-between; gap: 15px 0;
}
#page2 .info-group label {
    display: block; font-size: 13px; color: var(--p2-text-muted); margin-bottom: 4px;
}
#page2 .info-group .val {
    font-size: 15px; font-weight: 500; white-space: nowrap; 
}
#page2 .info-group .val.big {
    font-size: 19px; font-weight: 600;
}
#page2 .text-right { text-align: right; }
#page2 .full-width { grid-column: span 2; }
#page2 .tid {
    text-align: center; font-size: 13px; color: var(--p2-text-muted); margin: 25px 0 15px 0;
    font-family: monospace; letter-spacing: 0.5px;
}
#page2 .qr-button {
    width: 100%; background-color: var(--p2-red); color: white; border: none; border-radius: 4px;
    padding: 14px; font-size: 17px; font-weight: 500; display: flex; align-items: center; justify-content: center;
    gap: 10px; cursor: pointer; transition: transform 0.1s;
}

/* Shared Footer and Timestamp elements (Exact copy of original Page 2) */
#page2 .timestamp-bar, #page3 .timestamp-bar {
    margin-top: 1.5rem; background-color: var(--p2-card-bg); width: 88%; padding: 12px;
    border-radius: 8px; text-align: center; font-size: 14px; font-weight: 500; color: var(--p2-red);
}
#page2 .footer, #page3 .footer {
    padding: 15px 16px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px;
}
#page2 .branding-logo, #page3 .branding-logo {
    height: 16px; width: auto; max-width: 180px; object-fit: contain;
}
#page2 .iiit-credit, #page3 .iiit-credit {
    font-size: 10px; opacity: 0.7; margin-top: 5px;
}
@keyframes p2-fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }


/* =========================================
   PAGE 3: SPECIFIC STYLES
   ========================================= */
#page3 .ticket-card {
    background: white; width: 100%; max-width: 345px; aspect-ratio: 1 / 1; border-radius: 10px;
    padding: 22px; display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    margin-top: 15px; 
}
#page3 .ticket-card img {
    width: 100%; height: 100%; object-fit: contain;
}
#page3 .fade-in { animation: p3-fadeIn 0.4s ease-out forwards; }
@keyframes p3-fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* =========================================
   PAGE 4: TICKET HISTORY
   ========================================= */
#page4 {
    font-family: 'Inter', -apple-system, sans-serif;
    background: #f5f5f5;
    -webkit-font-smoothing: antialiased;
}

.p4-header {
    flex-shrink: 0;
    height: 56px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    background: var(--p1-red);
    color: white;
}
.p4-back-btn {
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none; cursor: pointer;
    color: white; border-radius: 50%;
    transition: background 150ms;
}
.p4-back-btn:hover { background: rgba(255,255,255,0.13); }
.p4-title {
    flex: 1;
    text-align: center;
    font-size: 18px; font-weight: 600;
    letter-spacing: 0.2px;
}
.p4-clear-btn {
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none; cursor: pointer;
    color: rgba(255,255,255,0.8); border-radius: 50%;
    transition: background 150ms, color 150ms;
}
.p4-clear-btn:hover { background: rgba(255,255,255,0.13); color: white; }

.p4-count-bar {
    flex-shrink: 0;
    padding: 10px 18px;
    background: var(--p1-red);
    color: rgba(255,255,255,0.75);
    font-size: 13px;
    font-weight: 500;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.p4-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 14px 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Empty State */
.p4-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 40px 20px;
    text-align: center;
}
.p4-empty .material-symbols-outlined {
    font-size: 64px;
    color: #ccc;
    margin-bottom: 16px;
}
.p4-empty-title {
    font-size: 17px;
    font-weight: 600;
    color: #555;
    margin-bottom: 6px;
}
.p4-empty-sub {
    font-size: 13px;
    color: #999;
    line-height: 1.4;
}

/* Ticket History Card */
.history-item {
    background: white;
    border-radius: 14px;
    padding: 0;
    color: #222;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    flex-shrink: 0;
    overflow: hidden;
    animation: histSlideIn 0.35s ease both;
}
.history-item:active {
    transform: scale(0.975);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.hist-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 10px;
}
.hist-route-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--p1-red);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.3px;
}
.hist-route-badge .material-symbols-outlined {
    font-size: 16px;
}
.hist-amount {
    font-size: 18px;
    font-weight: 700;
    color: #222;
}

.hist-mid {
    padding: 0 16px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.hist-stops-line {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
    padding: 2px 0;
}
.hist-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    border: 2px solid var(--p1-red);
    background: white;
}
.hist-line {
    width: 2px;
    height: 20px;
    background: #ddd;
}
.hist-dot.end {
    background: var(--p1-red);
}
.hist-stops-text {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}
.hist-stop-name {
    font-size: 14px;
    font-weight: 500;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hist-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: #fafafa;
    border-top: 1px solid #f0f0f0;
}
.hist-time {
    font-size: 12px;
    color: #888;
    display: flex;
    align-items: center;
    gap: 4px;
}
.hist-time .material-symbols-outlined {
    font-size: 14px;
}
.hist-qty {
    font-size: 12px;
    color: #888;
    display: flex;
    align-items: center;
    gap: 4px;
}
.hist-qty .material-symbols-outlined {
    font-size: 14px;
}
.hist-arrow {
    color: #ccc;
    display: flex;
    align-items: center;
}
.hist-arrow .material-symbols-outlined {
    font-size: 18px;
}

@keyframes histSlideIn {
    from { 
        opacity: 0; 
        transform: translateY(30px) scale(0.9); 
        filter: blur(4px);
    }
    to { 
        opacity: 1; 
        transform: translateY(0) scale(1); 
        filter: blur(0);
    }
}

/* Ensure mobile keyboard doesn't break layout */
@media (max-height: 600px) {
    #page1 .body { overflow-y: auto !important; }
    #page1 .amt-card { margin-bottom: 20px; }
    #page1 .amt-card.empty { height: 0; margin-top: 0; padding: 0; border: none; }
}

/* Loading Spinner */
.spinner {
    width: 30px; height: 30px;
    border: 3.5px solid #ddd;
    border-top: 3.5px solid var(--p1-red);
    border-radius: 50%;
    margin: 0 auto 12px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* =========================================
   PAGE 0: AUTHENTICATION (Modern UI/UX)
   ========================================= */
#page0 {
    background: linear-gradient(135deg, #B3261E 0%, #8C1D18 100%);
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    padding: 20px;
}

#page0 .auth-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    width: 100%;
    max-width: 350px;
    padding: 36px 28px;
    border-radius: 30px;
    box-shadow: 0 25px 50px rgba(0,0,0,0.25);
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.3);
    animation: p3-fadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.auth-logo {
    width: 72px;
    height: 72px;
    margin-bottom: 20px;
    border-radius: 18px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.1);
}

#auth-title {
    font-size: 24px;
    font-weight: 700;
    color: #111;
    margin-bottom: 6px;
}

#auth-subtitle {
    font-size: 14px;
    color: #666;
    margin-bottom: 30px;
}

.auth-form .irow {
    background: rgba(0, 0, 0, 0.04);
    border: 1.5px solid transparent;
    border-radius: 16px;
    height: 52px;
    margin-bottom: 14px;
    transition: all 0.3s ease;
}

.auth-form .irow:focus-within {
    background: white;
    border-color: #B3261E;
    box-shadow: 0 5px 15px rgba(179, 38, 30, 0.1);
}

.auth-submit-btn {
    width: 100%;
    height: 52px;
    background: #B3261E;
    color: white;
    border: none;
    border-radius: 16px;
    font-size: 16px;
    font-weight: 700;
    margin-top: 20px;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(179, 38, 30, 0.25);
    transition: all 0.3s ease;
}

.auth-submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 25px rgba(179, 38, 30, 0.35);
}

.auth-divider {
    display: flex;
    align-items: center;
    margin: 20px 0;
    color: #999;
    font-size: 12px;
    font-weight: 600;
}

.auth-divider::before, .auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: #eee;
}

.auth-divider span {
    margin: 0 12px;
}


.google-btn {
    width: 100%;
    height: 52px;
    background: white;
    border: 1.5px solid #eee;
    border-radius: 16px;
    color: #333;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    z-index: 10;
}

.google-btn img {
    width: 18px;
    height: 18px;
}

.google-btn:hover {
    background: #f9f9f9;
    border-color: #ddd;
}

.auth-toggle {
    margin-top: 24px;
    font-size: 14px;
    color: #555;
}

.auth-toggle a {
    color: #B3261E;
    font-weight: 700;
    text-decoration: none;
}

.auth-error-msg {
    margin-top: 16px;
    font-size: 13px;
    color: #d32f2f;
    min-height: 20px;
    font-weight: 500;
}

.auth-form .irow .ico {
    color: #888;
    margin-right: 12px;
}

.auth-form .irow:focus-within .ico {
    color: #B3261E;
}

.auth-form .irow input {
    background: transparent;
    border: none;
    outline: none;
    width: 100%;
    font-size: 15px;
    font-weight: 500;
    color: #111;
}

.auth-form .irow input::placeholder {
    color: #aaa;
}
