:root {
  --brand-red: #941c1f;
  --brand-red-soft: rgba(148, 28, 31, 0.08);
  --chart-blue: #3264b5;
  --positive: #15803d;
  --negative: #941c1f;
  --bg: #ffffff;
  --surface: #f3f4f6;
  --surface-hover: #f9fafb;
  --border: #e5e7eb;
  --grid-line: #eef0f3;
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: var(--bg); color: var(--text-primary); font-family: var(--font-sans); font-size: 12px; line-height: 1.3; -webkit-font-smoothing: antialiased; }
body { display: grid; justify-items: center; align-items: start; }

.widget { display: grid; grid-template-rows: auto 1fr; width: 300px; height: 200px; max-width: 100vw; max-height: 100vh; background: var(--bg); border: 1px solid var(--border); overflow: hidden; }

/* Header & Tabs */
.widget-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 30px; padding-inline: 8px; background: var(--bg); border-block-end: 1px solid var(--border); }
.tablist { display: flex; align-items: stretch; gap: 2px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.tablist::-webkit-scrollbar { display: none; }
.tab-btn { position: relative; flex: none; appearance: none; background: transparent; border: 0; padding: 6px 8px; margin: 0; font-family: inherit; font-size: 11.5px; font-weight: 600; color: var(--text-secondary); cursor: pointer; white-space: nowrap; min-block-size: 28px; transition: color 0.15s ease; }
.tab-btn:hover { color: var(--text-primary); }
.tab-btn[aria-selected="true"] { color: var(--brand-red); }
.tab-btn[aria-selected="true"]::after { content: ""; position: absolute; inset: auto 4px 0; border-block-end: 2.5px solid var(--brand-red); }
.tab-btn:focus-visible, .footer-logo-link:focus-visible, .news-link:focus-visible { outline: 2px solid var(--brand-red); outline-offset: -2px; }

/* Panels container */
.panels { display: grid; grid-template-rows: minmax(0, 1fr); min-height: 0; overflow: hidden; }
.panel { grid-area: 1 / 1; height: 100%; min-height: 0; overflow: hidden; }
.panel[hidden] { display: none; }
.panel-inner { height: 100%; min-height: 0; }

/* Tab 1: ASE Chart & Summary */
.ase-layout { display: grid; grid-template-rows: 1fr auto; height: 100%; min-height: 0; }
.chart-wrap { position: relative; min-height: 0; padding: 4px 6px 0 4px; display: flex; align-items: stretch; }
.ase-svg { display: block; width: 100%; height: 100%; overflow: visible; touch-action: pan-y; }
.chart-status { position: absolute; inset: 0; display: grid; place-items: center; font-size: 11px; color: var(--text-muted); background: rgba(255, 255, 255, 0.85); pointer-events: none; }
.chart-status[hidden] { display: none; }
.chart-tooltip { position: absolute; top: 4px; left: 0; z-index: 2; padding: 2px 6px; border-radius: 3px; background: rgba(17, 24, 39, 0.92); color: #ffffff; font-size: 10.5px; font-variant-numeric: tabular-nums; white-space: nowrap; pointer-events: none; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.16); }
.chart-tooltip[hidden] { display: none; }

.ase-footer { padding: 2px 8px 4px; }
.ase-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.ase-table thead tr { background: var(--surface); }
.ase-table th { padding: 3px 6px; font-size: 10.5px; font-weight: 600; color: var(--text-secondary); text-align: left; white-space: nowrap; }
.ase-table th:nth-child(2), .ase-table td:nth-child(2) { text-align: center; }
.ase-table th:last-child, .ase-table td:last-child { text-align: right; }
.ase-table td { padding: 3px 6px 1px; font-size: 12.5px; font-weight: 700; color: var(--text-primary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ase-table td.is-positive { color: var(--positive); }
.ase-table td.is-negative { color: var(--negative); }

.ase-meta { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding-top: 2px; }
.ase-updated { text-align: left; font-size: 8.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.footer-logo-link { flex: none; display: inline-flex; align-items: center; line-height: 0; border-radius: 2px; }
.footer-logo { display: block; width: 65px; height: 14px; object-fit: contain; }

/* Tab 2: News List */
.news-layout { height: 100%; overflow: hidden; }
.news-status { display: grid; place-items: center; height: 100%; font-size: 11.5px; color: var(--text-muted); }
.news-status[hidden] { display: none; }
.news-list { list-style: none; margin: 0; padding: 0; height: 100%; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #d1d5db transparent; }
.news-item { border-block-end: 1px solid var(--border); }
.news-item:last-child { border-block-end: 0; }
.news-link { display: grid; grid-template-columns: auto 1fr; align-items: baseline; gap: 8px; padding: 6px 10px; text-decoration: none; color: var(--text-primary); transition: background-color 0.12s ease, color 0.12s ease; }
.news-link:hover { background: var(--surface-hover); color: var(--brand-red); }
.news-time { font-size: 10.5px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--brand-red); background: var(--brand-red-soft); padding: 1px 5px; border-radius: 3px; white-space: nowrap; }
.news-title { font-size: 11.5px; font-weight: 500; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Compact adjustments for 300x200px widget */
@media (max-width: 340px) {
  .tab-btn { padding: 5px 6px; font-size: 11px; min-block-size: 26px; }
  .ase-table th { padding: 2px 5px; font-size: 10px; }
  .ase-table td { padding: 2px 5px 1px; font-size: 11.5px; }
}
