/* LIGHT MODE (Default) */
:root, [data-theme="light"] { 
    --bg-color: #F4F7FC; 
    --surface-color: #FFFFFF;
    --text-primary: #1D1B20;
    --text-secondary: #444746;
    --border-color: #E1E3E1;
    --primary-blue: #0b57d0; 
    --progress-bg: #E1E3E1;
    --tube-red: #E32017;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.1);
    --icon-color: #444746;
}

/* DARK MODE */
[data-theme="dark"] {
    --bg-color: #121212; 
    --surface-color: #1E1E1E;
    --text-primary: #E3E3E3;
    --text-secondary: #A0A0A0;
    --border-color: #333333;
    --primary-blue: #A8C7FA; 
    --progress-bg: #333333;
    --tube-red: #E32017;
    --card-shadow: 0 4px 6px rgba(0,0,0,0.3);
    --icon-color: #E3E3E3;
}

body { 
    font-family: 'Roboto', sans-serif; 
    background-color: var(--bg-color); 
    color: var(--text-primary); 
    margin: 0; 
    padding: 0; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* STICKY TOP APP BAR */
.top-app-bar {
    width: 100%;
    background-color: var(--surface-color);
    padding: 12px 20px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.top-app-bar h1 { 
    margin: 0; 
    font-size: 1.4rem; 
    font-weight: 700; 
    color: var(--text-primary); 
    letter-spacing: -0.5px;
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    fill: var(--icon-color);
    transition: background-color 0.2s;
}
.icon-btn:hover { background-color: rgba(111, 111, 111, 0.1); }

/* MAIN CONTENT CONTAINER */
.main-content {
    width: 100%;
    max-width: 600px;
    /* Perfect Desktop Clearance: Clears the 80px search bar height plus a crisp 20px gap */
    padding: 24px 16px 100px 16px;
    box-sizing: border-box;
}

/* Mobile responsive override */
@media (max-width: 600px) {
    .main-content {
        /* Mobile handles shifting system UI bars and gestures */
        padding-bottom: calc(120px + env(safe-area-inset-bottom));
    }
}

h2 { text-align: center; font-weight: 500; font-size: 1.5rem; margin-top: 0; margin-bottom: 24px; color: var(--text-primary); }
#status-message { text-align: center; color: var(--text-secondary); margin-bottom: 24px; font-weight: 500; font-size: 0.95rem; min-height: 20px; }

.md-card {
    background: var(--surface-color); 
    padding: 24px; 
    border-radius: 24px; 
    box-shadow: var(--card-shadow); 
    margin-bottom: 16px;
    border: 1px solid var(--border-color);
    transition: box-shadow 0.2s ease, transform 0.2s ease, background-color 0.3s ease, border-color 0.3s ease;
}

/* ==========================================
   OFFLINE-FIRST MATERIAL 3 SEARCH BAR
   ========================================== */
#search-container { 
    position: fixed; 
    bottom: 24px; 
    left: 50%; 
    transform: translateX(-50%); 
    width: 92%; 
    max-width: 560px; 
    z-index: 1000; 
    background: var(--surface-color); 
    border-radius: 28px; /* M3 Pill Shape */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-color);
    box-sizing: border-box;
    overflow: hidden;
    transition: all 0.2s ease;
}

.search-bar-inner {
    display: flex;
    align-items: center;
    height: 56px; /* Strict Material 3 component tracking specification */
    padding: 0 8px 0 16px;
    box-sizing: border-box;
}

.search-lead-icon {
    color: var(--text-secondary);
    margin-right: 12px;
    flex-shrink: 0;
    display: block;
}

#searchInput { 
    flex: 1; 
    height: 36px; /* Explicit core row boundary */
    line-height: 36px; /* Matches height to eliminate browser input sagging */
    padding: 0; 
    margin: 0;
    border: none;
    background: transparent; 
    color: var(--text-primary); 
    font-size: 1rem;
    font-family: inherit;
    display: block;
    box-sizing: border-box;
}
#searchInput:focus {
    outline: none;
}

.search-clear-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    flex-shrink: 0;
    transition: background-color 0.2s;
}
.search-clear-btn:hover {
    background-color: rgba(111, 111, 111, 0.1);
}

/* Search results list styling */
#search-results { 
    max-height: 280px; 
    overflow-y: auto; 
    padding: 0 8px 0 8px;
    box-sizing: border-box;
}
#search-results:not(:empty) {
    border-top: 1px solid var(--border-color);
    margin-top: 4px;
    padding-top: 8px;
}
#search-results .search-item { 
    display: flex; 
    align-items: center; 
    height: 48px; 
    padding: 0 12px; 
    gap: 16px; 
    border-radius: 16px;
    cursor: pointer;
    box-sizing: border-box;
}
#search-results .search-item:hover { 
    background-color: rgba(111, 111, 111, 0.08); 
}
#search-results .search-item span { 
    flex: 1; 
    font-size: 0.95rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#search-results .search-item input[type="checkbox"] { 
    margin: 0; 
    width: 20px; 
    height: 20px; 
    accent-color: var(--primary-blue);
    flex-shrink: 0;
    cursor: pointer;
}

/* AUTH VIEW */
#auth-view { display: none; flex-direction: column; gap: 16px; margin-top: 48px; }
#auth-view.active-view { display: flex !important; } 
#auth-view h3 { margin-top: 0; text-align: center; font-weight: 500; font-size: 1.5rem; margin-bottom: 4px; color: var(--text-primary); }
#auth-view p { text-align: center; color: var(--text-secondary); font-size: 0.9rem; margin-top: 0; margin-bottom: 12px; }

.md-input-container input { 
    padding: 16px 20px; 
    border: 1px solid var(--border-color); 
    border-radius: 14px; 
    font-size: 1rem; 
    font-family: inherit;
    background: var(--bg-color);
    color: var(--text-primary);
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.15s, background-color 0.3s ease;
}
.md-input-container input:focus { outline: none; border: 2px solid var(--primary-blue); }

.md-button {
    padding: 12px 24px; 
    border: none; 
    border-radius: 100px; 
    cursor: pointer; 
    font-weight: 500; 
    font-size: 0.95rem;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 48px;
    transition: background-color 0.2s, transform 0.1s;
}
.md-button:active { transform: scale(0.98); }

.auth-buttons { display: flex; gap: 12px; margin-top: 8px; }
.auth-buttons button { flex: 1; }
.btn-login { background-color: var(--primary-blue); color: white; }
.btn-signup { background-color: transparent; color: var(--primary-blue); border: 1px solid var(--primary-blue); }

.btn-google { background-color: var(--bg-color); color: var(--text-primary); border: 1px solid var(--border-color); width: 100%; }

.btn-logout { 
    background-color: transparent; 
    color: var(--tube-red); 
    height: 36px;
    padding: 0 16px;
    border: 1px solid var(--tube-red);
    font-size: 0.85rem;
}

.back-btn { background-color: var(--border-color); color: var(--text-primary); margin-bottom: 24px; height: 44px; }

/* APP VIEWS */
#app-views, #home-view, #line-view { display: none; }
.active-view { display: block !important; }

/* GLOBAL PROGRESS CARD */
.global-card {
    background: linear-gradient(135deg, var(--primary-blue), #6950a1);
    color: white;
    border: none;
    padding: 24px;
}
.global-card .line-header span:first-child,
.global-card .line-header span:last-child {
    color: white;
}
.global-card .progress-container {
    background-color: rgba(255, 255, 255, 0.2);
}
.global-card .progress-bar {
    background-color: white;
}
.global-card .stats-text {
    color: rgba(255, 255, 255, 0.9);
}

/* LINE CARDS */
.line-card { 
    cursor: pointer; 
    border-left: 10px solid var(--line-color); 
    padding: 18px 20px;
}
.line-card:hover { transform: translateY(-2px); box-shadow: 0 6px 12px rgba(0,0,0,0.1); }

.line-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.line-header span:first-child { font-weight: 700; font-size: 1.15rem; color: var(--text-primary); }
.line-header span:last-child { font-weight: 700; font-size: 1.1rem; color: var(--text-secondary); }

.progress-container { background-color: var(--progress-bg); border-radius: 100px; height: 10px; width: 100%; overflow: hidden; }
.progress-bar { height: 100%; background-color: var(--line-color); transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1); border-radius: 100px; }

.stats-text { font-size: 0.85rem; color: var(--text-secondary); margin-top: 10px; text-align: right; font-weight: 500;}

/* STATION LIST */
.station-item { 
    background: var(--surface-color); 
    padding: 16px 20px; 
    margin-bottom: 8px; 
    border-radius: 16px; 
    display: flex; 
    align-items: center; 
    cursor: pointer; 
    border: 1px solid var(--border-color);
    transition: background-color 0.2s ease;
}
.station-item:hover { background-color: var(--bg-color); }

.station-item input[type="checkbox"] { margin-right: 16px; width: 22px; height: 22px; pointer-events: none; accent-color: var(--primary-blue); }

.station-item span { font-size: 1rem; flex: 1; color: var(--text-primary); }
.completed-text { text-decoration: line-through; color: var(--text-secondary) !important; }

.divider-container { display: flex; align-items: center; text-align: center; margin: 12px 0; color: var(--text-secondary); font-size: 0.85rem; }
.divider-container::before, .divider-container::after { content: ''; flex: 1; border-bottom: 1px solid var(--border-color); }
.divider-container:not(:empty)::before { margin-right: .8em; }
.divider-container:not(:empty)::after { margin-left: .8em; }

.google-icon { width: 20px; height: 20px; }

/* ==========================================
   LINE VIEW CONTROL LAYOUT
   ========================================== */
.line-view-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 24px;
}

/* Remove bottom margin from back-btn since parent controls the row spacing now */
.line-view-controls .back-btn {
    margin-bottom: 0;
}

/* ==========================================
   SEARCH RESULT LINE INDICATORS
   ========================================== */
.search-item-badges {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-left: auto; /* Automatically pushes badges to the far right edge */
    padding-left: 8px;
    flex-shrink: 0;
}

/* ==========================================
   MATERIAL DESIGN 3 INTERCHANGE BADGES
   ========================================== */
.line-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 24px;            /* Upgraded to a pristine Material 3 compact token height */
    min-width: 24px;         /* Ensures a flawless circle base when idle */
    max-width: 24px;         /* Locks structural layout grid until active hover state */
    flex-shrink: 0;
    border-radius: 100px;    /* Strict pill capsule geometry specification */
    overflow: hidden;
    white-space: nowrap;
    box-shadow: 0 0 0 2px var(--surface-color); /* Crisp structural separation halo */
    cursor: pointer;
    box-sizing: border-box;
    /* Uses a standard M3 easing curve for premium, organic transitions */
    transition: max-width 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), 
                padding 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), 
                box-shadow 0.2s ease, 
                transform 0.15s ease;
}

.badge-text {
    font-size: 0.75rem;      /* Increased size for high-fidelity text legibility */
    font-weight: 500;        /* Standard M3 Medium typography token weight for labels */
    letter-spacing: 0.15px;  /* Fine modern text-tracking adjustment */
    color: #FFFFFF;          /* High contrast default label color */
    opacity: 0;
    transform: scale(0.85);  /* Subtle scale entrance animation baseline */
    padding: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Accessibility: dark text tracking overlay for light transit networks */
.line-badge.light-bg .badge-text {
    color: #1D1B20;          /* Authentic M3 dark onyx title tone */
}

/* ==========================================
   M3 HOVER ELEVATION & EXPANSION
   ========================================== */
.line-badge:hover {
    max-width: 240px;        /* Safely clear long titles like "Hammersmith & City" */
    padding: 0 12px;         /* Roomy, comfortable horizontal padding floor */
    transform: translateY(-1px); /* Delicate vertical lift out of the card surface */
    /* Applies a rich, tactile Material Design Level 2 elevation shadow */
    box-shadow: 0 3px 8px rgba(0,0,0,0.16), 0 0 0 2px var(--surface-color);
    z-index: 5;
}

.line-badge:hover .badge-text {
    opacity: 1;
    transform: scale(1);
    transition-delay: 0.04s; /* Snappy, responsive typography rendering delay */
}

/* ==========================================
   LINE DETAIL VIEW INTERCHANGE BADGES
   ========================================== */
.station-item-badges {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-left: auto; /* Automatically forces interchange dots to the right boundary */
    padding-left: 12px;
    flex-shrink: 0;
}


