/* static/style.css */
:root {
    --bg-color: #1a1a2e;
    --primary-color: #16213e;
    --secondary-color: #0f3460;
    --accent-color: #e94560;
    --text-color: #e0e0e0;
    --positive-color: #f44336; /* Red - 涨 */
    --negative-color: #4caf50; /* Green - 跌 */
    --neutral-color: #ffeb3b;  /* Yellow */
    /* Factor Colors */
    --value-color: #2196f3;
    --momentum-color: #ff9800;
    --safety-color: #4caf50;
    --game-color: #9c27b0;
}

/* Navbar styles */
.navbar {
    width: 100%;
    background-color: var(--secondary-color);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1001; /* Higher than modal */
}

.nav-container {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    height: 60px;
}

.nav-brand {
    color: var(--accent-color);
    font-weight: bold;
    font-size: 20px;
    text-decoration: none;
}

.nav-menu {
    display: flex;
    gap: 20px;
}

.nav-item {
    color: var(--text-color);
    text-decoration: none;
    padding: 10px 15px;
    border-radius: 5px;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.nav-item:hover, .nav-item.active {
    background-color: var(--accent-color);
    color: white;
}


body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 20px;
    padding-top: 80px; /* Add padding to body to offset fixed navbar */
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
}

.container {
    width: 100%;
    max-width: 900px;
    background-color: var(--primary-color);
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

header, footer {
    text-align: center;
}

header h1 {
    color: var(--accent-color);
    margin-bottom: 5px;
}

header p {
    opacity: 0.8;
    margin-top: 0;
}

main {
    text-align: center;
    margin: 30px 0;
}

/* New Filter Styles */
.filter-controls {
    display: flex;
    justify-content: space-around;
    background-color: var(--secondary-color);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 30px;
    gap: 20px;
}
.slider-container {
    flex: 1;
    text-align: left;
}
.slider-container label {
    font-weight: 600;
    color: var(--text-color);
}
.slider-container label span {
    color: var(--neutral-color);
    font-size: 1.1em;
}
.slider {
    -webkit-appearance: none;
    width: 100%;
    height: 8px;
    background: #1a1a2e;
    outline: none;
    opacity: 0.9;
    transition: opacity .2s;
    border-radius: 4px;
    margin-top: 10px;
}
.slider:hover {
    opacity: 1;
}
.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent-color);
    cursor: pointer;
    border-radius: 50%;
}
.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--accent-color);
    cursor: pointer;
    border-radius: 50%;
}
.slider-desc {
    font-size: 12px;
    opacity: 0.7;
    margin-top: 8px;
}

#fetch-btn {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 12px 25px;
    font-size: 16px;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

#fetch-btn:hover {
    background-color: #ff637d;
    transform: translateY(-2px);
}

.loader {
    border: 6px solid var(--secondary-color);
    border-top: 6px solid var(--accent-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 30px auto;
}

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

.table-container {
    margin-top: 30px;
}

#cb-table, #garch-table, #dca-table, #dca-top-table {
    width: 100%;
    border-collapse: collapse;
}

#cb-table th, #cb-table td, #garch-table th, #garch-table td, #dca-table th, #dca-table td, #dca-top-table th, #dca-top-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--secondary-color);
}

#cb-table thead th, #garch-table thead th, #dca-table thead th, #dca-top-table thead th {
    background-color: var(--secondary-color);
    color: var(--text-color);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}

#cb-table tbody tr:nth-child(even), #garch-table tbody tr:nth-child(even), #dca-table tbody tr:nth-child(even), #dca-top-table tbody tr:nth-child(even) {
    background-color: #1e2a4a;
}

#cb-table tbody tr:hover, #garch-table tbody tr:hover, #dca-table tbody tr:hover, #dca-top-table tbody tr:hover {
    background-color: var(--secondary-color);
    cursor: pointer;
}

/* Custom styles for new data */
.premium-negative {
    color: var(--positive-color); /* Negative premium is good */
}

.return-rate {
    color: var(--positive-color);
    font-weight: bold;
}

.ai-score {
    color: var(--accent-color);
    font-weight: bold;
}

.status-high { color: var(--accent-color); font-weight: bold; }
.status-mid { color: var(--neutral-color); }
.status-low { color: var(--text-color); opacity: 0.8; }
.status-default { color: var(--text-color); opacity: 0.6; }
.status-buy { color: var(--accent-color); font-weight: 700; }
.status-watch { color: #000000; }
.status-cautious { color: var(--text-color); opacity: 0.8; }

/* GARCH-specific tweaks reuse same tokens */
#garch-table .premium-negative { color: var(--positive-color); }
#garch-table .profit-value { color: var(--positive-color); font-weight: bold; }

.error-cell {
    text-align: center;
    color: var(--accent-color);
    padding: 20px;
    font-style: italic;
}

.info-cell {
    text-align: center;
    padding: 20px;
    font-style: italic;
}

footer {
    margin-top: 30px;
    font-size: 12px;
    opacity: 0.6;
}

/* --- Detail Report Modal --- */
.modal {
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal-content {
    background-color: var(--primary-color);
    margin: auto;
    padding: 20px 30px;
    border: 1px solid var(--secondary-color);
    width: 96%;
    max-width: 750px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    position: relative;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from {opacity: 0; transform: scale(0.95);}
    to {opacity: 1; transform: scale(1);}
}

.close-button {
    color: #aaa;
    position: absolute;
    top: 15px;
    right: 25px;
    font-size: 28px;
    font-weight: bold;
}

.close-button:hover,
.close-button:focus {
    color: var(--accent-color);
    text-decoration: none;
    cursor: pointer;
}

#report-title {
    color: var(--accent-color);
    text-align: center;
    margin-top: 0;
    margin-bottom: 25px;
}

#report-body {
    line-height: 1.7;
}

.loader-small {
    border: 4px solid var(--secondary-color);
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

/* New Report Styles */
.report-header {
    text-align: center;
    border-bottom: 1px solid var(--secondary-color);
    padding-bottom: 15px;
    margin-bottom: 20px;
}
.report-header h3 {
    margin: 0;
    font-size: 22px;
    color: var(--text-color);
}
.report-header p {
    margin: 5px 0 0;
    font-size: 14px;
    opacity: 0.7;
}
.report-header span {
    color: var(--neutral-color);
}

.report-section {
    margin-bottom: 25px;
}
.report-section h4 {
    color: var(--accent-color);
    margin-bottom: 15px;
    border-left: 3px solid var(--accent-color);
    padding-left: 10px;
}

.core-data-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    text-align: center;
}
.core-data-grid div {
    background-color: var(--secondary-color);
    padding: 10px;
    border-radius: 5px;
}
.core-data-grid span {
    display: block;
    font-size: 13px;
    opacity: 0.7;
    margin-bottom: 5px;
}
.core-data-grid strong {
    font-size: 18px;
}

.scenario {
    background-color: #1e2a4a;
    padding: 15px;
    border-radius: 5px;
    margin-bottom: 15px;
    border-left: 3px solid transparent;
    transition: border-color 0.3s ease;
}
.scenario:hover {
    border-left-color: var(--neutral-color);
}
.scenario h5 {
    margin: 0 0 10px;
    color: var(--neutral-color);
}
.scenario p {
    margin: 5px 0;
    font-size: 14px;
    opacity: 0.9;
}
.scenario p strong {
    color: var(--text-color);
    opacity: 1;
}
.estimated-return {
    font-weight: bold;
    color: var(--positive-color);
}

.scenario-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.holding-period {
    font-weight: bold;
    color: var(--neutral-color);
}

/* New Factor Grid Styles */
.factors-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    text-align: center;
}
.factors-grid div {
    background-color: var(--secondary-color);
    padding: 10px;
    border-radius: 5px;
}
.factors-grid span {
    display: block;
    font-size: 13px;
    opacity: 0.7;
    margin-bottom: 5px;
}
.factors-grid strong {
    font-size: 18px;
}

/* New Trade Plan Styles */
.trade-plan-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.take-profit, .stop-loss {
    padding: 15px;
    border-radius: 5px;
}
.take-profit {
    background-color: rgba(76, 175, 80, 0.1);
    border: 1px solid var(--positive-color);
}
.stop-loss {
    background-color: rgba(244, 67, 54, 0.1);
    border: 1px solid var(--accent-color);
}
.trade-plan-grid h5 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 16px;
    display: flex;
    align-items: center;
}
.take-profit h5 { color: var(--positive-color); }
.stop-loss h5 { color: var(--accent-color); }

.trade-plan-grid ul {
    margin: 0;
    padding-left: 20px;
}
.trade-plan-grid li {
    font-size: 14px;
    margin-bottom: 8px;
    opacity: 0.9;
}
.icon {
    font-size: 20px;
    margin-right: 8px;
}

.summary p {
    background-color: var(--secondary-color);
    padding: 15px;
    border-radius: 5px;
    font-style: italic;
    white-space: pre-wrap; /* To respect line breaks from AI */
}

/* --- Arbitrage Page Specific Styles --- */
.arbitrage-content .content-section {
    background-color: var(--primary-color);
    padding: 20px;
    margin-bottom: 20px;
    border-radius: 8px;
    border: 1px solid var(--secondary-color);
}

.arbitrage-content h2 {
    color: var(--accent-color);
    border-bottom: 2px solid var(--accent-color);
    padding-bottom: 10px;
    margin-top: 0;
}

.arbitrage-content h3 {
    color: var(--neutral-color);
    margin-top: 20px;
}

.arbitrage-content p, .arbitrage-content li {
    line-height: 1.8;
    opacity: 0.9;
}

.arbitrage-content strong {
    color: var(--text-color);
    font-weight: 600;
}

.arbitrage-content ul {
    padding-left: 20px;
}

.formula-box, .arbitrage-plans code {
    background-color: var(--bg-color);
    padding: 15px;
    margin: 15px 0;
    border-radius: 5px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 16px;
    color: var(--positive-color);
    text-align: center;
    border: 1px dashed var(--secondary-color);
}

.arbitrage-plans {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 20px;
}

.plan-box {
    padding: 20px;
    border-radius: 8px;
}

.plan-box.positive-plan {
    border: 1px solid var(--negative-color);
    background: rgba(244, 67, 54, 0.05);
}

.plan-box.negative-plan {
    border: 1px solid var(--positive-color);
    background: rgba(76, 175, 80, 0.05);
}

.plan-box h3 {
    margin-top: 0;
    border-bottom: 1px solid;
    padding-bottom: 10px;
}
.plan-box.positive-plan h3 { color: var(--negative-color); }
.plan-box.negative-plan h3 { color: var(--positive-color); }

.plan-box ol, .plan-box ul {
    padding-left: 25px;
}

#arbitrage-table th, #arbitrage-table td, #garch-table th, #garch-table td {
    padding: 12px 15px;
    text-align: center;
    border-bottom: 1px solid var(--secondary-color);
}

.basis-positive {
    color: var(--positive-color);
    font-weight: bold;
}
.basis-negative {
    color: var(--negative-color);
    font-weight: bold;
}

.status-arbitrage {
    color: var(--positive-color);
    font-weight: bold;
    background-color: rgba(76, 175, 80, 0.1);
    padding: 5px 8px;
    border-radius: 4px;
}

.status-no-arbitrage {
    color: var(--text-color);
    opacity: 0.7;
}

.profit-value {
    color: var(--positive-color);
    font-weight: bold;
}

.modal-content.large {
    max-width: 850px;
}

.view-plan-btn {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 8px 15px;
    font-size: 14px;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

.view-plan-btn:hover {
    background-color: #ff637d;
    transform: translateY(-1px);
}

/* Plan Modal Styles */
#plan-body h2 {
    color: var(--accent-color);
    text-align: center;
    margin-top: 0;
}

.plan-section {
    margin-bottom: 20px;
}

.plan-section h3 {
    color: var(--neutral-color);
    border-bottom: 1px solid var(--secondary-color);
    padding-bottom: 8px;
    margin-bottom: 15px;
    font-size: 18px;
}

.plan-section ul {
    list-style: none;
    padding-left: 0;
}

.plan-section li {
    background-color: #1e2a4a;
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 10px;
    border-left: 3px solid var(--accent-color);
}

.capital-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
    text-align: center;
}

.capital-grid div {
    background-color: var(--secondary-color);
    padding: 15px;
    border-radius: 5px;
}

.capital-grid span {
    display: block;
    font-size: 14px;
    opacity: 0.7;
    margin-bottom: 5px;
}

.capital-grid strong {
    font-size: 20px;
    color: var(--neutral-color);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px; /* Add some space below the header */
}

.section-header h2 {
    margin: 0; /* Remove default margin from h2 */
}

.refresh-btn {
    background-color: var(--secondary-color);
    color: var(--text-color);
    border: 1px solid var(--accent-color);
    padding: 8px 15px;
    font-size: 14px;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
}

.refresh-btn:hover {
    background-color: var(--accent-color);
    color: white;
}

.refresh-btn .icon {
    margin-right: 8px;
    display: inline-block;
    transition: transform 0.5s ease;
}

.refresh-btn.loading .icon {
    animation: spin 1s linear infinite;
}

select, button {
    -webkit-appearance: none;
    appearance: none;
    border: 1px solid #555;
    background-color: #333;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: all .2s ease;
  border: 1px solid transparent;
}
.btn-primary {
  background: var(--accent-color);
  color: #fff;
  border-color: var(--accent-color);
}
.btn-primary:hover {
  background: #ff637d;
  border-color: #ff637d;
  transform: translateY(-1px);
}

/* Chips for sample ETF codes */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { background: #233357; color: #cdd6f4; padding: 6px 10px; border-radius: 14px; cursor: pointer; border: 1px solid #3b4b6a; font-size: 12px; }
.chip:hover { background: #2b4470; }

/* Detail sections */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.detail-card {
  background: var(--secondary-color);
  border-radius: 8px;
  padding: 12px;
}
.detail-card h4 { margin-top: 0; color: var(--neutral-color); }
.detail-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.detail-metrics div span { display:block; font-size:12px; opacity:0.7; }
.detail-metrics div strong { font-size:18px; }

/* Simple progress bar */
.progress { background: #223; border: 1px solid #445; height: 10px; border-radius: 6px; overflow: hidden; }
.progress > .bar { height: 100%; width: 0%; background: var(--accent-color); transition: width .3s ease; }

/* Tabs simple styles */
.tab-bar .btn { background:#2b4470; border-color:#3b4b6a; color:#cdd6f4; }
.tab-bar .btn.btn-primary { background: var(--accent-color); border-color: var(--accent-color); color:#fff; }
.dca-monthly th, .dca-monthly td { text-align:center; }

/* Execution details table styles */
.dca-execution {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  background: var(--primary-color);
  border-radius: 6px;
  overflow: hidden;
}
.dca-execution th {
  background: var(--secondary-color);
  color: var(--text-color);
  padding: 8px 6px;
  text-align: center;
  font-weight: 600;
  font-size: 11px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.dca-execution td {
  padding: 6px 4px;
  text-align: center;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 11px;
}
.dca-execution tbody tr:hover {
  background-color: rgba(255,255,255,0.05);
}
.dca-execution .positive {
  color: var(--positive-color);
  font-weight: 600;
}
.dca-execution .negative {
  color: var(--negative-color);
  font-weight: 600;
}

/* Execution summary styles */
.execution-summary {
  border-left: 4px solid var(--accent-color);
}
.execution-summary h5 {
  color: var(--accent-color) !important;
}

/* GARCH table refinements */
.table-container { overflow-x: auto; }
#garch-table { min-width: 860px; table-layout: auto; }
#garch-table th, #garch-table td { padding: 10px 12px; }
#garch-table thead th { border-bottom: 1px solid rgba(255,255,255,0.1); }
#garch-table td:nth-child(1) { text-align: left; }
#garch-table td:nth-child(2) { text-align: center; font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; font-size: 13px; }
#garch-table td:nth-child(3),
#garch-table td:nth-child(4) { text-align: right; }
#garch-table td:nth-child(5),
#garch-table td:nth-child(6),
#garch-table td:nth-child(7) { text-align: center; }
#garch-table tbody tr { height: 44px; }
#garch-table tbody tr:hover { background-color: #243356; }

/* Signal badges based on existing classes */
#garch-table td.status-high { color: #fff; background: rgba(233,69,96,0.15); border: 1px solid #e94560; border-radius: 14px; padding: 4px 10px; display: inline-block; }
#garch-table td.status-low { color: #fff; background: rgba(76,175,80,0.15); border: 1px solid #4caf50; border-radius: 14px; padding: 4px 10px; display: inline-block; }
#garch-table td.status-default { color: #d0d6e4; background: rgba(111,126,154,0.15); border: 1px solid #6f7e9a; border-radius: 14px; padding: 4px 10px; display: inline-block; }

/* Compact action button */
.view-garch-btn, .clear-cache-btn { padding: 6px 10px; font-size: 12px; border-radius: 6px; }

/* Numeric coloring */
#garch-table td .profit-value, #garch-table td.premium-negative { color: var(--positive-color); font-weight: 600; }

/* IV arbitrage table refinements (unified with GARCH) */
#cb-iv-table { min-width: 920px; table-layout: auto; }
#cb-iv-table th, #cb-iv-table td { padding: 10px 12px; }
#cb-iv-table thead th { border-bottom: 1px solid rgba(255,255,255,0.1); }
#cb-iv-table td:nth-child(1) { text-align: left; }
#cb-iv-table td:nth-child(2) { text-align: center; font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; font-size: 13px; }
#cb-iv-table td:nth-child(3),
#cb-iv-table td:nth-child(4),
#cb-iv-table td:nth-child(5),
#cb-iv-table td:nth-child(6),
#cb-iv-table td:nth-child(7),
#cb-iv-table td:nth-child(8) { text-align: right; }
#cb-iv-table td:nth-child(9),
#cb-iv-table td:nth-child(10) { text-align: center; }
#cb-iv-table tbody tr { height: 44px; }
#cb-iv-table tbody tr:hover { background-color: #243356; }
/* width constraint for badges */
#cb-iv-table td.status-buy,
#cb-iv-table td.status-watch,
#cb-iv-table td.status-cautious { display:inline-block; max-width: 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* pill styles */
#cb-iv-table td.status-buy { color:#fff; background: rgba(233,69,96,0.15); border:1px solid #e94560; border-radius:14px; padding:4px 10px; }
#cb-iv-table td.status-watch { color:#fff; background: rgba(255,235,59,0.12); border:1px solid #ffeb3b; border-radius:14px; padding:4px 10px; }
#cb-iv-table td.status-cautious { color:#d0d6e4; background: rgba(111,126,154,0.15); border:1px solid #6f7e9a; border-radius:14px; padding:4px 10px; }
#cb-iv-table td.status-default { color: #d0d6e4; background: rgba(111,126,154,0.15); border: 1px solid #6f7e9a; border-radius: 14px; padding: 4px 10px; display: inline-block; }
.iv-detail-btn, .iv-refresh-btn { padding: 6px 10px; font-size: 12px; border-radius: 6px; }
