:root {
  color-scheme: dark;
  --page: #101217;
  --surface: #191b23;
  --surface-raised: #22252f;
  --surface-soft: #14161d;
  --border: #30333f;
  --border-strong: #454957;
  --text: #f0f0f5;
  --text-muted: #bec0ca;
  --text-soft: #9296a5;
  --accent: #ad96ff;
  --accent-strong: #7856e8;
  --accent-wash: rgb(173 150 255 / 12%);
  --success: #75d8a7;
  --warning: #e9bd74;
  --danger: #ff9aa8;
  --focus: #cfbeff;
  --shadow: 0 16px 42px rgb(0 0 0 / 18%);
  --radius-lg: 16px;
  --radius-md: 11px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

html[data-theme="light"] {
  color-scheme: light;
  --page: #f4f5f9;
  --surface: #fff;
  --surface-raised: #fafaff;
  --surface-soft: #f0f1f6;
  --border: #dfe1eb;
  --border-strong: #c5c9d8;
  --text: #242531;
  --text-muted: #515567;
  --text-soft: #656a7c;
  --accent: #6246c8;
  --accent-strong: #583cc1;
  --accent-wash: rgb(98 70 200 / 9%);
  --success: #176f4b;
  --warning: #855d13;
  --danger: #ad2e49;
  --focus: #6348c9;
  --shadow: 0 14px 36px rgb(46 42 82 / 8%);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 88px; }
body {
  margin: 0;
  min-width: 0;
  background: radial-gradient(ellipse at 16% 0, rgb(123 91 223 / 8%), transparent 36rem), var(--page);
  color: var(--text);
  font-size: 16px;
  line-height: 1.55;
}
button, input, select, textarea { font: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button { color: inherit; }
svg { display: block; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; z-index: 30; top: 8px; left: 8px; padding: 10px 14px; transform: translateY(-160%); border-radius: 8px; background: var(--surface); }
.skip-link:focus { transform: none; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  padding: 0 max(24px, calc((100vw - 1480px) / 2));
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--page) 94%, transparent);
  backdrop-filter: blur(14px);
}
.brand { display: inline-flex; min-width: max-content; align-items: center; gap: 10px; }
.brand-mark { display: grid; width: 40px; height: 40px; place-items: center; border: 1px solid color-mix(in srgb, var(--accent) 32%, var(--border)); border-radius: 12px; background: var(--accent-wash); color: var(--accent); }
.brand-mark svg { width: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.brand-copy { display: grid; gap: 1px; line-height: 1.25; }
.brand-copy strong { font-size: 15px; }
.brand-copy small { color: var(--text-soft); font-size: 12px; }
.main-nav { display: flex; min-width: 0; align-items: center; justify-content: center; gap: clamp(8px, 2vw, 28px); }
.main-nav a { padding: 10px 2px; border-bottom: 2px solid transparent; color: var(--text-muted); font-size: 14px; font-weight: 540; white-space: nowrap; }
.main-nav a:hover, .main-nav a[aria-current="page"] { border-color: var(--accent); color: var(--text); }
.header-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 8px; }
.local-badge { display: inline-flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 99px; color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.local-badge i { width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.icon-button { display: grid; width: 44px; height: 44px; flex: 0 0 auto; place-items: center; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); cursor: pointer; }
.icon-button svg { width: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.moon-icon, html[data-theme="light"] .sun-icon { display: none; }
html[data-theme="light"] .moon-icon { display: block; }

.app-shell { width: min(1480px, calc(100% - 64px)); margin-inline: auto; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: var(--space-5); padding: 38px 0 22px; }
.page-heading h1 { margin: 0; font-size: clamp(34px, 4vw, 46px); line-height: 1.12; letter-spacing: -.045em; }
.page-heading p:not(.eyebrow) { max-width: 760px; margin: 8px 0 0; color: var(--text-muted); font-size: 16px; }
.eyebrow { margin: 0 0 6px; color: var(--text-soft); font-size: 12px; font-weight: 720; letter-spacing: .12em; }
.heading-actions, .button-row, .dialog-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.button { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; gap: 9px; padding: 0 16px; border: 1px solid transparent; border-radius: 10px; font-size: 15px; font-weight: 650; cursor: pointer; transition: background .16s ease, border-color .16s ease, transform .16s ease; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button-primary { background: var(--accent-strong); color: #fff; }
.button-primary:hover:not(:disabled) { background: var(--accent); color: #16131e; }
.button-secondary { border-color: var(--border-strong); background: var(--surface); color: var(--text); }
.button-secondary:hover:not(:disabled), .button-quiet:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-wash); }
.button-quiet { border-color: var(--border); background: transparent; color: var(--text-muted); }
.button-small { min-height: 36px; padding-inline: 11px; font-size: 13px; }
.button:disabled { opacity: .5; cursor: not-allowed; }

.page-section { padding: 25px 0 38px; scroll-margin-top: 78px; }
.section-title { display: flex; align-items: end; justify-content: space-between; gap: var(--space-4); margin-bottom: 18px; }
.section-title h2, .about-section h2 { margin: 0; font-size: clamp(24px, 2.6vw, 30px); line-height: 1.2; letter-spacing: -.03em; }
.section-title p:not(.eyebrow) { margin: 5px 0 0; color: var(--text-muted); font-size: 15px; }
.section-title .status-note { text-align: right; }
.overview-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat-card { display: grid; min-width: 0; gap: 4px; padding: 18px 20px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow); }
.stat-card span { color: var(--text-muted); font-size: 14px; }
.stat-card strong { font-size: 30px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-card small { color: var(--text-soft); font-size: 13px; }
.stat-accent { border-color: color-mix(in srgb, var(--accent) 42%, var(--border)); background: linear-gradient(125deg, var(--surface), var(--accent-wash)); }
.quick-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
.panel { min-width: 0; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow); }
.quick-card { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 16px; }
.quick-card:hover { border-color: var(--accent); }
.quick-number { color: var(--accent); font-size: 14px; font-weight: 750; }
.quick-card strong, .quick-card small { display: block; }
.quick-card strong { font-size: 16px; }
.quick-card small { color: var(--text-soft); font-size: 13px; }
.quick-card b { color: var(--accent); font-size: 20px; }

.upload-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.upload-card, .preview-panel, .result-panel, .chart-panel, .type-panel, .detail-panel, .advanced-panel, .manual-data { padding: 20px; }
.card-heading { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-heading > div { min-width: 0; }
.card-heading h3 { margin: 0; font-size: 19px; line-height: 1.3; }
.card-heading p:not(.eyebrow) { margin: 4px 0 0; color: var(--text-muted); font-size: 14px; }
.file-type-icon { display: grid; width: 42px; height: 42px; flex: 0 0 auto; place-items: center; border-radius: 11px; font-size: 12px; font-weight: 750; }
.csv-icon { background: color-mix(in srgb, var(--success) 13%, transparent); color: var(--success); }
.json-icon { background: var(--accent-wash); color: var(--accent); }
.drop-zone { position: relative; display: flex; min-height: 132px; flex-direction: column; align-items: center; justify-content: center; gap: 5px; padding: 15px; border: 1px dashed var(--border-strong); border-radius: 12px; background: var(--surface-soft); text-align: center; cursor: pointer; }
.drop-zone:hover, .drop-zone.is-over { border-color: var(--accent); background: var(--accent-wash); }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-zone:focus-within { outline: 3px solid var(--focus); outline-offset: 3px; }
.drop-zone strong { font-size: 16px; }
.drop-zone span, .drop-zone small { color: var(--text-muted); font-size: 13px; }
.selected-file { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; color: var(--text-muted); }
.selected-file span { overflow-wrap: anywhere; font-size: 13px; }
.selected-file button { width: 40px; height: 40px; flex: 0 0 auto; border: 1px solid var(--border); border-radius: 9px; background: transparent; cursor: pointer; font-size: 21px; }
.selected-file button:hover { color: var(--danger); }
.file-error { margin: 8px 0; color: var(--danger); font-size: 14px; overflow-wrap: anywhere; }
.inline-link { display: inline-flex; margin-top: 10px; color: var(--accent); font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }
.input-summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 14px 0; padding: 14px 18px; }
.input-summary p { margin: 0; color: var(--text-muted); }
.input-summary .button { min-height: 40px; font-size: 14px; }
.preview-panel { margin-top: 14px; }
.preview-panel .card-heading { margin-bottom: 10px; }
.subtle-count { color: var(--text-soft); font-size: 13px; text-align: right; }
.empty-inline { padding: 19px; border: 1px dashed var(--border); border-radius: 10px; color: var(--text-muted); font-size: 14px; text-align: center; }
.preview-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, .8fr); gap: 18px; }
.preview-grid h4 { display: flex; justify-content: space-between; gap: 8px; margin: 0 0 9px; font-size: 15px; }
.preview-grid h4 span { color: var(--text-soft); font-size: 13px; font-weight: 450; }
.table-scroll { width: 100%; overflow: auto; }
.preview-scroll { max-height: 260px; border: 1px solid var(--border); border-radius: 9px; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-soft); font-size: 13px; font-weight: 650; white-space: nowrap; }
td { color: var(--text-muted); font-size: 14px; }
tbody tr:last-child td { border-bottom: 0; }
.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.rule-list { display: grid; max-height: 260px; gap: 8px; overflow: auto; }
.rule-preview-item { padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-soft); }
.rule-preview-item strong { display: block; overflow-wrap: anywhere; font-size: 14px; }
.rule-preview-item span { color: var(--text-muted); font-size: 13px; overflow-wrap: anywhere; }
.panel-actions { display: flex; align-items: center; gap: 14px; margin-top: 16px; padding-top: 15px; border-top: 1px solid var(--border); }
.analysis-message { color: var(--text-muted); font-size: 14px; overflow-wrap: anywhere; }
.analysis-message.success { color: var(--success); }
.analysis-message.error { color: var(--danger); }

.admin-only { display: none; }
html[data-mode="admin"] .admin-only { display: block; }
html[data-mode="admin"] .advanced-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; margin-top: 16px; }
.advanced-panel { margin-top: 14px; }
.advanced-panel summary { display: flex; min-height: 44px; align-items: center; justify-content: space-between; gap: 15px; cursor: pointer; font-size: 16px; font-weight: 650; }
.advanced-panel summary span { color: var(--text-soft); font-size: 13px; font-weight: 450; }
.advanced-panel pre, .advanced-panel textarea { width: 100%; max-height: 300px; overflow: auto; padding: 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-soft); color: var(--text-muted); font: 13px/1.55 ui-monospace, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.advanced-panel textarea { resize: vertical; }
.advanced-panel label { display: block; margin-bottom: 8px; font-weight: 600; }
.advanced-panel p { color: var(--text-muted); font-size: 14px; }
.advanced-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.advanced-actions span { color: var(--text-soft); font-size: 13px; }

.manual-data { margin-top: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; align-items: end; }
label { color: var(--text-muted); font-size: 14px; font-weight: 560; }
label input, label select, label textarea, input, select, textarea {
  color: var(--text);
}
.form-grid input, .filter-grid input, .filter-grid select, .card-heading select, #rule-form input, #rule-form select {
  display: block; width: 100%; min-width: 0; min-height: 44px; margin-top: 5px; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface-soft);
}
.form-grid button { min-height: 44px; }
.observation-list { display: grid; gap: 5px; max-height: 190px; margin-top: 12px; overflow: auto; }
.observation-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; color: var(--text-muted); font-size: 13px; }
.observation-item button { min-width: 38px; min-height: 38px; border: 1px solid var(--border); border-radius: 7px; background: transparent; cursor: pointer; }
.observation-item span { min-width: 0; overflow-wrap: anywhere; }

.rule-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.rule-card { padding: 16px; }
.rule-card-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.rule-card h3 { margin: 0; overflow-wrap: anywhere; font-size: 17px; }
.rule-card p { margin: 5px 0 12px; color: var(--text-muted); font-size: 14px; overflow-wrap: anywhere; }
.rule-card-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.rule-card-actions .button { min-height: 38px; font-size: 13px; }
.empty-state { display: flex; min-height: 180px; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; }
.empty-state h3 { margin: 0 0 6px; font-size: 19px; }
.empty-state p { max-width: 580px; margin: 0 0 14px; color: var(--text-muted); font-size: 15px; }
.guide-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 16px; }
.guide-card { padding: 18px; }
.guide-index { color: var(--accent); font-size: 13px; font-weight: 750; letter-spacing: .08em; }
.guide-card h3 { margin: 9px 0; font-size: 19px; }
.guide-card p { margin: 7px 0; color: var(--text-muted); font-size: 15px; }
.guide-card .guide-footnote { padding-top: 8px; border-top: 1px solid var(--border); color: var(--text-soft); font-size: 13px; }
dialog { width: min(520px, calc(100% - 28px)); max-height: min(90vh, 820px); overflow: auto; padding: 22px; border: 1px solid var(--border-strong); border-radius: var(--radius-lg); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
dialog::backdrop { background: rgb(6 7 12 / 72%); backdrop-filter: blur(3px); }
#rule-form { display: grid; gap: 12px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.dialog-heading h3 { margin: 0; font-size: 23px; }
.ma-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-actions { justify-content: end; margin-top: 5px; }

.result-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0 0 14px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
.result-stats div { min-width: 0; padding: 14px 16px; border-right: 1px solid var(--border); }
.result-stats div:last-child { border: 0; }
.result-stats span { display: block; color: var(--text-muted); font-size: 13px; }
.result-stats strong { display: block; margin-top: 3px; overflow: hidden; font-size: 19px; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.results-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(310px, 370px); align-items: start; gap: 14px; }
.result-panel { padding: 16px; }
.filter-grid { display: grid; grid-template-columns: minmax(180px, 1.4fr) repeat(4, minmax(120px, .8fr)) auto; gap: 9px; align-items: end; margin-bottom: 14px; }
.filter-grid label { min-width: 0; font-size: 13px; }
.filter-grid input, .filter-grid select { min-height: 42px; font-size: 14px; }
.filter-grid .button { min-height: 42px; padding-inline: 11px; font-size: 13px; }
.alert-table-wrap { min-height: 150px; border-top: 1px solid var(--border); }
.alert-table { min-width: 760px; }
.alert-table thead th { position: sticky; top: 0; background: var(--surface); }
.alert-table tbody tr { cursor: pointer; }
.alert-table tbody tr:hover, .alert-table tbody tr[aria-selected="true"] { background: var(--accent-wash); }
.alert-table td:nth-child(1), .alert-table td:nth-child(2) { white-space: nowrap; font-variant-numeric: tabular-nums; }
.alert-table td:nth-child(3) { color: var(--text); font-weight: 630; }
.sort-button { border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; }
.alert-type-pill { display: inline-block; padding: 4px 8px; border: 1px solid currentColor; border-radius: 6px; color: var(--accent); font-size: 12px; font-weight: 650; white-space: nowrap; }
.alert-type-pill[data-type*="BEARISH"], .alert-type-pill[data-type*="DOWN"] { color: var(--success); }
.alert-table-wrap > .empty-state { min-height: 190px; }
.alert-table-wrap > .empty-state[hidden], .alert-table[hidden] { display: none; }
.results-footer { display: flex; justify-content: space-between; gap: 12px; padding-top: 12px; color: var(--text-soft); font-size: 13px; }
.results-aside { display: grid; min-width: 0; gap: 12px; }
.chart-panel, .type-panel, .detail-panel { padding: 16px; }
.chart-panel .card-heading label { min-width: 100px; max-width: 160px; }
.chart-panel select { min-height: 40px; }
.chart-description, .chart-point-detail { min-height: 24px; margin: 6px 0; color: var(--text-muted); font-size: 13px; }
.chart-area { position: relative; width: 100%; height: clamp(190px, 22vw, 280px); min-width: 0; }
.chart-placeholder { display: grid; height: 100%; place-items: center; padding: 20px; border: 1px dashed var(--border); border-radius: 9px; color: var(--text-muted); text-align: center; font-size: 14px; }
.chart-svg { width: 100%; height: 100%; overflow: visible; }
.chart-svg text { fill: var(--text-soft); font-family: inherit; font-size: 11px; }
.chart-gridline { stroke: var(--border); stroke-width: 1; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.chart-area-fill { fill: url(#chartFill); }
.chart-alert-dot { fill: var(--success); stroke: var(--surface); stroke-width: 2; vector-effect: non-scaling-stroke; cursor: pointer; }
.chart-point { fill: var(--accent); stroke: var(--surface); stroke-width: 1.5; vector-effect: non-scaling-stroke; cursor: pointer; }
.chart-point:focus { stroke: var(--focus); stroke-width: 3; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; padding-top: 8px; color: var(--text-muted); font-size: 13px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 13px; height: 3px; background: var(--accent); }
.chart-legend .legend-alert { width: 9px; height: 9px; border-radius: 50%; background: var(--success); }
.breakdown-empty, .detail-empty { color: var(--text-muted); font-size: 14px; }
.breakdown-row { display: grid; grid-template-columns: minmax(74px, auto) minmax(45px, 1fr) 30px; align-items: center; gap: 10px; margin-top: 10px; color: var(--text-muted); font-size: 13px; }
.breakdown-track { height: 7px; overflow: hidden; border-radius: 99px; background: var(--surface-soft); }
.breakdown-track i { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.breakdown-row[data-type*="BEARISH"] .breakdown-track i, .breakdown-row[data-type*="DOWN"] .breakdown-track i { background: var(--success); }
.breakdown-row b { text-align: right; font-variant-numeric: tabular-nums; }
.detail-block { display: grid; gap: 10px; }
.detail-event { color: var(--accent); font-size: 15px; font-weight: 700; }
.detail-rule { color: var(--text-muted); font-size: 14px; overflow-wrap: anywhere; }
.detail-facts { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, auto); gap: 6px 10px; color: var(--text-soft); font-size: 13px; }
.detail-facts b { color: var(--text-muted); text-align: right; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.detail-note { margin: 0; color: var(--text-soft); font-size: 13px; }
.about-section { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); align-items: center; gap: 28px; padding-bottom: 54px; }
.about-section > div:first-child > p:not(.eyebrow) { max-width: 760px; color: var(--text-muted); font-size: 16px; }
.about-section h2 { margin-bottom: 14px; }
.architecture-card { padding: 21px; }
.architecture-flow { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; margin: 14px 0; }
.architecture-flow span { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-soft); color: var(--text-muted); font-size: 13px; }
.architecture-flow b { color: var(--accent); }
.architecture-card > p:last-child { margin: 0; color: var(--text-muted); font-size: 14px; }
.page-footer { display: flex; min-height: 70px; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 12px max(24px, calc((100vw - 1480px) / 2)); border-top: 1px solid var(--border); color: var(--text-soft); font-size: 13px; }
.page-footer a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }

@media (max-width: 1150px) {
  .topbar { flex-wrap: wrap; justify-content: space-between; gap: 4px 16px; padding-block: 8px; }
  .main-nav { order: 3; width: 100%; justify-content: start; overflow-x: auto; }
  .main-nav a { min-height: 44px; padding-inline: 10px; }
  .filter-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .results-layout { grid-template-columns: minmax(0, 1fr) minmax(280px, .65fr); }
}
@media (max-width: 850px) {
  .app-shell { width: min(100% - 40px, 760px); }
  .page-heading { align-items: start; flex-direction: column; }
  .heading-actions { width: 100%; }
  .results-layout { grid-template-columns: minmax(0, 1fr); }
  .results-aside { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-panel { grid-column: 1 / -1; }
  .overview-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quick-actions { grid-template-columns: 1fr; }
  .input-summary { align-items: start; flex-direction: column; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .topbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 8px; padding-inline: 12px; }
  .brand-mark { width: 36px; height: 36px; }
  .brand-copy strong { font-size: 14px; }
  .brand-copy small { font-size: 11px; }
  .header-actions { gap: 5px; }
  .local-badge { width: 34px; height: 34px; justify-content: center; padding: 0; font-size: 0; }
  .mode-toggle { min-height: 38px; padding-inline: 9px; font-size: 12px; }
  .icon-button { width: 40px; height: 40px; }
  .main-nav { grid-column: 1 / -1; justify-content: space-between; gap: 2px; }
  .main-nav a { padding-inline: 8px; font-size: 13px; }
  .app-shell { width: calc(100% - 28px); }
  .page-heading { padding-top: 25px; }
  .page-heading h1 { font-size: clamp(31px, 10vw, 40px); }
  .page-heading p:not(.eyebrow) { font-size: 15px; }
  .heading-actions > * { flex: 1 1 auto; }
  .page-section { padding-block: 20px 30px; }
  .section-title { align-items: start; flex-direction: column; }
  .section-title .status-note { text-align: left; }
  .overview-stats { gap: 9px; }
  .stat-card { padding: 13px; }
  .stat-card strong { font-size: 25px; }
  .upload-grid, .preview-grid, .rule-cards, .guide-grid, .about-section { grid-template-columns: minmax(0, 1fr); }
  .upload-card, .preview-panel, .result-panel, .chart-panel, .type-panel, .detail-panel, .advanced-panel, .manual-data { padding: 15px; }
  .input-summary .button-row { width: 100%; }
  .input-summary .button-row > * { flex: 1 1 auto; }
  .panel-actions { align-items: start; flex-direction: column; }
  .panel-actions .button { width: 100%; }
  .subtle-count { text-align: right; }
  .results-aside { grid-template-columns: minmax(0, 1fr); }
  .chart-panel { grid-column: auto; }
  .result-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-stats div { padding: 10px; border-bottom: 1px solid var(--border); }
  .result-stats div:nth-child(2) { border-right: 0; }
  .result-stats div:nth-child(n+3) { border-bottom: 0; }
  .result-stats strong { font-size: 16px; }
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-grid label:first-child { grid-column: 1 / -1; }
  .filter-grid .button { width: 100%; }
  .results-footer { align-items: start; flex-direction: column; }
  .advanced-grid, html[data-mode="admin"] .advanced-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .page-footer { align-items: start; flex-direction: column; padding: 16px; }
}
@media (max-width: 360px) {
  .app-shell { width: calc(100% - 20px); }
  .brand-copy small { display: none; }
  .header-actions { gap: 4px; }
  .mode-toggle { min-height: 38px; padding-inline: 7px; font-size: 11px; }
  .main-nav a { padding-inline: 5px; font-size: 12px; }
  .heading-actions { align-items: stretch; flex-direction: column; }
  .filter-grid { grid-template-columns: minmax(0, 1fr); }
  .filter-grid label:first-child { grid-column: auto; }
  .result-stats span { font-size: 12px; }
  .card-heading { align-items: start; }
  .subtle-count { max-width: 43%; overflow-wrap: anywhere; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
