/* 这是全新的 style.css (v3.7 - UI Polish) */
:root {
    --dark-bg: #1c1c1e;
    --card-bg: #2c2c2e;
    --primary-text: #ffffff;
    --secondary-text: #8e8e93;
    --highlight-color: #fddc3e;
    --border-color: #3a3a3c;
    --star-inactive-color: #555;
    --monospace-font: "SF Mono", "Menlo", "Consolas", monospace;
    --header-element-height: 36px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--dark-bg);
    color: var(--primary-text);
    margin: 0;
    padding: 100px 0 60px 0;
}

.main-header, .tabs {
    background-color: var(--dark-bg);
    position: fixed;
    left: 0;
    right: 0;
    z-index: 100;
}

.main-header {
    top: 0; 
    padding: 10px 15px; 
    display: flex; 
    align-items: center; 
    border-bottom: 1px solid var(--border-color);
}

.search-bar {
    flex-grow: 1; 
    background-color: var(--card-bg); 
    border-radius: 8px; 
    padding: 0 12px;
    display: flex; 
    align-items: center;
    height: var(--header-element-height);
}

.search-icon {
    color: var(--secondary-text); 
    margin-right: 8px;
    font-size: 16px;
}

#search-input {
    background: none; 
    border: none; 
    color: var(--primary-text); 
    width: 100%; 
    height: 100%;
    font-size: 16px; 
    font-family: var(--monospace-font);
    outline: none; /* Remove focus outline */
}

#search-input::placeholder {
    color: var(--secondary-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.header-actions {
    display: flex;
    align-items: center;
    margin-left: 10px;
}

.header-btn {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--primary-text);
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.1s ease;
    margin-left: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    font-family: var(--monospace-font); 
    text-align: center;
    height: var(--header-element-height);
    width: 50px; /* Fixed width for all buttons */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    padding: 0; /* Remove padding to rely on flex alignment */
}

.header-btn:hover {
    background-color: #3a3a3c;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.header-btn:active {
    transform: translateY(1px);
    box-shadow: none;
}

.tabs {
    top: 55px; display: flex; padding: 0 15px; border-bottom: 1px solid var(--border-color);
}

.tab-item {
    font-family: inherit;
    font-size: 16px;
    background: none; 
    border: none;
    color: var(--secondary-text); 
    text-decoration: none; 
    padding: 12px 5px; 
    margin-right: 20px; 
    font-weight: 500; 
    position: relative; 
    cursor: pointer;
}

.tab-item.active { color: var(--highlight-color); }
.tab-item.active::after {
    content: ''; 
    position: absolute; 
    bottom: 0; 
    left: 0; 
    right: 0; 
    height: 3px; 
    background-color: var(--highlight-color); 
    border-radius: 1.5px;
}

#main-content { padding: 10px; }
.placeholder { text-align: center; color: var(--secondary-text); padding: 40px 20px; }
.placeholder.error { color: #ff453a; }

/* Styling for global search results container */
#global-search-results-container {
    padding: 10px;
}

#global-search-results-container h3 {
    color: var(--primary-text);
    margin-top: 0;
    margin-bottom: 15px;
    padding-left: 5px;
}

/* Global Search Hint */
.global-search-hint {
    background-color: var(--card-bg);
    color: var(--highlight-color);
    text-align: center;
    padding: 15px;
    margin: 15px 10px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.global-search-hint:hover {
    background-color: #3a3a3c;
    transform: translateY(-1px);
}

.global-search-hint:active {
    transform: translateY(0);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.stop-group-card {
    background-color: var(--card-bg);
    border-radius: 12px;
    margin-bottom: 15px;
    overflow: hidden; /* Ensures content respects border-radius during animation */
    transition: background-color 0.2s ease;
}

.global-search-card .sub-stops-container {
    max-height: 0; /* Initially collapsed */
    transition: max-height 0.4s ease-in-out; /* Smooth expansion/collapse */
    overflow: hidden;
}

.global-search-card.expanded {
    background-color: #38383a; /* Slightly darker background when expanded */
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3); /* Deeper shadow when expanded */
}

.global-search-card.expanded .sub-stops-container {
    max-height: 500px; /* Arbitrary large value for expansion, actual height handled by JS scrollHeight */
    padding: 0 15px 5px 15px;
}

.stop-group-header {
    display: flex;
    align-items: center;
    padding: 15px;
    cursor: pointer; /* Indicate clickable area */
}

.favorite-star { font-size: 24px; color: var(--star-inactive-color); cursor: pointer; transition: color 0.2s ease, transform 0.2s ease; }
.favorite-star.favorited { color: var(--highlight-color); transform: scale(1.2); }
.group-star { margin-right: 12px; }
.stop-group-name { font-weight: 600; font-size: 18px; margin: 0; flex-grow: 1; }
.stop-group-distance { color: var(--secondary-text); font-size: 14px; margin-left: 10px; }

.sub-stops-container { padding: 0 15px 5px 15px; }
.sub-stop-section { border-top: 1px solid var(--border-color); padding: 10px 0; }
.sub-stop-section:first-child { border-top: none; padding-top: 0; }
.sub-stop-header { display: flex; align-items: center; margin-bottom: 5px; }
.sub-stop-star { font-size: 20px; margin-right: 10px; }
.sub-stop-name { font-weight: 500; color: var(--secondary-text); }
.sub-stop-lane { font-weight: 500; color: var(--secondary-text); margin-left: 8px; font-size: 14px; }

.eta-list {}
.eta-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    font-size: 16px;
    text-decoration: none;
    color: var(--primary-text);
    border-bottom: 1px solid var(--border-color);
}
.eta-item:last-child { border-bottom: none; }

.eta-route-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start; 
}

.eta-route {
    font-weight: bold;
    font-size: 18px;
}

.eta-dest {
    font-size: 14px;
    color: var(--secondary-text);
    margin-top: 2px;
}

.eta-time {
    font-weight: bold;
    font-size: 17px;
    color: var(--highlight-color);
    text-align: right;
    min-width: 80px;
}

.eta-item-no-data {
    color: var(--secondary-text);
    padding: 8px 0;
    font-size: 14px;
}

.order-controls {
    display: flex;
    flex-direction: column;
    margin-left: 10px;
}
.order-btn {
    background: none; border: 1px solid var(--secondary-text);
    color: var(--secondary-text); border-radius: 4px; cursor: pointer;
    padding: 0 4px; line-height: 1; font-size: 12px;
}
.order-btn:first-child { margin-bottom: 4px; }

.tab-item.hidden {
    display: none;
}

.loading-etas {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 15px;
    color: var(--secondary-text);
    font-size: 15px;
    gap: 10px;
}

.loading-etas::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid var(--highlight-color);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Style for highlighted search terms */
mark {
    background-color: var(--highlight-color);
    color: var(--dark-bg);
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: bold;
}

/* --- Precise Route Page Styles (Revision) --- */

/* 1. Body Padding Fix: 只對主頁應用頂部內邊距 */
body.page-index {
    padding-top: 100px; /* 57px header + 43px tabs */
}

/* 為路線頁面動態添加的 padding，由 JS 控制 */
body.page-route {
    padding-top: 110px; /* 根據 route-header-container 的高度設定 */
}


/* 2. Header and Info Bar Styling */
.route-header-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background-color: var(--dark-bg);
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.route-header {
    padding: 10px 15px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}
.route-header .back-btn {
    width: auto;
    padding: 0 15px;
    font-size: 20px;
    margin-left: -10px;
    margin-right: 10px;
    text-decoration:none;
}
.route-header-title {
    font-size: 22px;
    font-weight: bold;
    margin: 0;
    flex-grow: 1;
    font-family: var(--monospace-font);
}

#route-info-bar {
    padding: 8px 15px;
    display: flex;
    justify-content: space-between; /* This arranges items correctly */
    align-items: center;
    overflow: hidden; /* Hide any initial overflow before JS runs */
}
.switch-dir-btn {
    width: 50px;
    margin-left: 10px; /* Maintain spacing */
    font-size: 20px;
    flex-shrink: 0; /* Prevent the button from shrinking */
}

/* 5. Typography Improvement */
#route-direction-info {
    font-size: 16px;
    font-weight: 600; /* 加粗以匹配 .stop-group-name */
    white-space: nowrap; /* CRITICAL: Prevent text from wrapping to a new line */
}
.stop-item-name {
    font-size: 18px; /* 增大字體以匹配 .stop-group-name */
    font-weight: 600; /* 加粗 */
}

/* Route Timeline Layout */
#route-container {
    position: relative;
    padding: 25px 15px 15px 45px;
}
.stop-list {
    list-style: none;
    padding: 0; margin: 0;
    position: relative;
}
.stop-list::before {
    content: ''; position: absolute;
    left: 8px; top: 20px; bottom: 20px;
    width: 4px; background-color: var(--border-color);
    z-index: 1;
}
.stop-item {
    position: relative;
    padding: 15px 0 15px 35px;
    min-height: 30px;
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    cursor: pointer; /* 添加點擊指標 */
    transition: background-color 0.2s ease;
}
.stop-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}
.stop-item::after {
    content: ''; position: absolute;
    left: 0; top: 50%;
    transform: translateY(-50%);
    width: 18px; height: 18px;
    border-radius: 50%;
    background-color: var(--secondary-text);
    border: 3px solid var(--dark-bg);
    z-index: 2;
}
.stop-item-seq {
    position: absolute; left: -40px;
    font-size: 14px; color: var(--secondary-text);
    font-weight: bold; width: 25px; text-align: right;
}

/* 4. Highlighted Stop Alignment Fix */
.stop-item.highlight {
    background-color: rgba(253, 220, 62, 0.1);
    border-radius: 8px;
}
.stop-item.highlight::after {
    background-color: var(--highlight-color);
    transform: translateY(-50%) scale(1.2);
}
.stop-item.highlight .stop-item-name {
    color: var(--highlight-color);
}

/* 3. New Bus Icon Style (Material-like) */
.bus-icon {
    position: absolute;
    left: 9px; /* 與站點圓點中心對齊 */
    transform: translate(-50%, -50%); /* 精確居中 */
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: #d63031;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    cursor: pointer;
    transition: top 1s ease-in-out;
    box-shadow: 0 3px 6px rgba(0,0,0,0.2), 0 3px 6px rgba(0,0,0,0.25); /* 陰影 */
}
.bus-icon::before {
    content: '🚌';
    font-size: 16px;
    line-height: 1;
}

/* --- Tooltip and Badge Styles from previous step are still needed --- */
.bus-count-badge {
    position: absolute; top: -4px; right: -4px;
    background-color: var(--highlight-color); color: var(--dark-bg);
    font-size: 11px; font-weight: bold; border-radius: 50%;
    width: 16px; height: 16px; display: flex;
    align-items: center; justify-content: center;
    border: 1px solid var(--dark-bg);
}
.bus-tooltip {
    position: absolute; left: 100%; top: 50%;
    transform: translateY(-50%); margin-left: 15px;
    background-color: var(--card-bg); border: 1px solid var(--border-color);
    border-radius: 8px; padding: 8px 12px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3); z-index: 20;
    opacity: 0; visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    white-space: nowrap;
}
.bus-tooltip.visible { opacity: 1; visibility: visible; }
.bus-tooltip-item { display: block; font-size: 14px; padding: 2px 0; }
.bus-tooltip-item .bus-plate { font-weight: bold; }
.bus-tooltip-item .bus-speed { color: var(--secondary-text); margin-left: 5px; }