/* CSS Reset & Variable Definitions */
:root {
    --bg-base: #090a0f;
    --bg-surface: #121420;
    --bg-card: rgba(22, 25, 41, 0.65);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-highlight: rgba(0, 242, 254, 0.15);
    
    --accent-primary: #00f2fe; /* Electric Cyan */
    --accent-secondary: #4facfe; /* Royal Blue */
    --accent-gradient: linear-gradient(135deg, var(--accent-secondary) 0%, var(--accent-primary) 100%);
    
    --text-primary: #ffffff;
    --text-secondary: #a0a5c0;
    --text-muted: #646a8a;
    
    --success: #00e676;
    --warning: #ffb300;
    --danger: #ff5252;
    
    --shadow-glow: 0 8px 32px 0 rgba(0, 242, 254, 0.08);
    --shadow-card: 0 8px 24px rgba(0, 0, 0, 0.4);
    
    --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --radius-lg: 18px;
    --radius-md: 12px;
    --radius-sm: 8px;
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    overflow-x: hidden;
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(79, 172, 254, 0.06) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(0, 242, 254, 0.06) 0%, transparent 40%);
    background-attachment: fixed;
}

/* App Layout */
.app-container {
    width: 100%;
    max-width: 500px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 16px;
    padding-bottom: env(safe-area-inset-bottom, 16px);
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0 20px 0;
}

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

.logo-icon {
    color: var(--accent-primary);
    filter: drop-shadow(0 0 6px rgba(0, 242, 254, 0.5));
}

.app-header h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.04);
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.green {
    background-color: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.status-dot.orange {
    background-color: var(--warning);
    box-shadow: 0 0 8px var(--warning);
}

.status-text {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Content */
.app-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Search Section */
.search-section {
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 10;
}

.search-box {
    display: flex;
    align-items: center;
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 18px 50px 18px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-size: 16px;
    font-family: var(--font-sans);
    font-weight: 400;
    outline: none;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-card);
}

.search-box input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(0, 242, 254, 0.15), var(--shadow-glow);
}

.clear-search-btn {
    position: absolute;
    right: 18px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    width: 36px;
}

.clear-search-btn:hover {
    color: var(--text-primary);
}

/* Autocomplete List */
.search-results-list {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: rgba(18, 20, 32, 0.95);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    max-height: 280px;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    z-index: 99;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover, .search-result-item:active {
    background-color: rgba(255, 255, 255, 0.05);
}

.search-result-icon {
    color: var(--accent-primary);
    display: flex;
    flex-shrink: 0;
}

.search-result-name {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
}

/* Info & Permission Banners */
.info-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.03) 0%, rgba(255, 255, 255, 0.01) 100%);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    gap: 12px;
    animation: slideIn 0.3s ease;
}

.permission-banner {
    background: linear-gradient(135deg, rgba(0, 242, 254, 0.05) 0%, rgba(79, 172, 254, 0.01) 100%);
    border-color: var(--border-highlight);
}

.banner-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.banner-body p {
    font-size: 13px;
    line-height: 1.4;
    color: var(--text-secondary);
}

.banner-body strong {
    color: var(--text-primary);
}

.banner-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    align-self: flex-start;
}

/* Buttons */
.btn {
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 13px;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    text-align: center;
    transition: transform 0.2s ease, filter 0.2s ease;
    align-self: flex-start;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--accent-gradient);
    color: #000;
    box-shadow: 0 4px 12px rgba(0, 242, 254, 0.3);
}

.btn-primary:hover {
    filter: brightness(1.1);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 6px;
}

/* Active Alarms Section */
.active-alarms-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.section-title {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    font-weight: 700;
    padding-left: 4px;
}

.active-alarm-card {
    display: flex;
    align-items: center;
    gap: 16px;
    background: linear-gradient(135deg, rgba(255, 82, 82, 0.1) 0%, rgba(22, 25, 41, 0.6) 100%);
    border: 1px solid rgba(255, 82, 82, 0.2);
    border-radius: var(--radius-md);
    padding: 16px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    animation: pulseBorder 2.5s infinite;
}

.alarm-card-icon {
    color: var(--danger);
    animation: ringBell 1s ease-in-out infinite alternate;
}

.alarm-card-info {
    flex: 1;
}

.alarm-card-info h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 2px;
}

.alarm-card-info p {
    font-size: 12px;
    color: var(--text-secondary);
}

.btn-cancel-alarm {
    background: rgba(255, 82, 82, 0.1);
    border: 1px solid rgba(255, 82, 82, 0.3);
    color: var(--danger);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.btn-cancel-alarm:hover, .btn-cancel-alarm:active {
    background: rgba(255, 82, 82, 0.2);
}

/* Departures Container */
.departures-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex: 1;
}

.selected-stop-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-card);
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.stop-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stop-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--accent-primary);
    letter-spacing: 0.5px;
}

.stop-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.btn-change-stop {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 12px;
}

.btn-change-stop:hover, .btn-change-stop:active {
    background: rgba(255, 255, 255, 0.1);
}

/* Empty State / Loader */
.empty-state, .loader-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 20px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px dashed var(--border-color);
    flex: 1;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.empty-icon-container {
    background: rgba(255, 255, 255, 0.02);
    padding: 20px;
    border-radius: 50%;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}

.pulse-icon {
    color: var(--text-muted);
}

.empty-state h3 {
    font-size: 18px;
    margin-bottom: 8px;
    font-weight: 600;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-secondary);
    max-width: 320px;
    line-height: 1.5;
}

.loader-view {
    border-style: solid;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(0, 242, 254, 0.15);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

.loader-view p {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Departures List */
.departures-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.departure-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 16px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: var(--shadow-card);
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.departure-card:hover {
    border-color: rgba(255, 255, 255, 0.15);
}

.departure-info {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
    min-width: 0; /* Ensures text truncation works */
}

.line-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 16px;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.line-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.line-headsign {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.line-schedule {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.rt-indicator {
    color: var(--success);
    font-weight: 600;
}

.departure-timing {
    display: flex;
    align-items: center;
    gap: 16px;
}

.countdown {
    text-align: right;
}

.countdown-number {
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.countdown-label {
    font-size: 10px;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
}

.alarm-toggle-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.alarm-toggle-btn:hover, .alarm-toggle-btn:active {
    background: rgba(0, 242, 254, 0.08);
    border-color: var(--border-highlight);
    color: var(--accent-primary);
}

.alarm-toggle-btn.active {
    background: rgba(255, 82, 82, 0.1);
    border-color: rgba(255, 82, 82, 0.3);
    color: var(--danger);
    animation: ringBell 0.5s ease-in-out;
}

/* Modal dialog custom styling */
.glass-dialog {
    border: 1px solid var(--border-color);
    background: rgba(18, 20, 32, 0.95);
    border-radius: var(--radius-lg);
    padding: 0;
    max-width: 400px;
    width: 90%;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    color: var(--text-primary);
    overflow: hidden;
}

.glass-dialog::backdrop {
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.dialog-content {
    display: flex;
    flex-direction: column;
}

.dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.dialog-header h3 {
    font-size: 16px;
    font-weight: 700;
}

.dialog-close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
}

.dialog-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.dialog-description {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.departure-preview-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
}

.lead-time-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.lead-time-selector label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.lead-time-selector select {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 12px;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 14px;
    outline: none;
    cursor: pointer;
    width: 100%;
}

.lead-time-selector select:focus {
    border-color: var(--accent-primary);
}

.notification-warning {
    background: rgba(255, 179, 0, 0.08);
    border: 1px solid rgba(255, 179, 0, 0.2);
    border-radius: var(--radius-md);
    padding: 10px;
}

.notification-warning p {
    font-size: 12px;
    line-height: 1.4;
    color: var(--warning);
}

.dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 20px;
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid var(--border-color);
}

.dialog-footer button {
    align-self: initial;
}

/* Toast Stacking & Popovers */
.toast-stack {
    position: fixed;
    bottom: 24px;
    left: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    z-index: 10000;
}

.toast-item[popover] {
    position: relative;
    inset: auto;
    width: 100%;
    max-width: 468px;
    background: rgba(18, 20, 32, 0.9);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    color: var(--text-primary);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    pointer-events: auto;
    
    /* Discrete transition for popover top layer */
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), display 0.3s allow-discrete;
    opacity: 0;
    transform: translateY(20px);
    margin: 0 auto;
}

.toast-item[popover]:popover-open {
    opacity: 1;
    transform: translateY(0);
}

@starting-style {
    .toast-item[popover]:popover-open {
        opacity: 0;
        transform: translateY(20px);
    }
}

/* Multiple toasts spacing support */
.toast-item[popover] + .toast-item[popover] {
    margin-top: 8px;
}

.toast-content {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: space-between;
}

.toast-body {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toast-icon {
    color: var(--accent-primary);
    flex-shrink: 0;
}

.toast-message {
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
}

.toast-close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toast-close-btn:hover {
    color: var(--text-primary);
}

/* Footer styling */
.app-footer {
    text-align: center;
    padding: 24px 0 8px 0;
}

.app-footer p {
    font-size: 11px;
    color: var(--text-muted);
    letter-spacing: 0.3px;
}

/* Animations */
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes ringBell {
    0% { transform: rotate(-8deg); }
    100% { transform: rotate(8deg); }
}

@keyframes pulseBorder {
    0% { border-color: rgba(255, 82, 82, 0.2); box-shadow: 0 0 0 rgba(255, 82, 82, 0); }
    50% { border-color: rgba(255, 82, 82, 0.4); box-shadow: 0 0 12px rgba(255, 82, 82, 0.15); }
    100% { border-color: rgba(255, 82, 82, 0.2); box-shadow: 0 0 0 rgba(255, 82, 82, 0); }
}

/* Google AdSense Sticky Banner */
.adsense-container {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 500px;
    background: rgba(18, 20, 32, 0.95);
    border-top: 1px solid var(--border-color);
    padding: 8px 16px 12px 16px;
    z-index: 1000;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.3s ease;
}

.adsense-container.hidden {
    transform: translate(-50%, 100%);
    pointer-events: none;
}

.ads-label {
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 4px;
    align-self: flex-start;
}

.ads-close-btn {
    position: absolute;
    top: 6px;
    right: 12px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 2px;
}

.ads-close-btn:hover {
    color: var(--text-primary);
}

.mock-ad-content {
    width: 320px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.dev-ad-placeholder {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 11px;
}

.dev-ad-placeholder p {
    font-size: 9px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Adjust app-container bottom padding so ad banner doesn't cover content */
.app-container {
    padding-bottom: calc(76px + env(safe-area-inset-bottom, 16px)) !important;
}

/* GDPR Consent Banner */
.consent-banner {
    position: fixed;
    bottom: 16px;
    left: 16px;
    right: 16px;
    background: rgba(18, 20, 32, 0.95);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    z-index: 10000;
    max-width: 468px;
    margin: 0 auto;
    animation: slideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.consent-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.consent-content h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
}

.consent-content p {
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-secondary);
}

.consent-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 4px;
}

.consent-buttons button {
    align-self: auto;
}
