:root {
  --bg: #f5efe6;
  --ink: #1d1a16;
  --muted: #6f655a;
  --card: #fffaf3;
  --accent: #e26d2f;
  --accent-dark: #b74714;
  --link: #9a3f12;
  --link-hover: #7d320d;
  --line: #e2d6c6;
  --shadow: 0 20px 40px rgba(28, 19, 10, 0.12);
  --gauge-start: #c83b3b;
  --gauge-mid: #f0c04f;
  --gauge-end: #2d9c5f;
}

[data-theme="dark"] {
  --bg: #0f1115;
  --ink: #f3f2ef;
  --muted: #8d8b85;
  --card: #161920;
  --accent: #ff8f3f;
  --accent-dark: #d26c24;
  --link: #ffb36a;
  --link-hover: #ffd5a6;
  --line: #262a34;
  --shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  --gauge-start: #d16045;
  --gauge-mid: #d2b54a;
  --gauge-end: #6acf7a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top left, #fff7ea 0%, #f3e7d6 40%, #efe2cd 100%);
}

[data-theme="dark"] body {
  background: radial-gradient(circle at top left, #131720 0%, #0f1115 60%, #0b0d12 100%);
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover,
a:focus {
  color: var(--link-hover);
  text-decoration: underline;
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 48px 24px 80px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 28px;
  animation: riseIn 0.6s ease both;
}

.topbar-left {
  display: grid;
  gap: 4px;
}

.topbar-title {
  font-family: "DM Serif Display", "Times New Roman", serif;
  font-size: 34px;
  color: var(--ink);
}

.topbar-sub {
  font-size: 13px;
  color: var(--muted);
}

.topbar-right {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.stat {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  min-width: 90px;
  text-align: center;
}

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

.label {
  color: var(--muted);
  font-size: 12px;
}

.button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 10px 20px rgba(226, 109, 47, 0.25);
}

.button:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 24px rgba(226, 109, 47, 0.3);
}

.button-outline {
  background: transparent;
  color: var(--accent-dark);
  border: 1px solid var(--accent-dark);
  box-shadow: none;
}

.button.small {
  padding: 6px 12px;
  font-size: 12px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

@media (max-width: 640px) {
  .filters {
    flex-direction: column;
    align-items: stretch;
  }

  .input {
    width: 100%;
  }

  .range-wrap {
    width: 100%;
  }

  .panel {
    padding: 18px;
  }

  .table-row {
    padding: 10px 12px;
  }
}

.grid {
  display: grid;
  gap: 24px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  margin-bottom: 24px;
}

.grid.single {
  grid-template-columns: minmax(0, 1fr);
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow);
  animation: riseIn 0.6s ease both;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.tracker-head {
  align-items: center;
}

.tracker-title h2 {
  margin: 0;
  font-size: 28px;
}

.tracker-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.tracker-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.panel-sub {
  margin: 6px 0 0;
  color: var(--muted);
}

.panel-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.chip-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.filters {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-start;
}

.input-stack {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.actions-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  width: 100%;
}

.actions-left,
.actions-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

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

.input {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  min-width: 200px;
}

.range-wrap {
  display: grid;
  gap: 6px;
  min-width: 240px;
}

.range-wrap label {
  font-size: 12px;
  color: var(--muted);
}

.range-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  position: relative;
  height: 32px;
}

.range-controls input[type="range"] {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  width: 100%;
  margin: 0;
  background: transparent;
  pointer-events: none;
}

.range-values {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}

.range-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 12px;
  height: 8px;
  border-radius: 999px;
  background: var(--line);
}

.range-highlight {
  position: absolute;
  top: 12px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gauge-start), var(--gauge-mid), var(--gauge-end));
  opacity: 0.7;
}

.range-controls input[type="range"]::-webkit-slider-thumb {
  pointer-events: auto;
}

.chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--accent-dark);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 600;
}

.chip-muted {
  border-color: var(--line);
  color: var(--muted);
}

.chip-button {
  background: transparent;
  font-family: inherit;
  cursor: pointer;
}

.chip-button:hover {
  background: rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] .chip-button:hover {
  background: rgba(255, 255, 255, 0.06);
}

.chip-button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.table {
  display: grid;
  gap: 12px;
}

.table-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: #fff5e8;
  border: 1px solid #f1dcc7;
  align-items: center;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.table-row.strong-positive {
  background: #e2f4e8;
  border-color: #b7e1c5;
}

.table-row.strong-negative {
  background: #fde7e4;
  border-color: #f1b5ad;
}

.table-row:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(28, 19, 10, 0.08);
  border-color: #e0c8ae;
}

[data-theme="dark"] .table-row {
  background: #1c2029;
  border-color: #2a2f3c;
}

[data-theme="dark"] .table-row.strong-positive {
  background: #1b2a24;
  border-color: #2d5443;
}

[data-theme="dark"] .table-row.strong-negative {
  background: #2a1d1c;
  border-color: #5a2f2a;
}

[data-theme="dark"] .table-row:hover {
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.5);
}

.row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

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

.row-select input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.row-name {
  font-weight: 700;
  font-size: 16px;
}

.row-ticker {
  font-size: 12px;
  color: var(--muted);
}

.gauge {
  display: grid;
  gap: 2px;
}

.row-main .gauge-track {
  max-width: 240px;
}

.row-sparkline {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: 100px;
}

.sparkline {
  width: 90px;
  height: 26px;
}

.sparkline polyline {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sparkline-empty {
  font-size: 12px;
  color: var(--muted);
  width: 90px;
  text-align: right;
}

.gauge-track {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gauge-start), var(--gauge-mid), var(--gauge-end));
  overflow: hidden;
}

.gauge-fill {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.05);
}

.gauge-thumb {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  background: var(--ink);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.08);
}

[data-theme="dark"] .gauge-thumb {
  border-color: var(--card);
  box-shadow: 0 0 0 2px rgba(255,255,255,0.1);
}

.gauge-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
}

.table-row strong {
  font-size: 16px;
}

.score {
  font-weight: 600;
}

.score.positive {
  color: #2f8f4e;
}

.score.negative {
  color: #c2462b;
}

.score.neutral {
  color: #7a6d5f;
}

.detail-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.detail-card {
  background: #fffdf8;
  border-radius: 16px;
  padding: 16px;
  border: 1px solid var(--line);
}

.detail-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.pill-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.pill {
  padding: 6px 12px;
  border-radius: 999px;
  background: #f5e7d6;
  font-size: 12px;
  font-weight: 600;
}

.drivers {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}

.driver {
  padding: 10px 12px;
  border-radius: 12px;
  background: #f7efdf;
  border: 1px solid #ead9c6;
}

.article-list {
  display: grid;
  gap: 14px;
}

.article-card {
  border-radius: 16px;
  border: 1px solid var(--line);
  padding: 16px;
  background: #fffdf9;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.article-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .article-card {
  background: #161920;
  border-color: #2a2f3c;
}

.article-card h4 {
  margin: 0 0 8px;
  font-size: 18px;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.article-sub {
  margin-top: 6px;
}

.article-summary {
  display: none;
}

.article-card.expanded .article-summary {
  display: block;
}

.data-sources {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}

.article-summary {
  margin: 10px 0 0;
  padding-left: 18px;
  color: #493f35;
}

[data-theme="dark"] .article-summary {
  color: #d6cfc5;
}

.article-summary.rtl {
  direction: rtl;
  text-align: right;
}

.alerts {
  display: grid;
  gap: 12px;
}

.alert {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff3ec;
}

.alert strong {
  display: block;
  margin-bottom: 6px;
}

.select-wrap select {
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  font-family: inherit;
  background: #fffdf8;
}

.panel-footer {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(18, 14, 10, 0.5);
  padding: 24px;
}

.modal[aria-hidden="false"] {
  display: flex;
}

.modal-content {
  background: #fffdf8;
  border-radius: 16px;
  padding: 20px;
  max-width: 640px;
  width: 100%;
  max-height: 80vh;
  overflow: auto;
  box-shadow: var(--shadow);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 6px;
}

.form-grid label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.icon-button {
  background: none;
  border: none;
  color: var(--accent-dark);
  font-weight: 600;
  cursor: pointer;
}

@media (max-width: 900px) {
  .tracker-head {
    align-items: flex-start;
  }

  .tracker-actions {
    width: 100%;
    justify-content: space-between;
  }

  .table-row {
    grid-template-columns: 1fr;
  }

  .row-sparkline {
    justify-content: flex-start;
    width: auto;
  }

  .row-main .gauge-track {
    max-width: 100%;
  }
}
