/* ===========================
   全域樣式
   =========================== */
body {
    padding: 20px;
    font-family: 'Noto Sans', sans-serif;
}

.header {
    margin-bottom: 20px;
}

/* ===========================
   表單區域
   =========================== */
.form-section,
.form-activate-section {
    margin-bottom: 20px;
    background-color: #f8f9fa;
    padding: 20px;
    border-radius: 5px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.form-section {
    height: 100%;
}

.form-section h4,
.form-activate-section h4 {
    font-weight: bold;
}

/* ===========================
   Tooltips
   =========================== */
.tooltip {
    position: absolute;
    text-align: center;
    padding: 6px;
    font: 12px sans-serif;
    background: lightsteelblue;
    border: 0;
    border-radius: 8px;
    pointer-events: none;
    opacity: 0;
}

/* ===========================
   列表
   =========================== */
.list-unstyled {
    padding-left: 20px;
    line-height: 1.6;
}

/* ===========================
   儀表板
   =========================== */
.dashboard-row {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.top-row .card {
    flex: 1;
    min-width: 200px;
    background-color: #ffffff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    text-align: center;
    font-weight: bold;
}

.bottom-row .card.wide {
    flex: 1;
    min-width: 400px;
    background-color: #ffffff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.stat {
    font-size: 24px;
    color: #007BFF;
    font-weight: bold;
}

.placeholder-chart,
.placeholder-map {
    height: 200px;
    background-color: #e9ecef;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6c757d;
}

/* ===========================
   表格
   =========================== */
#compare-table {
    width: 100%;
}

#compare-table th,
#compare-table td {
    padding: 2px 8px;
}

#compare-table th {
    text-align: left;
    font-weight: 600;
}

#compare-table td.text-end {
    text-align: right;
}

/* ===========================
   範圍按鈕
   =========================== */
.range-buttons-wrapper {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.btn-select {
    background: none;
    border: none;
    font-size: 0.95rem;
    color: #444;
    padding: 6px 8px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
}

.btn-select:hover {
    color: #007bff;
    background-color: rgba(0, 123, 255, 0.05);
}

.btn-select.active {
    color: #007bff;
    border-bottom: 2px solid #007bff;
    font-weight: 500;
}

.btn-select:disabled {
    color: #aaa;
    cursor: not-allowed;
    background-color: rgba(0, 0, 0, 0.05);
}

/* ===========================
   圖表區
   =========================== */
.compare-chart-wrapper {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 10px;
}

.compare-table-wrapper {
    overflow-x: auto;
}

/* ===========================
   比較搜尋
   =========================== */
#search-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
    max-width: 100%;
}

#search-input {
    cursor: pointer;
    width: 100px;
    padding: 6px;
    margin-top: 15px;
    border: 0px;
    border-radius: 4px;
    font-size: 0.95rem;
}

#search-input:hover {
    background-color: rgba(0, 123, 255, 0.05);
    box-shadow: 0 0 5px rgba(0, 123, 255, 0.2);
}

#search-input:focus {
    outline: none;
    box-shadow: 0 0 5px #007bff;
}

#search-suggestions .list-group-item {
    display: inline-block;
    white-space: nowrap;
    padding: 3px 8px;
    font-size: 0.9rem;
    border: 1px solid #eee;
    border-radius: 6px;
    transition: background-color 0.2s;
    max-width: 100%;
}

#search-suggestions .list-group-item:hover {
    background-color: #e7f1ff;
    cursor: pointer;
}

.list-group-item.active {
    color: #007bff;
    border-bottom: 2px solid #007bff;
    font-weight: 500;
}

/* ===========================
   投資追蹤
   =========================== */
.invest-toolbar {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.invest-tradepanel,
.invest-configpanel {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* 7:3 比例 */
.invest-tradepanel {
    flex: 7 1 0;
}

.invest-configpanel {
    flex: 3 1 0;
}

.invest-trade-row-1,
.invest-trade-row-2,
.invest-config-row-1,
.invest-config-row-2 {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: nowrap;
    min-width: 0;
}

/* 左邊交易區第一排 */
.invest-side-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    flex: 0 0 auto;
}

.invest-symbol-wrap {
    min-width: 0;
    flex: 1 1 auto;
}

#invest-symbol-input {
    cursor: pointer;
    padding: 6px 10px;
    border: 0;
    border-radius: 4px;
    font-size: 0.95rem;
    width: 95%;
}

#invest-symbol-input:hover {
    background-color: rgba(0, 123, 255, 0.05);
    box-shadow: 0 0 5px rgba(0, 123, 255, 0.2);
}

#invest-symbol-input:focus {
    outline: none;
    box-shadow: 0 0 5px #007bff;
}

#invest-shares-input,
#invest-date-input,
#invest-config-select,
#invest-config-name {
    height: 24px;
    padding: 6px 10px;
    font-size: 0.95rem;
    line-height: 1.2;
    color: #444;
    background: #fff;
    border: 1px solid #d7dce3;
    border-radius: 6px;
    box-shadow: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}
#invest-config-select {
    height: 34px;
}

#invest-shares-input:hover,
#invest-date-input:hover,
#invest-config-select:hover,
#invest-config-name:hover {
    background-color: rgba(0, 123, 255, 0.03);
    border-color: #b8c7da;
}

#invest-shares-input:focus,
#invest-date-input:focus,
#invest-config-select:focus,
#invest-config-name:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.12);
}

#invest-shares-input::placeholder,
#invest-config-name::placeholder {
    color: #8a8f98;
}

/* 尺寸配置 */
#invest-shares-input {
    width: 110px;
    flex: 0 0 110px;
}

#invest-date-input {
    width: 150px;
    flex: 0 0 150px;
}

#invest-config-select {
    flex: 1 1 auto;
    min-width: 140px;
}

#invest-config-name {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
}

#invest-btn-add {
    flex: 0 0 auto;
}

/* 左邊交易區第二排：推薦選股整排 */
.invest-suggestions-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
    min-height: 36px;
    padding: 2px 0;
}

.invest-suggestions-row .list-group-item {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    padding: 5px 10px;
    font-size: 0.9rem;
    border: 1px solid #eee;
    border-radius: 999px;
    transition: background-color 0.2s;
    background: #fff;
    max-width: 100%;
}

.invest-suggestions-row .list-group-item:hover {
    background-color: #e7f1ff;
    cursor: pointer;
}

/* 右邊設定檔區 */
#invest-config-select {
    flex: 1 1 auto;
    min-width: 140px;
}

#invest-config-reload,
#invest-config-delete,
#invest-config-add {
    flex: 0 0 auto;
}

#invest-config-name {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
}

.invest-msg {
    display: none;
    flex: 1 1 100%;
    font-size: 0.9rem;
    padding: 4px 10px;
    border-radius: 4px;
}

.invest-msg.ok {
    background-color: #e7f4e4;
    color: #256029;
    border: 1px solid #b5e0b1;
}

.invest-msg.error {
    background-color: #fcebea;
    color: #842029;
    border: 1px solid #f5c2c7;
}

.invest-chart-wrapper {
    width: 100%;
    height: 260px;
    overflow-x: auto;
    padding-bottom: 10px;
}

.invest-table-wrapper {
    overflow-x: auto;
}

#invest-table {
    width: 100%;
}

#invest-table th,
#invest-table td {
    padding: 2px 8px;
}

#invest-table th {
    text-align: left;
    font-weight: 600;
}

#invest-table td.text-end {
    text-align: right;
}

.completed-row {
    background: #f2f3f5;
    font-weight: 600;
}

/* ===========================
   刪除按鈕
   =========================== */
.remove-btn {
    background: none;
    border: none;
    color: #888;
    font-size: 0.9rem;
    margin-left: 6px;
}

.remove-btn:hover {
    color: #d33;
}

/* ===========================
   比較訊息
   =========================== */
#compare-msg {
    font-size: 0.9rem;
    padding: 6px 12px;
    border-radius: 4px;
    display: none;
}

#compare-msg.success {
    background-color: #e7f4e4;
    color: #256029;
    border: 1px solid #b5e0b1;
}

#compare-msg.error {
    background-color: #fcebea;
    color: #842029;
    border: 1px solid #f5c2c7;
}

#range-buttons {
    display: flex;
    gap: 12px;
    align-items: center;
    width: 100%;
}

#range-buttons button {
    flex: 1;
    white-space: nowrap;
}

#compare-start-date {
    flex: 1;
    font-size: 0.9rem;
    color: #666;
    margin-top: 6px;
    text-align: left;
}

#slider-value {
    flex: 1;
    text-align: left;
    white-space: nowrap;
    font-size: 0.9rem;
}

#days-slider {
    -webkit-appearance: none;
    flex: 8;
    min-width: 0;
    height: 4px;
    margin: 10px 0;
    background: #ddd;
    border-radius: 3px;
    outline: none;
    transition: background 0.3s ease;
}

#days-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: #007bff;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.3s;
}

#days-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: #007bff;
    border-radius: 50%;
    cursor: pointer;
}

/* ===========================
   TWSE 分布圖
   =========================== */
.btn-bar {
    margin-bottom: 12px;
    justify-content: center;
}

#heatmap-control {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

#twse-distribution {
    width: 100% !important;
    max-width: 100%;
    display: block;
    margin: 0 auto;
}

.twse-bar-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
}

/* ===========================
   響應式
   =========================== */
@media (max-width: 992px) {
    .invest-toolbar {
        flex-direction: column;
    }

    .invest-tradepanel,
    .invest-configpanel {
        flex: 1 1 100%;
        width: 100%;
    }
}

@media (max-width: 768px) {
    .bottom-row .card.wide {
        min-width: 100%;
    }

    .invest-trade-row-1,
    .invest-config-row-1,
    .invest-config-row-2 {
        flex-wrap: wrap;
    }

    .invest-side-actions {
        width: 100%;
    }

    .invest-symbol-wrap,
    #invest-config-select,
    #invest-config-name {
        width: 100%;
        flex: 1 1 100%;
    }

    #invest-shares-input,
    #invest-date-input {
        flex: 1 1 100%;
        width: 100%;
    }
}