:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-subtle: #f8fafb;
  --ink: #17202a;
  --muted: #697586;
  --line: #dce2e8;
  --line-strong: #c4cdd6;
  --teal: #0e8f7b;
  --teal-soft: #e4f5f1;
  --red: #d9485f;
  --red-soft: #fcebef;
  --amber: #c88905;
  --amber-soft: #fff5d8;
  --blue: #2e6fbb;
  --blue-soft: #eaf2fb;
  --shadow: 0 8px 22px rgba(23, 32, 42, 0.07);
  --nav-width: 176px;
  --topbar-height: 72px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
}

button,
select {
  font: inherit;
}

button,
select,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(46, 111, 187, 0.32);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  right: 8px;
  padding: 10px 14px;
  transform: translateY(-150%);
  border-radius: 4px;
  background: var(--ink);
  color: #fff;
}

.skip-link:focus {
  transform: translateY(0);
}

.topbar {
  position: fixed;
  z-index: 20;
  inset: 0 0 auto 0;
  height: var(--topbar-height);
  display: grid;
  grid-template-columns: var(--nav-width) minmax(320px, 1fr) auto;
  direction: rtl;
  align-items: center;
  gap: 22px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
}

.brand,
.market-strip,
.header-actions {
  direction: rtl;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 2px solid var(--amber);
  border-radius: 6px;
  color: var(--amber);
  font-size: 20px;
  font-weight: 800;
}

.brand div {
  display: grid;
  gap: 1px;
}

.brand strong {
  font-size: 18px;
}

.brand span:last-child {
  color: var(--muted);
  font-size: 11px;
}

.market-strip {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 18px;
  min-width: 0;
  font-size: 13px;
}

.market-price b {
  font-size: 18px;
}

.price-change {
  direction: ltr;
  font-weight: 700;
}

.price-change.is-up {
  color: var(--teal);
}

.price-change.is-down {
  color: var(--red);
}

.muted {
  color: var(--muted);
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-weight: 600;
}

.status-dot::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  content: "";
}

.status-dot.is-online::before {
  background: var(--teal);
  box-shadow: 0 0 0 4px rgba(14, 143, 123, 0.12);
}

.status-dot.is-loading::before {
  background: var(--amber);
  animation: pulse 1.2s ease-in-out infinite;
}

.status-dot.is-offline::before {
  background: var(--red);
}

@keyframes pulse {
  50% { opacity: 0.35; }
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 22px;
}

.icon-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-subtle);
}

.icon-button.is-busy span {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.side-nav {
  position: fixed;
  z-index: 15;
  top: var(--topbar-height);
  right: 0;
  bottom: 0;
  width: var(--nav-width);
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 22px 12px;
  border-left: 1px solid var(--line);
  background: var(--surface);
}

.nav-button {
  position: relative;
  min-height: 46px;
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-align: right;
  font-weight: 600;
}

.nav-button:hover {
  background: var(--surface-subtle);
  color: var(--ink);
}

.nav-button.is-active {
  background: var(--ink);
  color: #fff;
}

.nav-icon {
  font-size: 20px;
  text-align: center;
}

.nav-count {
  min-width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--line);
  color: var(--ink);
  font-size: 11px;
}

.nav-button.is-active .nav-count {
  background: var(--amber);
  color: #fff;
}

main {
  min-height: 100vh;
  padding: calc(var(--topbar-height) + 28px) calc(var(--nav-width) + 28px) 44px 28px;
}

.app-view {
  display: none;
  max-width: 1480px;
  margin: 0 auto;
}

.app-view.is-active {
  display: block;
}

.page-heading,
.section-toolbar,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.page-heading {
  min-height: 56px;
  margin-bottom: 22px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
  line-height: 1.3;
}

.eyebrow {
  margin-bottom: 3px;
  color: var(--amber);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.scan-box {
  display: flex;
  align-items: baseline;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.scan-box strong {
  direction: ltr;
  color: var(--ink);
  font-size: 20px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric {
  min-height: 112px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 17px 18px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.metric > span,
.metric small {
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  min-height: 32px;
  margin: 5px 0 2px;
  font-size: 24px;
  line-height: 1.25;
}

.metric strong.is-up {
  color: var(--teal);
}

.metric strong.is-down {
  color: var(--red);
}

.chart-section,
.decision-panel,
.levels-panel,
.data-section,
.report-panel {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.chart-section {
  margin-bottom: 16px;
  overflow: hidden;
}

.section-toolbar,
.section-heading {
  padding: 17px 20px;
}

.section-toolbar p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.segmented-control {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-subtle);
}

.timeframe-button {
  min-width: 58px;
  height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.timeframe-button.is-active {
  background: var(--ink);
  color: #fff;
}

.chart-shell {
  position: relative;
  width: 100%;
  height: clamp(360px, 48vh, 570px);
  min-height: 360px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

#marketChart {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
}

.chart-empty[hidden] {
  display: none;
}

.chart-tooltip {
  position: absolute;
  z-index: 4;
  min-width: 172px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: rgba(23, 32, 42, 0.94);
  color: #fff;
  font-size: 11px;
  line-height: 1.7;
  pointer-events: none;
  box-shadow: var(--shadow);
}

.chart-legend {
  min-height: 42px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 9px 20px;
  color: var(--muted);
  font-size: 11px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 9px;
  height: 9px;
  display: inline-block;
}

.legend-swatch.bullish {
  background: var(--teal);
}

.legend-swatch.bearish {
  background: var(--red);
}

.legend-line {
  width: 19px;
  height: 0;
  display: inline-block;
  border-top: 2px solid;
}

.legend-line.trend { border-color: var(--blue); }
.legend-line.support { border-color: var(--teal); border-top-style: dashed; }
.legend-line.resistance { border-color: var(--red); border-top-style: dashed; }
.legend-line.current { border-color: var(--amber); border-top-style: dotted; }

.overview-lower {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.75fr);
  gap: 16px;
}

.decision-panel,
.levels-panel {
  min-height: 290px;
}

.score-ring {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 5px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.decision-reason {
  margin: 0;
  padding: 0 20px 15px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.65;
}

.trade-levels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 0 20px 15px;
  border: 1px solid var(--line);
}

.trade-levels[hidden] {
  display: none;
}

.trade-levels div {
  display: grid;
  gap: 3px;
  padding: 11px 13px;
  border-left: 1px solid var(--line);
}

.trade-levels div:last-child {
  border-left: 0;
}

.trade-levels span {
  color: var(--muted);
  font-size: 10px;
}

.trade-levels strong {
  direction: ltr;
  text-align: right;
}

.checklist {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px 16px;
  margin: 0;
  padding: 0 20px 20px;
  list-style: none;
}

.checklist li {
  position: relative;
  padding-right: 20px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.checklist li::before {
  position: absolute;
  top: 1px;
  right: 0;
  width: 14px;
  height: 14px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  content: "×";
  background: var(--red-soft);
  color: var(--red);
  font-size: 10px;
  font-weight: 800;
}

.checklist li.is-passed {
  color: var(--ink);
}

.checklist li.is-passed::before {
  content: "✓";
  background: var(--teal-soft);
  color: var(--teal);
}

.level-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 20px 10px;
  padding: 14px;
  border-right: 4px solid;
  background: var(--surface-subtle);
}

.level-row div {
  display: grid;
  gap: 3px;
}

.level-row span,
.level-row small {
  color: var(--muted);
  font-size: 11px;
}

.level-row strong {
  direction: ltr;
  font-size: 20px;
}

.support-row {
  border-color: var(--teal);
}

.resistance-row {
  border-color: var(--red);
}

.channel-position {
  padding: 13px 20px 20px;
}

.channel-labels {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 10px;
}

.channel-labels b {
  color: var(--ink);
}

.channel-track {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: var(--amber-soft);
  overflow: hidden;
}

.channel-track::before,
.channel-track::after {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 33.333%;
  content: "";
}

.channel-track::before {
  right: 0;
  background: var(--red-soft);
}

.channel-track::after {
  left: 0;
  background: var(--teal-soft);
}

.channel-track i {
  position: absolute;
  top: 50%;
  right: 50%;
  width: 14px;
  height: 14px;
  transform: translate(50%, -50%);
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 1px var(--line-strong);
}

.command-button {
  min-height: 38px;
  padding: 0 15px;
  border: 1px solid var(--ink);
  border-radius: 5px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.command-button:hover {
  background: #2b3642;
}

.data-section {
  overflow: hidden;
}

.filter-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.filter-control select {
  min-width: 130px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
}

.table-wrap {
  overflow-x: auto;
  border-top: 1px solid var(--line);
}

table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
  text-align: right;
}

th,
td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  font-size: 12px;
}

th {
  background: var(--surface-subtle);
  color: var(--muted);
  font-weight: 700;
}

td {
  color: var(--ink);
}

.trade-status {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 800;
}

.trade-status.open {
  background: var(--blue-soft);
  color: var(--blue);
}

.trade-status.won {
  background: var(--teal-soft);
  color: var(--teal);
}

.trade-status.lost {
  background: var(--red-soft);
  color: var(--red);
}

.empty-state {
  margin: 0;
  padding: 36px 20px;
  color: var(--muted);
  text-align: center;
}

.news-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.date-badge {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  font-size: 11px;
}

.event-list {
  border-top: 1px solid var(--line);
}

.event-item {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 14px;
  padding: 17px 20px;
  border-bottom: 1px solid var(--line);
}

.event-item:last-child {
  border-bottom: 0;
}

.event-time {
  direction: ltr;
  color: var(--ink);
  font-size: 17px;
  font-weight: 800;
}

.event-body {
  min-width: 0;
}

.event-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.event-title-row h3 {
  margin: 0;
  font-size: 14px;
}

.importance {
  flex: 0 0 auto;
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  padding: 0 7px;
  border-radius: 4px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 9px;
  font-weight: 800;
}

.importance.high {
  background: var(--red-soft);
  color: var(--red);
}

.importance.low {
  background: var(--blue-soft);
  color: var(--blue);
}

.event-body p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.event-empty {
  padding: 34px 20px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.schedule-band {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.schedule-band div {
  display: grid;
  gap: 3px;
  padding: 18px;
  border-left: 1px solid var(--line);
}

.schedule-band div:last-child {
  border-left: 0;
}

.schedule-band strong {
  font-size: 15px;
}

.schedule-band span {
  color: var(--muted);
  font-size: 11px;
}

.notification-state {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.reports-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.report-panel {
  min-height: 260px;
  padding: 20px;
}

.report-panel.wide {
  grid-column: 1 / -1;
}

.report-panel h2 {
  padding-bottom: 15px;
  border-bottom: 1px solid var(--line);
}

.report-list {
  display: grid;
  grid-template-columns: 1fr auto;
  margin: 0;
}

.report-list dt,
.report-list dd {
  margin: 0;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.report-list dt {
  color: var(--muted);
}

.report-list dd {
  direction: ltr;
  font-weight: 800;
  text-align: left;
}

.decision-history {
  display: grid;
}

.history-row {
  display: grid;
  grid-template-columns: 82px 150px 80px 1fr;
  gap: 14px;
  align-items: center;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.history-row span {
  color: var(--muted);
}

.history-row p {
  margin: 0;
}

.disclaimer {
  margin: 18px 0 0;
  padding: 13px 16px;
  border-right: 4px solid var(--amber);
  background: var(--amber-soft);
  color: #6f5514;
  font-size: 11px;
  line-height: 1.6;
}

.toast-region {
  position: fixed;
  z-index: 60;
  left: 22px;
  bottom: 22px;
  width: min(390px, calc(100vw - 44px));
  display: grid;
  gap: 9px;
}

.toast {
  padding: 13px 15px;
  border-right: 4px solid var(--blue);
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 12px 28px rgba(23, 32, 42, 0.25);
  font-size: 12px;
  line-height: 1.55;
  animation: toast-in 0.2s ease-out;
}

.toast.success {
  border-color: var(--teal);
}

.toast.error {
  border-color: var(--red);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
}

@media (max-width: 1050px) {
  :root {
    --nav-width: 82px;
  }

  .topbar {
    grid-template-columns: var(--nav-width) 1fr auto;
  }

  .brand div,
  .nav-button > span:not(.nav-icon):not(.nav-count) {
    display: none;
  }

  .brand {
    justify-content: center;
  }

  .nav-button {
    grid-template-columns: 1fr;
    justify-items: center;
    padding: 0;
  }

  .nav-count {
    position: absolute;
    top: 3px;
    left: 6px;
  }

  .overview-lower {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  :root {
    --topbar-height: 64px;
  }

  .topbar {
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    padding: 0 12px;
  }

  .market-strip {
    justify-content: flex-start;
    gap: 8px;
    overflow: hidden;
  }

  .market-strip .status-dot,
  #headerUpdated {
    display: none;
  }

  .market-price b {
    font-size: 16px;
  }

  .header-actions {
    gap: 4px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

  .side-nav {
    top: auto;
    bottom: 0;
    width: 100%;
    height: 66px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
    padding: 5px 6px calc(5px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .nav-button {
    min-height: 54px;
    grid-template-rows: 25px 16px;
    grid-template-columns: 1fr;
    gap: 0;
    justify-items: center;
    font-size: 10px;
  }

  .nav-button > span:not(.nav-count) {
    display: block;
  }

  .nav-icon {
    font-size: 19px;
  }

  .nav-count {
    top: 1px;
    left: calc(50% - 25px);
  }

  main {
    padding: calc(var(--topbar-height) + 18px) 12px 90px;
  }

  .page-heading {
    align-items: flex-start;
    margin-bottom: 16px;
  }

  h1 {
    font-size: 23px;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .metric {
    min-height: 101px;
    padding: 13px;
  }

  .metric strong {
    font-size: 20px;
  }

  .section-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .segmented-control {
    width: 100%;
  }

  .timeframe-button {
    min-width: 0;
    flex: 1;
  }

  .chart-shell {
    height: 390px;
    min-height: 390px;
  }

  .chart-legend {
    gap: 10px;
    padding: 9px 12px;
  }

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

  .news-layout,
  .reports-grid {
    grid-template-columns: 1fr;
  }

  .report-panel.wide {
    grid-column: auto;
  }

  .schedule-band {
    grid-template-columns: repeat(2, 1fr);
  }

  .schedule-band div:nth-child(2) {
    border-left: 0;
  }

  .schedule-band div:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }

  .history-row {
    grid-template-columns: 72px 1fr;
  }

  .history-row p {
    grid-column: 1 / -1;
  }
}

@media (max-width: 430px) {
  .brand-mark {
    width: 34px;
    height: 34px;
  }

  #headerChange {
    display: none;
  }

  .scan-box {
    display: grid;
    gap: 0;
    text-align: left;
  }

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

  .metric small {
    min-height: 30px;
  }

  .chart-shell {
    height: 350px;
    min-height: 350px;
  }

  .chart-legend {
    font-size: 10px;
  }

  .trade-levels {
    grid-template-columns: 1fr;
  }

  .trade-levels div {
    grid-template-columns: 1fr auto;
    border-bottom: 1px solid var(--line);
    border-left: 0;
  }

  .trade-levels div:last-child {
    border-bottom: 0;
  }

  .event-item {
    grid-template-columns: 52px 1fr;
    padding: 15px 13px;
  }

  .schedule-band {
    grid-template-columns: 1fr;
  }

  .schedule-band div {
    border-bottom: 1px solid var(--line);
    border-left: 0;
  }

  .schedule-band div:last-child {
    border-bottom: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
