* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    color: white;
    min-height: 100vh;
    padding: 20px;
    overflow-x: hidden;
    margin: 0;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.header {
    text-align: center;
    margin-bottom: 30px;
    position: relative;
}

.header h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
}

.header p {
    font-size: 16px;
    opacity: 0.8;
}

/* PWA 安裝圖標 - 只在手機版顯示 */
.pwa-install-icon {
    display: none;
    position: absolute;
    top: 5px;
    right: 5px;
    width: 30px;
    height: 30px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
}

.pwa-install-icon:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.pwa-install-icon svg {
    width: 16px;
    height: 16px;
    fill: white;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 25px;
}

/* 統一所有主要區塊的樣式 */
.search-section,
.ranking-section,
.loading-status,
.error-message,
.success-message {
    width: 100%;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.search-section,
.ranking-section {
    background: rgba(255, 255, 255, 0.95);
    color: #333;
}

.loading-status {
    display: none;
    background: rgba(52, 152, 219, 0.95);
    color: white;
    text-align: center;
    margin-top: 0;
}

.error-message {
    background: #e74c3c;
    color: white;
    display: none;
    font-size: 16px;
}

.success-message {
    background: #27ae60;
    color: white;
    display: none;
    font-size: 16px;
}

.input-label {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 15px;
    color: #666;
}

.input-container {
    position: relative;
    margin-bottom: 25px;
}

.stock-input {
    width: 100%;
    padding: 18px 120px 18px 25px; /* 右側留空間給按鈕 */
    font-size: 20px;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    background: #fff;
    color: #333;
    outline: none;
    transition: all 0.3s ease;
}

.stock-input:focus {
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

/* 智能歷史記錄下拉選單樣式 */
.stock-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 2px solid #3498db;
    border-top: none;
    border-radius: 0 0 12px 12px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.stock-suggestions.show {
    display: block;
}

.suggestion-item {
    padding: 12px 15px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: all 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.suggestion-item:hover {
    background: #f8f9fa;
}

.suggestion-item.selected {
    background: #3498db;
    color: white;
}

.suggestion-item:last-child {
    border-bottom: none;
    border-radius: 0 0 10px 10px;
}

.suggestion-main {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.suggestion-code {
    font-size: 16px;
    font-weight: 600;
    color: #2c3e50;
}

.suggestion-item.selected .suggestion-code {
    color: white;
}

.suggestion-name {
    font-size: 14px;
    color: #666;
    margin-top: 2px;
}

.suggestion-item.selected .suggestion-name {
    color: rgba(255, 255, 255, 0.9);
}

.suggestion-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-size: 12px;
    color: #999;
}

.suggestion-item.selected .suggestion-meta {
    color: rgba(255, 255, 255, 0.8);
}

.suggestion-type {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    background: #e9ecef;
    color: #6c757d;
    margin-bottom: 2px;
}

.suggestion-type.history {
    background: #d4edda;
    color: #155724;
}

.suggestion-type.favorite {
    background: #fff3cd;
    color: #856404;
}

.suggestion-type.popular {
    background: #d1ecf1;
    color: #0c5460;
}

.suggestion-item.selected .suggestion-type {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

/* 快速操作按鈕樣式 */
.quick-actions {
    position: absolute;
    top: 50%;
    right: 15px;
    transform: translateY(-50%);
    display: flex;
    gap: 5px;
    z-index: 10;
}

.quick-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: #f8f9fa;
    color: #6c757d;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.quick-btn:hover {
    background: #e9ecef;
    color: #495057;
    transform: scale(1.05);
}

.quick-btn.active {
    background: #3498db;
    color: white;
}

.quick-btn.favorites-btn.has-favorites {
    background: #ffc107;
    color: white;
}

/* 搜尋區塊標題 */
.suggestion-section-title {
    padding: 8px 15px;
    background: #f8f9fa;
    font-size: 12px;
    font-weight: 600;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #e9ecef;
}

/* 無結果提示 */
.no-suggestions {
    padding: 20px;
    text-align: center;
    color: #999;
    font-size: 14px;
}

/* 快速標籤區樣式 */
.quick-tags {
    margin-top: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
    border: 1px solid #e9ecef;
}

.tag-label {
    font-size: 14px;
    font-weight: 600;
    color: #666;
    margin-bottom: 10px;
}

.stock-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.stock-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    color: #495057;
    cursor: pointer;
    transition: all 0.2s ease;
}

.stock-tag:hover {
    background: #3498db;
    color: white;
    border-color: #3498db;
    transform: translateY(-1px);
}

.stock-tag.favorite {
    background: #fff3cd;
    border-color: #ffc107;
    color: #856404;
}

.stock-tag.favorite:hover {
    background: #ffc107;
    color: white;
}

.favorite-icon {
    font-size: 12px;
}

/* 排行榜區塊樣式 */
.ranking-section {
    margin-top: 0;
}

.ranking-tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 25px;
    background: #f8f9fa;
    border-radius: 10px;
    padding: 4px;
}

.ranking-tab {
    flex: 1;
    padding: 12px 20px;
    border: none;
    background: transparent;
    color: #666;
    font-size: 16px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.ranking-tab:hover {
    background: rgba(52, 152, 219, 0.1);
    color: #3498db;
}

.ranking-tab.active {
    background: #3498db;
    color: white;
    box-shadow: 0 2px 8px rgba(52, 152, 219, 0.3);
}

.ranking-content {
    min-height: 100px;
    position: relative;
    transition: all 0.3s ease-in-out;
}

.ranking-content.collapsed {
    max-height: 480px;
    overflow: hidden;
    border-bottom: 3px dashed #ddd;
}

.ranking-content.expanded {
    max-height: none;
    overflow: visible;
    border-bottom: 3px solid #28a745;
}

.ranking-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.ranking-expand-btn {
    background: transparent;
    border: 2px solid #3498db;
    color: #3498db;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 5px;
}

.ranking-expand-btn:hover {
    background: #3498db;
    color: white;
    transform: translateY(-1px);
}

.ranking-expand-btn.expanded {
    background: #e74c3c;
    border-color: #e74c3c;
    color: white;
}

.ranking-expand-btn.expanded:hover {
    background: #c0392b;
    border-color: #c0392b;
}

.expand-icon {
    transition: transform 0.3s ease;
}

.ranking-summary {
    font-size: 14px;
    color: #666;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ranking-count {
    font-weight: 600;
    color: #3498db;
}

.loading-dots-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100px;
}

.loading-text {
    font-size: 18px;
    color: #666;
    font-weight: 500;
}

.ranking-list {
    display: grid;
    gap: 8px;
}

.ranking-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: white;
    border: 2px solid #f0f0f0;
    border-radius: 12px;
    transition: all 0.3s ease;
    cursor: pointer;
}

.ranking-item:hover {
    border-color: #3498db;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(52, 152, 219, 0.1);
}

.ranking-position {
    font-size: 18px;
    font-weight: 700;
    color: #3498db;
    min-width: 40px;
    text-align: center;
}

.ranking-position.top3 {
    color: #e74c3c;
}

.ranking-stock-info {
    flex: 1;
    margin-left: 15px;
}

.ranking-stock-code {
    font-size: 18px;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 2px;
}

.ranking-stock-name {
    font-size: 14px;
    color: #666;
}

.ranking-actions {
    display: flex;
    gap: 10px;
}

.ranking-action-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: #f8f9fa;
    color: #6c757d;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.ranking-action-btn:hover {
    background: #3498db;
    color: white;
    transform: scale(1.1);
}

.ranking-action-btn.favorite-btn.active {
    background: #ffc107;
    color: white;
}

.ranking-error {
    text-align: center;
    padding: 40px 20px;
    color: #e74c3c;
    font-size: 16px;
}

/* 回測按鈕樣式 */
.analyze-btn {
    width: 100%;
    background: #27ae60;
    color: white;
    border: none;
    padding: 18px;
    font-size: 18px;
    font-weight: 600;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 10px;
}

.analyze-btn:hover {
    background: #219a52;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(39, 174, 96, 0.3);
}

.analyze-btn:disabled {
    background: #bdc3c7;
    transform: none;
    cursor: not-allowed;
    box-shadow: none;
}

.analyze-btn .btn-text {
    display: inline-block;
    transition: opacity 0.3s ease;
}

.analyze-btn.loading .btn-text {
    opacity: 0;
}

.analyze-btn.loading .loading {
    display: block;
}

.loading {
    display: none;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

.loading::after {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid #ffffff;
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 12px;
}

.loading-subtitle {
    font-size: 16px;
    opacity: 0.9;
    margin-bottom: 18px;
}

.loading-timer {
    font-size: 28px;
    font-weight: 700;
    color: #ecf0f1;
    font-family: 'Courier New', monospace;
}

.loading-dots {
    display: inline-block;
    animation: loadingDots 2s infinite;
}

@keyframes loadingDots {
    0%, 20% { opacity: 0; }
    40% { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes fadeIn {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
    0% { opacity: 0; max-height: 0; transform: translateY(-10px); }
    100% { opacity: 1; max-height: 1000px; transform: translateY(0); }
}

.loading-dots:nth-child(1) { animation-delay: 0s; }
.loading-dots:nth-child(2) { animation-delay: 0.2s; }
.loading-dots:nth-child(3) { animation-delay: 0.4s; }

.results-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 25px;
    width: 100%;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
    margin-top: 0;
}

.stats-section, .chart-section, .sub-charts-section {
    background: rgba(255, 255, 255, 0.95);
    color: #333;
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    display: none;
    width: 100%;
}

.section-title {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 20px;
    color: #444;
}

/* 回測完成狀态樣式 */
.analysis-complete-info {
    font-size: 14px;
    font-weight: normal;
    color: #27ae60;
    margin-top: 8px;
    padding: 8px 12px;
    background: rgba(39, 174, 96, 0.1);
    border-radius: 6px;
    border-left: 3px solid #27ae60;
}

/* 統計表格樣式 */
.stats-container {
    width: 100%;
    overflow-x: auto;
}

.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
}

.stats-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 15px;
    table-layout: fixed;
    min-width: 500px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
}

.stats-table th,
.stats-table td {
    padding: 12px 8px;
    text-align: center;
    border-bottom: 1px solid #e0e0e0;
    border-right: 1px solid #e0e0e0;
    font-size: 14px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.stats-table th:last-child,
.stats-table td:last-child {
    border-right: none;
}

.stats-table tr:last-child td {
    border-bottom: none;
}

.stats-table th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #666;
    font-size: 14px;
    border-bottom: 2px solid #e0e0e0;
}

.stats-table td {
    color: #333;
    background-color: #fff;
}

.stats-table tbody tr:nth-child(even) td {
    background-color: #f9f9f9;
}

.stats-table tbody tr:hover td {
    background-color: #f0f8ff;
}

.stats-table .positive {
    color: #dc3545;
    font-weight: 600;
}

.stats-table .negative {
    color: #28a745;
    font-weight: 600;
}

/* 主圖表樣式 */
.chart-item {
    background: white;
    border-radius: 12px;
    padding: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    margin-bottom: 20px;
}

.chart-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #f8f9fa;
    flex-wrap: nowrap;
}

.chart-stock-name-code {
    font-size: 18px;
    color: #2c3e50;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
}

.chart-price-info-container {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 600;
    flex-shrink: 0;
    white-space: nowrap;
}

.chart-price-value {
    font-size: 16px;
    font-weight: 600;
}

.chart-trend-icon {
    font-size: 14px;
    font-weight: bold;
}

.chart-price-change {
    font-size: 14px;
    font-weight: 600;
}

.chart-image {
    width: 100%;
    min-height: 200px;
    max-height: 400px;
    object-fit: contain;
    cursor: pointer;
    transition: all 0.3s ease;
    background-color: #ffffff;
    display: block;
}

.chart-image:hover {
    transform: scale(1.01);
}

/* 台灣股市價格顏色 */
.price-trend-up {
    color: #dc3545;
}

.price-trend-down {
    color: #28a745;
}

.price-trend-flat {
    color: #333;
}

/* 相似歷史樣式 */
.sub-charts-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
}

.sub-chart-item {
    background: white;
    border-radius: 12px;
    padding: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.sub-chart-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}

.sub-chart-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 12px 15px 8px 15px;
    background: #f8f9fa;
}

.sub-chart-stock-name {
    font-size: 16px;
    color: #2c3e50;
    font-weight: 600;
    line-height: 1.2;
}

.sub-chart-corr-percentage {
    font-size: 18px;
    color: #e67e22;
    font-weight: 700;
    line-height: 1;
}

.sub-chart-middle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
}

.sub-chart-stock-id {
    font-size: 20px;
    color: #6c757d;
    font-weight: 500;
}

.sub-chart-similarity {
    font-size: 12px;
    color: #7f8c8d;
    font-weight: 500;
}

.sub-chart-image {
    min-height: 160px;
    max-height: 300px;
    object-fit: contain;
    cursor: pointer;
    transition: all 0.3s ease;
    background-color: #ffffff;
    display: block;
    width: 100%;
}

.sub-chart-image:hover {
    transform: scale(1.01);
}

.chart-placeholder {
    color: #999;
    font-size: 16px;
    padding: 50px;
    background: #f8f9fa;
    border-radius: 15px;
    text-align: center;
    border: 2px dashed #ddd;
}

/* 免責聲明區塊 */
.disclaimer-section {
    background: rgba(255, 193, 7, 0.1);
    border: 2px solid rgba(255, 193, 7, 0.3);
    border-radius: 15px;
    padding: 20px;
    margin-top: 20px;
    display: none;
    width: 100%;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.disclaimer-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-align: center;
}

.disclaimer-icon {
    font-size: 20px;
}

.disclaimer-text {
    font-size: 14px;
    color: #856404;
    font-weight: 600;
}

/* Modal for viewing enlarged images */
.image-modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.modal-image-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 95%;
    max-height: 95%;
}

.modal-content {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    transition: all 0.3s ease;
    cursor: grab;
}

.modal-content:active {
    cursor: grabbing;
}

.modal-close {
    position: absolute;
    top: 30px;
    right: 40px;
    color: white;
    font-size: 50px;
    font-weight: bold;
    cursor: pointer;
    z-index: 2001;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.modal-close:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
}

.modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.5);
    border: none;
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 2001;
    font-size: 0;
}

.modal-nav:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: translateY(-50%) scale(1.1);
}

.modal-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.modal-nav:disabled:hover {
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.5);
}

.modal-prev {
    left: 30px;
}

.modal-next {
    right: 30px;
}

.modal-nav svg {
    width: 24px;
    height: 24px;
}

.modal-info {
    margin-top: 15px;
    text-align: center;
    color: white;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px 20px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
}

.modal-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 5px;
}

.modal-counter {
    font-size: 14px;
    opacity: 0.8;
}

.modal-indicators {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    background: rgba(0, 0, 0, 0.3);
    padding: 8px 12px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
}

.modal-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    cursor: pointer;
    transition: all 0.3s ease;
}

.modal-indicator.active {
    background: white;
    transform: scale(1.2);
}

.modal-indicator:hover {
    background: rgba(255, 255, 255, 0.6);
}

/* PWA 工具提示 */
.pwa-tooltip {
    position: absolute;
    bottom: -28px;
    right: 0;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    opacity: 0;
    transform: translateY(-3px);
    transition: all 0.2s ease;
    pointer-events: none;
    z-index: 1000;
}

.pwa-install-icon:hover .pwa-tooltip {
    opacity: 1;
    transform: translateY(0);
}

.pwa-tooltip::before {
    content: '';
    position: absolute;
    top: -4px;
    right: 8px;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 4px solid rgba(0, 0, 0, 0.85);
}

/* 手機版樣式優化 */
@media (max-width: 767px) {
    body {
        padding: 15px;
        margin: 0;
        overflow-x: hidden;
    }
    
    .container {
        padding: 0;
        margin: 0;
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }
    
    .header {
        padding: 0;
        margin-bottom: 25px;
        position: relative;
    }
    
    .header h1 {
        font-size: 22px;
    }
    
    .header p {
        font-size: 14px;
    }
    
    .pwa-install-icon {
        display: flex;
        top: 0;
        right: 0;
        width: 28px;
        height: 28px;
        background: rgba(52, 152, 219, 0.9);
        border: 1px solid rgba(52, 152, 219, 1);
        border-radius: 50%;
    }
    
    .pwa-install-icon svg {
        width: 14px;
        height: 14px;
    }
    
    .main-content {
        gap: 20px;
    }
    
    .search-section,
    .ranking-section,
    .loading-status,
    .error-message,
    .success-message {
        padding: 20px;
        margin-bottom: 0;
        max-width: 100%;
        margin-left: 0;
        margin-right: 0;
        border-radius: 15px;
    }
    
    .results-grid {
        max-width: 100%;
        padding: 0;
        margin-top: 0;
        gap: 20px;
    }
    
    .stats-section, .chart-section, .sub-charts-section {
        padding: 20px;
        margin-bottom: 0;
        border-radius: 15px;
        overflow-x: auto;
    }
    
    .analysis-complete-info {
        font-size: 12px;
        padding: 6px 10px;
        margin-top: 6px;
    }
    
    .stats-table {
        font-size: 11px;
        min-width: 320px;
    }
    
    .stats-table th,
    .stats-table td {
        padding: 8px 4px;
        font-size: 11px;
        line-height: 1.2;
    }
    
    .stats-table th {
        font-size: 12px;
        font-weight: 600;
    }
    
    .stats-table th:nth-child(1) { width: 18%; }
    .stats-table th:nth-child(2) { width: 15%; }
    .stats-table th:nth-child(3) { width: 22%; }
    .stats-table th:nth-child(4) { width: 22%; }
    .stats-table th:nth-child(5) { width: 23%; }
    
    .chart-header {
        padding: 12px 15px;
        gap: 8px;
        min-height: 44px;
    }
    
    .chart-stock-name-code {
        font-size: 14px;
        max-width: 60%;
    }
    
    .chart-price-info-container {
        gap: 4px;
        font-size: 12px;
        flex-shrink: 0;
    }
    
    .chart-price-value {
        font-size: 12px;
    }
    
    .chart-trend-icon {
        font-size: 10px;
    }
    
    .chart-price-change {
        font-size: 10px;
    }
    
    .chart-image {
        min-height: 150px;
        max-height: 300px;
    }
    
    .sub-charts-list {
        gap: 12px;
    }
    
    .sub-chart-header {
        padding: 10px 12px 6px 12px;
    }
    
    .sub-chart-stock-name {
        font-size: 14px;
    }
    
    .sub-chart-corr-percentage {
        font-size: 16px;
    }
    
    .sub-chart-middle {
        padding: 6px 12px;
    }
    
    .sub-chart-stock-id {
        font-size: 16px;
    }
    
    .sub-chart-similarity {
        font-size: 11px;
    }
    
    .sub-chart-image {
        min-height: 140px;
        max-height: 250px;
    }
    
    .disclaimer-section {
        padding: 15px;
        margin-top: 15px;
    }
    
    .disclaimer-content {
        gap: 8px;
    }
    
    .disclaimer-icon {
        font-size: 18px;
    }
    
    .disclaimer-text {
        font-size: 12px;
    }
    
    /* 手機版智能歷史記錄優化 */
    .stock-input {
        padding: 15px 100px 15px 20px;
        font-size: 18px;
    }
    
    .quick-actions {
        right: 10px;
        gap: 3px;
    }
    
    .quick-btn {
        width: 28px;
        height: 28px;
    }
    
    .stock-suggestions {
        max-height: 250px;
    }
    
    .suggestion-item {
        padding: 10px 12px;
    }
    
    .suggestion-code {
        font-size: 14px;
    }
    
    .suggestion-name {
        font-size: 12px;
    }
    
    .quick-tags {
        margin-top: 12px;
        padding: 12px;
    }
    
    .tag-label {
        font-size: 12px;
        margin-bottom: 8px;
    }
    
    .stock-tag {
        padding: 5px 10px;
        font-size: 12px;
    }
    
    /* 手機版回測按鈕優化 */
    .analyze-btn {
        padding: 15px;
        font-size: 16px;
        margin-top: 8px;
    }
    
    /* 手機版排行榜優化 */
    .ranking-header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
        margin-bottom: 15px;
    }
    
    .ranking-expand-btn {
        padding: 6px 12px;
        font-size: 12px;
        align-self: flex-end;
    }
    
    .ranking-summary {
        font-size: 12px;
        margin-bottom: 12px;
        flex-direction: column;
        gap: 5px;
        align-items: flex-start;
    }
    
    .ranking-tabs {
        gap: 1px;
        padding: 2px;
        margin-bottom: 15px;
    }
    
    .ranking-tab {
        padding: 10px 12px;
        font-size: 14px;
    }
    
    .ranking-item {
        padding: 12px 15px;
    }
    
    .ranking-position {
        font-size: 16px;
        min-width: 35px;
    }
    
    .ranking-stock-info {
        margin-left: 12px;
    }
    
    .ranking-stock-code {
        font-size: 16px;
    }
    
    .ranking-stock-name {
        font-size: 12px;
    }
    
    .ranking-action-btn {
        width: 32px;
        height: 32px;
    }
}

/* 極小螢幕優化 */
@media (max-width: 359px) {
    .search-section,
    .ranking-section,
    .stats-section, 
    .chart-section, 
    .sub-charts-section {
        padding: 12px;
        margin-left: 5px;
        margin-right: 5px;
    }
    
    .stats-table {
        font-size: 10px;
        min-width: 300px;
    }
    
    .stats-table th,
    .stats-table td {
        padding: 6px 2px;
        font-size: 10px;
    }
    
    .stats-table th {
        font-size: 11px;
    }
    
    .chart-header {
        padding: 8px 10px;
        gap: 4px;
        min-height: 36px;
    }
    
    .chart-stock-name-code {
        font-size: 12px;
        max-width: 55%;
    }
    
    .chart-price-info-container {
        gap: 2px;
        font-size: 10px;
    }
    
    .chart-price-value {
        font-size: 10px;
    }
    
    .chart-trend-icon {
        font-size: 8px;
    }
    
    .chart-price-change {
        font-size: 8px;
    }
    
    .chart-image {
        min-height: 120px;
        max-height: 250px;
    }
    
    .disclaimer-section {
        padding: 12px;
        margin-left: 5px;
        margin-right: 5px;
    }
    
    .disclaimer-content {
        gap: 6px;
    }
    
    .disclaimer-icon {
        font-size: 16px;
    }
    
    .disclaimer-text {
        font-size: 11px;
    }
    
    /* 極小螢幕回測按鈕優化 */
    .analyze-btn {
        padding: 12px;
        font-size: 14px;
        margin-top: 6px;
    }
    
    /* 極小螢幕排行榜優化 */
    .ranking-tab {
        padding: 8px 10px;
        font-size: 12px;
    }
    
    .ranking-item {
        padding: 10px 12px;
    }
    
    .ranking-position {
        font-size: 14px;
        min-width: 30px;
    }
    
    .ranking-stock-info {
        margin-left: 10px;
    }
    
    .ranking-stock-code {
        font-size: 14px;
    }
    
    .ranking-stock-name {
        font-size: 11px;
    }
    
    .ranking-action-btn {
        width: 28px;
        height: 28px;
    }
}
