@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=DM+Sans:wght@400;500;600;700&family=Noto+Sans+TC:wght@400;500;600;700&display=swap');

/* View visibility must take precedence over flex/grid layout rules. */
[hidden] { display: none !important; }

.search-option, .recent-stock { text-decoration: none; }
.search-option { display: flex; justify-content: space-between; gap: 12px; }
.search-option[aria-selected="true"] { background: #273a57; }
#page-root { min-width: 0; }
button:disabled { opacity: .5; cursor: wait; }

:root {
  color-scheme: dark;
  font-family: 'DM Sans', 'Noto Sans TC', sans-serif;
  color: #e7edf7;
  background: #0b1220;
  font-synthesis: none;
  --muted: #8794a8;
  --line: #263247;
  --panel: #111b2b;
  --red: #f06a65;
  --green: #36c99a;
  --accent: #6c9cff;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 340px; min-height: 100vh; background: radial-gradient(ellipse at 50% -30%, #203453 0, transparent 55%), #0b1220; }
button, input { font: inherit; }
.app-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; display: flex; flex-direction: column; height: 100vh; padding: 21px 12px; border-right: 1px solid #202c3e; background: #0d1625; }
.brand { display: flex; gap: 14px; align-items: center; color: #edf3ff; text-decoration: none; font-size: 18px; font-weight: 700; letter-spacing: .2px; }
.brand small { display: block; margin-top: 3px; color: var(--muted); font: 10px 'DM Mono', monospace; letter-spacing: 1.4px; }
.brand-icon { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 10px; background: #6c9cff; color: #081326; font-weight: 700; }
.nav-caption { margin: 0 10px 10px; color: #718099; font: 9px 'DM Mono', monospace; letter-spacing: 1.4px; }
.primary-nav { display: grid; gap: 6px; }
.stock-nav-group { display: grid; gap: 4px; }
.nav-link { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 54px; padding: 15px 16px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: #9eacc0; text-align: left; cursor: pointer; font-size: 13px; }
.stock-nav-group > .nav-link { width: 100%; }
.nav-link:hover { background: #152238; color: #e7edf7; }
.nav-link.active { border-color: #293a56; background: #192943; color: #dce8fb; }
.nav-icon { display: grid; width: 19px; height: 19px; place-items: center; color: #85aaff; font-size: 17px; }
.recent-stocks { display: grid; gap: 2px; max-height: 300px; overflow-y: auto; margin-left: 18px; padding-left: 8px; border-left: 1px solid #263247; }
.recent-stocks[hidden] { display: none; }
.recent-stock { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 32px; padding: 5px 8px; border: 1px solid transparent; border-radius: 5px; background: transparent; color: #9eacc0; text-align: left; cursor: pointer; }
.recent-stock:hover { border-color: #293a56; background: #152238; color: #e7edf7; }
.recent-stock-code { flex: 0 0 48px; color: #85aaff; font: 10px 'DM Mono', monospace; }
.recent-stock-name { overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid #202c3e; color: #718099; font-size: 10px; line-height: 1.8; }
.app-shell { width: min(1180px, calc(100% - 64px)); margin: 0 auto; padding: 24px 0 30px; }
.instrument-head { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: end; gap: 24px; padding: 30px 2px 24px; }
.eyebrow { color: var(--muted); font: 10px 'DM Mono', monospace; letter-spacing: 1.3px; }
h1 { margin: 8px 0 10px; font-size: 27px; font-weight: 600; letter-spacing: -.4px; }
.symbol { margin-left: 10px; color: #96a7c1; font: 500 15px 'DM Mono', monospace; }
.instrument-meta { display: flex; gap: 9px; align-items: center; color: var(--muted); font-size: 11px; }
.market-tag { padding: 3px 6px; border: 1px solid #3a4b65; border-radius: 4px; color: #a9bddc; font: 9px 'DM Mono', monospace; }
.last-price { justify-self: end; text-align: right; }
.last-price>div { display: flex; gap: 8px; align-items: baseline; }
#close-price { font: 500 32px 'DM Mono', monospace; letter-spacing: -1px; }
.currency { color: var(--muted); font: 10px 'DM Mono', monospace; }
.change { display: block; margin-top: 4px; color: var(--muted); font: 11px 'DM Mono', monospace; }
.positive { color: var(--red) !important; }
.negative { color: var(--green) !important; }
.toolbar { display: flex; flex-wrap: wrap; justify-content: flex-start; align-items: center; gap: 8px; margin-bottom: 14px; }
.search { display: flex; align-items: center; gap: 10px; min-width: 240px; height: 40px; padding: 0 10px; border: 1px solid #35445c; border-radius: 7px; background: #111b2b; color: var(--muted); font-size: 11px; }
.search input { width: 70px; border: 0; outline: 0; background: transparent; color: #edf3ff; font: 12px 'DM Mono', monospace; }
.search button,.periods button { border: 1px solid transparent; border-radius: 6px; cursor: pointer; }
.search button { margin-left: auto; padding: 6px 10px; background: #223552; color: #c6d8f5; font-size: 11px; }
.sidebar .search { width: 100%; min-width: 0; height: 53px; margin: 21px 0 12px; padding: 0 12px; flex-wrap: nowrap; gap: 10px; }
.sidebar .search-icon { flex: 0 0 16px; width: 16px; height: 16px; fill: none; stroke: #8794a8; stroke-linecap: round; stroke-width: 1.8; }
.sidebar .search input { flex: 1; min-width: 0; width: 100%; padding: 0; font: 13px 'DM Sans', 'Noto Sans TC', sans-serif; }
.sidebar .search input::placeholder { color: #8794a8; opacity: 1; }
.sidebar .search[hidden] { display: none; }
.instrument-search { position: relative; z-index: 10; }
.search-results { position: absolute; z-index: 20; top: calc(100% + 6px); left: 0; display: grid; width: 100%; max-height: min(360px, 55vh); overflow-y: auto; padding: 5px; border: 1px solid #35445c; border-radius: 8px; background: #111b2b; box-shadow: 0 12px 28px #0008; }
.search-results[hidden] { display: none; }
.search-option { display: grid; gap: 4px; width: 100%; margin: 0 !important; padding: 9px 10px !important; border: 0 !important; border-radius: 5px !important; background: transparent !important; color: #e7edf7 !important; text-align: left; cursor: pointer; }
.search-option:hover,.search-option.active,.search-option[aria-selected="true"] { background: #1c2c45 !important; }
.search-option-name { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.search-option-detail { color: #8794a8; font: 10px 'DM Mono', monospace; }
.search-note { padding: 10px; color: #8794a8; font-size: 11px; }
.periods { display: flex; flex-wrap: wrap; gap: 3px; padding: 3px; border: 1px solid #263247; border-radius: 8px; background: #101a29; }
.periods button { padding: 7px 12px; background: transparent; color: #95a2b6; font-size: 11px; }
.periods button.selected { background: #273a57; color: #e8f0ff; }
.ma-controls button.selected { color: var(--ma-color); box-shadow: inset 0 -2px var(--ma-color); }
/* Distribute the available chart width; wrap whole control groups first. */
#chart-toolbar { align-items: stretch; }
#chart-toolbar > .periods { flex: 4 1 200px; min-width: 0; max-width: 100%; flex-wrap: nowrap; order: 0; }
#chart-toolbar > .periods:nth-child(2) { flex: 3 1 132px; }
#chart-toolbar > .ma-controls { flex: 6 1 330px; }
#chart-toolbar > .periods:last-child { flex: 1.5 1 86px; }
#chart-toolbar .periods button { flex: 1 1 0; min-width: 0; min-height: 36px; padding: 7px 6px; white-space: nowrap; }
.chart-card,.table-card { border: 1px solid var(--line); border-radius: 10px; background: linear-gradient(145deg, #121d2e, #101927); }
.chart-card { padding: 12px 18px 11px; }
.chart-title,.table-heading { display: flex; align-items: center; justify-content: space-between; }
h2 { margin: 0; font-size: 14px; font-weight: 600; }
.chart-title>div:first-child>span,.table-heading>div>span { display: inline-block; margin-top: 5px; color: var(--muted); font-size: 10px; }
.legend { display: flex; align-items: center; gap: 6px; color: #9ba8ba; font-size: 10px; }
.up-key,.down-key { width: 8px; height: 8px; margin-left: 7px; border-radius: 2px; background: var(--red); }
.down-key { background: var(--green); }
.market-turnover-key { width: 8px; height: 8px; margin-left: 7px; border-radius: 2px; background: #6e9dff; }
.ohlc { display: flex; flex-wrap: wrap; gap: 14px; min-height: 16px; margin-top: 15px; color: #aebbd0; font: 10px 'DM Mono', monospace; }
.header-ohlc { justify-content: center; align-self: center; gap: 16px; margin-top: 0; font-size: 12px; }
.header-ohlc span { white-space: nowrap; }
.chart-wrap { position: relative; height: 390px; margin-top: 0; }
.chart-wrap canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
.indicator-card { margin-top: 12px; }
.indicator-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 3px 0 8px; }
.indicator-toolbar select { max-width: 100%; border: 1px solid #354762; border-radius: 6px; background: #101b2c; color: #dce6f5; padding: 7px 30px 7px 10px; font: inherit; font-size: 12px; cursor: pointer; }
.indicator-toolbar select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.indicator-values { display: flex; flex-wrap: wrap; gap: 14px; font: 11px 'DM Mono', monospace; }
.indicator-wrap { height: 170px; }
.indicator-wrap canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
.chart-message { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; color: #a4b2c8; text-align: center; font-size: 12px; }
.chart-message[hidden] { display: none; }
.chart-tooltip { position: absolute; z-index: 2; display: grid; gap: 5px; min-width: 175px; padding: 10px 12px; border: 1px solid #40516c; border-radius: 7px; background: #0c1422ee; color: #dce6f5; pointer-events: none; font: 10px 'DM Mono', monospace; box-shadow: 0 8px 26px #0005; }
.chart-tooltip[hidden] { display: none; }
.chart-tooltip b { color: #a9c3ed; font-weight: 500; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 13px; }
.stats-grid article { display: grid; gap: 12px; padding: 15px; border: 1px solid var(--line); border-radius: 8px; background: #111b2b; }
.stats-grid article span { color: var(--muted); font-size: 10px; }
.stats-grid article b { font: 500 16px 'DM Mono', monospace; }
.stats-grid.fundamental-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.fundamental-metrics article { position: relative; }
.metric-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.metric-info { display: inline-flex; }
.metric-info-trigger { display: inline-grid; place-items: center; width: 18px; height: 18px; padding: 0; border: 1px solid #526986; border-radius: 50%; background: transparent; color: #a9c3ed; cursor: help; font: 600 11px sans-serif; }
.metric-info-trigger:focus-visible { outline: 2px solid #65b5ff; outline-offset: 3px; }
.stats-grid .metric-info-tooltip { display: none; position: absolute; z-index: 10; left: 8px; right: 8px; top: 32px; padding: 12px; border: 1px solid #40516c; border-radius: 8px; background: #0c1422; color: #dce6f5; box-shadow: 0 8px 26px #0005; font: 12px/1.7 sans-serif; white-space: pre-line; overflow-wrap: anywhere; }
.metric-info:hover .metric-info-tooltip, .metric-info:focus-within .metric-info-tooltip { display: block; }
@media (max-width: 540px) { .stats-grid.fundamental-metrics { grid-template-columns: 1fr; } }
.table-card { margin-top: 14px; padding: 17px 18px 10px; }
.stock-details,.market-details { margin-top: 14px; }
.history-plot-legend { display: flex; flex-wrap: wrap; gap: 20px; margin: 14px 0 8px; font-size: 12px; }
.history-plot-heading { flex-wrap: wrap; gap: 12px; }
.history-plot-heading .periods { max-width: 100%; }
.history-plot-readout { display: flex; flex-wrap: wrap; gap: 12px; min-height: 20px; color: var(--muted); font: 11px 'DM Mono', monospace; }
.history-plot-wrap { position: relative; height: 260px; }
.history-plot-wrap canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
.tabs { display: flex; gap: 5px; overflow-x: auto; padding: 4px; border: 1px solid var(--line); border-radius: 9px; background: #101a29; }
.tab-button { flex: 0 0 auto; padding: 9px 16px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: #95a2b6; cursor: pointer; font-size: 11px; }
.tab-button:hover { color: #e7edf7; }
.tab-button.active { border-color: #304362; background: #223552; color: #e8f0ff; }
.tab-panel { margin-top: 12px; }
.tab-panel[hidden],.market-details[hidden],.stock-details[hidden] { display: none; }
.planned-panel,.market-details { padding: 18px; border: 1px solid var(--line); border-radius: 10px; background: linear-gradient(145deg, #121d2e, #101927); }
.planned-panel { min-height: 175px; }
.planned-panel h2 { margin-top: 15px; }
.planned-panel p { max-width: 650px; margin: 9px 0 0; color: var(--muted); font-size: 12px; line-height: 1.8; }
.section-title { display: flex; justify-content: space-between; align-items: center; }
.section-title h2 { margin: 0; }
.section-title>div>span { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; }
.today-market { margin-top: 24px; }
.table-pagination { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 12px; padding: 16px 0 6px; color: var(--muted); font-size: 12px; }
.table-pagination button { padding: 7px 12px; border: 1px solid #35445c; border-radius: 6px; background: #17243a; color: #c6d8f5; cursor: pointer; }
.today-summary-grid { margin-top: 12px; }
.today-summary-grid article b { font-size: 14px; }
.today-table th button { padding: 0; border: 0; background: transparent; color: var(--muted); cursor: pointer; font: 9px 'DM Mono', monospace; }
.today-table th button:hover { color: #e7edf7; }
.today-table th:nth-child(2),.today-table td:nth-child(2) { text-align: left; }
.sort-indicator { color: #9bbcff; }
.today-table tbody tr:hover { background: #17243a; }
.daily-stock-link { color: #a9c8ff; text-decoration: none; }
.daily-stock-link:hover { color: #e7edf7; text-decoration: underline; }
.daily-market-tag { margin-left: 8px; vertical-align: middle; }
.planned-badge { display: inline-flex; align-items: center; padding: 5px 8px; border: 1px solid #394b68; border-radius: 20px; color: #9bb5dc; font-size: 9px; white-space: nowrap; }
.market-source-badge { display: inline-flex; align-items: center; padding: 5px 8px; border: 1px solid #294d83; border-radius: 20px; color: #a9c8ff; font-size: 9px; white-space: nowrap; }
.market-stats-grid article b { font-size: 14px; }
.market-stats-table { margin-top: 12px; }
.planned-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 15px; }
.planned-card { display: grid; gap: 8px; min-height: 112px; padding: 14px; border: 1px solid #263247; border-radius: 8px; background: #111b2b; }
.planned-card span { color: #9eacc0; font-size: 10px; }
.planned-card b { font-size: 12px; font-weight: 500; }
.planned-card small { color: #75839a; font-size: 10px; }
.table-note { color: var(--muted); font-size: 10px; }
.table-scroll { overflow: auto; margin-top: 14px; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th { padding: 0 10px 10px; color: var(--muted); text-align: right; font: 9px 'DM Mono', monospace; font-weight: 400; }
td { padding: 10px; border-top: 1px solid #253146; color: #ccd6e6; text-align: right; font: 10px 'DM Mono', monospace; }
th:first-child,td:first-child { padding-left: 0; text-align: left; }
.empty { padding: 24px; color: var(--muted); text-align: center; }
footer { display: flex; justify-content: space-between; padding: 19px 2px 0; color: #748197; font: 9px 'DM Mono', monospace; }

@media (max-width: 860px) {
  .instrument-head { grid-template-columns: minmax(0, 1fr) auto; gap: 16px; }
  .header-ohlc { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; }
  .app-layout { grid-template-columns: 1fr; }
  .sidebar { position: sticky; z-index: 5; top: 0; height: auto; padding: 10px 16px; border-right: 0; border-bottom: 1px solid #202c3e; }
  .sidebar .search { width: 100%; margin: 0 0 8px; flex-wrap: nowrap; }
  .sidebar .brand { display: flex; }
  .nav-caption { margin: 0 10px 4px; }
  .sidebar-foot { display: none; }
  .primary-nav { display: flex; gap: 8px; }
  .nav-link { justify-content: center; width: auto; min-width: 96px; padding: 9px 14px; }
  .stock-nav-group { flex: 0 0 116px; }
  .recent-stocks { max-height: 112px; margin-left: 8px; padding-left: 5px; }
  .recent-stock { min-height: 28px; padding: 4px 5px; }
  .recent-stock-code { flex-basis: 42px; }
  .app-shell { width: min(100% - 32px, 1180px); padding-top: 15px; }
}

@media (max-width: 700px) {
  .instrument-head { padding-top: 24px; }
  h1 { font-size: 22px; }
  #close-price { font-size: 25px; }
  .toolbar { flex-wrap: wrap; }
  .search { flex: 1; }
  .periods { order: 3; flex: 1; justify-content: space-between; }
  .periods button { padding: 7px 9px; }
  .chart-wrap { height: 300px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .chart-card,.table-card { padding-right: 12px; padding-left: 12px; }
  .ohlc { gap: 8px; font-size: 9px; }
  .planned-grid { grid-template-columns: 1fr; }
  .planned-card { min-height: 94px; }
}

@media (max-width: 430px) {
  #chart-toolbar > .ma-controls { flex-wrap: wrap; }
  #chart-toolbar .ma-controls button { flex: 1 0 calc(33.333% - 3px); }
  .instrument-head { align-items: start; gap: 8px; }
  .last-price { padding-top: 4px; }
  .symbol { margin-left: 5px; font-size: 12px; }
  .chart-wrap { height: 250px; }
  .legend { font-size: 9px; }
  .table-note { display: none; }
}
