/* ========== 通用樣式（全站統一） ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei", sans-serif;
    background: #fafafa;
    color: #333333;
    line-height: 1.5;
}

/* ========== 小工具（跨頁共用，避免 inline style） ========== */
.is_hidden {
    display: none;
}

.text_center {
    text-align: center;
}

.text_muted {
    color: #666666;
}

.text_gray_999 {
    color: #999999;
}

.text_gray_ccc {
    color: #cccccc;
}

.text_red {
    color: #f44336;
}

.text_green {
    color: #4caf50;
}

.text_orange {
    color: #ff9800;
}

.text_blue {
    color: #4e90ea;
}

.font_bold_700 {
    font-weight: 700;
}

.font_weight_600 {
    font-weight: 600;
}

.percent_symbol_small {
    font-size: 0.6rem;
}

.chart_empty_hint {
    text-align: center;
    padding: 40px;
    color: #999999;
}

.chart_canvas_wrap {
    flex: 1;
    min-height: 0;
    width: 100%;
}

.btn_disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.batch_preview_title {
    margin-bottom: 10px;
    font-weight: bold;
}

/* 讓整個頁面以 viewport 高度為基準，並把全域捲軸關閉，
   由各欄位內部處理自己的滾動條（避免整頁出現垂直捲動） */
html, body {
    height: 100vh;
}
body {
    overflow: hidden;
}

.container {
    margin: 0 auto;
    padding: 10px;
    overflow: visible;
}

/* ========== 表格樣式（通用） ========== */
/* 
 * 合併 .records_table、.strategies_table、.monthly_table 為統一樣式
 * 使用多選擇器減少重複程式碼
 */
.records_table,
.strategies_table,
.monthly_table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.strategies_table,
.monthly_table {
    margin-top: 12px;
}

.records_table th,
.strategies_table th,
.monthly_table th {
    padding: 5px;
    font-weight: 500;
    color: #666666;
    font-size: 12px;
    border-bottom: 1px solid #e0e0e0;
    text-align: right;
    white-space: nowrap;
}

.records_table th:first-child,
.strategies_table th:first-child,
.monthly_table th:first-child {
    text-align: left;
}

.records_table th:last-child,
.strategies_table th:last-child,
.monthly_table th:last-child {
    text-align: center;
}

.records_table td,
.strategies_table td,
.monthly_table td {
    padding: 5px;
    border-bottom: 1px solid #f5f5f5;
    color: #333333;
    text-align: right;
}

.records_table td:first-child,
.strategies_table td:first-child,
.monthly_table td:first-child {
    text-align: left;
    white-space: nowrap;
}

.records_table td:last-child,
.strategies_table td:last-child,
.monthly_table td:last-child {
    padding: 0;
    vertical-align: middle;
}

.records_table tbody tr:hover,
.strategies_table tbody tr:hover,
.monthly_table tbody tr:hover,
.monthly_records_table tbody tr:hover {
    background-color: #fafafa;
}

/* 通用表格容器（白底 BOX，與 chart_section 統一） */
.table_container {
    background: #fff;
    padding: 30px;
}

/* ========== 全站統一按鈕樣式（無圓角） ========== */
.btn {
    display: inline-block;
    padding: 8px 16px;
    background-color: #9e9e9e;
    color: #fff;
    border: none;
    border-radius: 0;
    font-size: 13px;
    cursor: pointer;
    transition: background-color 0.2s;
    text-decoration: none;
}

.btn:hover {
    background-color: #757575;
}

.btn_success {
    background-color: #5b9bd5;
}

.btn_success:hover {
    background-color: #4a8bc2;
}

.btn_danger {
    background-color: #dc3545;
}

.btn_danger:hover {
    background-color: #c82333;
}

.btn_small {
    padding: 6px;
    font-size: 12px;
}

/* ========== 表格操作按鈕 ========== */
.records_table_actions {
    display: flex;
    gap: 1px;
    justify-content: flex-end;
}

.records_table_actions .btn {
    background-color: #f5f5f5;
    color: #333;
    flex: 1;
    max-width: 50px;
}

.records_table_actions .btn:hover {
    background-color: #e5e5e5;
}

/* ========== Modal 樣式 ========== */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.5);
    align-items: center;
    justify-content: center;
}

.modal.is_open {
    display: flex;
}

.modal_content {
    background-color: #fff;
    padding: 50px 90px;
    width: 90%;
    max-width: 580px;
    border: 1px solid #e0e0e0;
}

.modal_close {
    color: #999999;
    float: right;
    font-size: 22px;
    font-weight: 400;
    cursor: pointer;
    line-height: 1;
}

.modal_close:hover {
    color: #333333;
}

.modal_content h2 {
    margin-top: 0;
    margin-bottom: 12px;
    color: #222222;
    font-size: 16px;
    font-weight: 500;
}

/* ========== 表單樣式 ========== */
.form_group {
    margin-bottom: 12px;
}

.form_row {
    position: relative;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}

.form_group label {
    display: block;
    margin-bottom: 4px;
    font-weight: 400;
    color: #666666;
    font-size: 13px;
}

.form_group input,
.form_group select,
.form_group textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cccccc;
    font-size: 13px;
    background-color: #fff;
    color: #333333;
    transition: border-color 0.2s;
}

.form_group input:focus,
.form_group select:focus,
.form_group textarea:focus {
    outline: none;
    border-color: #555555;
}

.form_actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 12px;
}

/* ========== 績效解析預覽（策略頁 / 月損益頁共用） ========== */
.performance_preview {
    background: #f8f9fa;
    padding: 15px;
    margin-top: 10px;
    font-size: 12px;
    color: #666;
}

.performance_preview h4 {
    margin-bottom: 10px;
    color: #333;
}

.performance_preview .field {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

/* ========== Flatpickr 日曆樣式美化 ========== */
.flatpickr-calendar {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei", sans-serif !important;
    background: #ffffff !important;
    border: 1px solid #e0e0e0 !important;
}

.flatpickr-months {
    background: #fafafa !important;
    border-bottom: 1px solid #e0e0e0 !important;
}

.flatpickr-current-month .flatpickr-monthDropdown-months {
    font-size: 85% !important;
    padding: 0 .5ch !important;
}

.flatpickr-current-month {
    padding: 0 !important;
    color: #222222 !important;
}

.flatpickr-current-month .flatpickr-monthDropdown-months {
    background: #ffffff !important;
    color: #222222 !important;
    border: 1px solid #cccccc !important;
}

.flatpickr-current-month input.cur-year {
    color: #222222 !important;
}

/* 年份月份順序調整 */
.flatpickr-months .flatpickr-month {
    display: flex !important;
}

.flatpickr-months .flatpickr-month .flatpickr-current-month {
    display: flex !important;
    flex-direction: row-reverse !important;
    justify-content: center !important;
    align-items: center !important;
    flex: 1 !important;
    text-align: center !important;
}

.flatpickr-months .flatpickr-month .flatpickr-current-month span.cur-month {
    order: 2 !important;
}

.flatpickr-months .flatpickr-month .flatpickr-current-month .numInputWrapper {
    order: 1 !important;
    margin-right: 8px !important;
}

.flatpickr-prev-month,
.flatpickr-next-month {
    fill: #666666 !important;
}

.flatpickr-prev-month:hover,
.flatpickr-next-month:hover {
    fill: #555555 !important;
}

.flatpickr-weekdays {
    background: #fafafa !important;
}

.flatpickr-weekday {
    color: #666666 !important;
    font-weight: 500 !important;
}

.flatpickr-day {
    color: #333333 !important;
    border: 1px solid transparent !important;
}

.flatpickr-day.prevMonthDay,
.flatpickr-day.nextMonthDay {
    color: #999999 !important;
}

.flatpickr-day:hover {
    background: #f0f0f0 !important;
    border-color: #e0e0e0 !important;
}

.flatpickr-day.today {
    border-color: #555555 !important;
}

.flatpickr-day.selected {
    background: #555555 !important;
    border-color: #555555 !important;
    color: #ffffff !important;
}

.flatpickr-day.flatpickr-disabled {
    color: #cccccc !important;
}

/* ========== 分頁樣式 ========== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 10px;
    padding: 10px 0;
}

.pagination_info {
    font-size: 13px;
    color: #666666;
    padding: 0 8px;
}

/* ========== 空狀態 ========== */
.empty_state {
    text-align: center;
    padding: 60px 20px;
    color: #999999;
}

.empty_state_icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.3;
}

.empty_state_text {
    font-size: 14px;
    color: #999999;
}

/* ========== 訊息提示 ========== */
.error_message,
.success_message {
    padding: 12px 16px;
    margin: 12px 0;
    font-size: 14px;
    border-left: 3px solid;
}

.error_message {
    background-color: #fef2f2;
    border-color: #dc2626;
    color: #991b1b;
}

.success_message {
    background-color: #f0fdf4;
    border-color: #059669;
    color: #166534;
}

/* ========== 載入動畫 ========== */
.spinner {
    border: 2px solid #f0f0f0;
    border-top: 2px solid #555555;
    width: 32px;
    height: 32px;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* ========== 響應式設計 ========== */
@media (max-width: 768px) {
    .modal_content {
        width: 95%;
        max-width: 380px;
        padding: 30px 60px;
    }

    .records_table {
        font-size: 12px;
    }

    .records_table th,
    .records_table td {
        padding: 5px;
    }

    .form_row {
        grid-template-columns: 1fr;
    }

    .form_actions {
        flex-direction: column-reverse;
    }

    .form_actions button {
        width: 100%;
    }

    .records_table_actions {
        flex-direction: column;
    }

    .btn_small {
        width: 100%;
        font-size: 11px;
    }
}


/* ========== 列印樣式 ========== */
@media print {

    .btn,
    .records_table_actions,
    .modal {
        display: none !important;
    }

    body {
        background: #fff;
    }
}

/* ========== 滾動條樣式 ========== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #fafafa;
}

::-webkit-scrollbar-thumb {
    background: #cccccc;
}

::-webkit-scrollbar-thumb:hover {
    background: #999999;
}

/* ========== 熱力圖 ========== */

.heatmap_container {
    /* 減少底部額外空間，避免推高頁面總高度 */
    padding: 0;
    overflow: hidden;
    flex: 1;
    min-height: 0; /* 重要：允許縮小 */
}

.heatmap_grid {
    width: 100%;
    min-width: 650px;
}

.heatmap_months {
    display: flex;
    margin-bottom: 5px;
    padding-left: 50px;
    gap: 2px;
}

.heatmap_month_label {
    flex: 1;
    text-align: center;
    font-size: 12px;
    color: #666666;
}

.heatmap_year_row {
    display: flex;
    align-items: stretch;
    margin-bottom: 2px;
}

.heatmap_year_label {
    width: 50px;
    text-align: right;
    font-size: 12px;
    color: #666666;
    padding-right: 10px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.heatmap_cells {
    display: flex;
    flex: 1;
    gap: 2px;
}

.heatmap_cell {
    flex: 1;
    line-height: 45px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    color: #222222;
    cursor: default;
}

/* 熱力圖格子 TOOLTIP */
.heatmap_cell[data-tooltip] {
    position: relative;
}

.heatmap_cell[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 12px;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-line;
    text-align: left;
    z-index: 10000;
    margin-top: 5px;
    width: max-content;
    max-width: 200px;
    word-wrap: break-word;
}

.heatmap_cell[data-tooltip]:hover::before {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-bottom-color: rgba(0, 0, 0, 0.8);
    z-index: 10000;
    margin-top: -5px;
}

.heatmap_cell_empty {
    background: #f5f5f5;
    color: #999999;
}

.heatmap_year_total_label {
    font-weight: 600;
    color: #555555;
    border-left: 1px solid #cccccc;
    padding-left: 4px;
    margin-left: 4px;
}

.heatmap_year_total {
    font-weight: 600;
    padding-left: 4px;
    margin-left: 4px;
    font-size: 12px;
}

/* ========== 交易紀錄區塊樣式 ========== */
#btn_add_record {
    position: absolute;
    top: 0;
    right: 0;
}

/* ========== 月損益樣式 ========== */
.monthly_records_summary {
    margin-top: 20px;
}

.summary_stats {
    background: #f8f9fa;
    margin-bottom: 20px;
}

.summary_stats h4 {
    margin: 0 0 15px 0;
    color: #333;
    font-size: 16px;
}

.stats_grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.stat_item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: white;
    border: 1px solid #e9ecef;
}

.stat_label {
    font-weight: 500;
    color: #666;
}

.stat_value {
    font-weight: 600;
    font-size: 14px;
}

/* 統一左側統計欄位與其他頁面使用的 stat_card_value 樣式，
   保證字重與靠右對齊一致 */
.stat_card_value {
    font-size: 14px;
    font-weight: 600;
    color: inherit;
    text-align: right;
}

.stat_card_value.positive { color: inherit; }
.stat_card_value.negative { color: inherit; }

.monthly_table_container {
    background: white;
    overflow: hidden;
    border: 1px solid #e9ecef;
}

.monthly_table_container h4 {
    margin: 0;
    padding: 15px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    color: #333;
    font-size: 16px;
}

.monthly_records_table {
    width: 100%;
    border-collapse: collapse;
}

.monthly_records_table th {
    background: #f8f9fa;
    padding: 12px 20px;
    text-align: left;
    font-weight: 600;
    color: #333;
    border-bottom: 1px solid #e9ecef;
}

.monthly_records_table td {
    padding: 12px 20px;
    border-bottom: 1px solid #f1f3f4;
}

.monthly_records_table tr:last-child td {
    border-bottom: none;
}

.no_data {
    text-align: center;
    color: #666;
    font-style: italic;
    padding: 40px 20px;
    background: #f8f9fa;
    margin: 20px 0;
}

/* ========== 圖表十字線樣式 ========== */
.chart_container canvas {
    cursor: crosshair;
}

/* 防止在圖表上拖曳時選取文字 */
.chart_container {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* ========== 多因子評分可排序欄位 ========== */
.sortable_field {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.sortable_field:hover {
    background-color: #ecf6fe;
    color: #1976d2;
}

.sortable_field:active {
    background-color: #bbdefb;
}

/* 當前排序列高亮 */
.active_sort_row {
    background-color: #fff3cd;
}

.active_sort_row:hover {
    background-color: #ffe69c;
}

/* ========== END OF FILE ========== */