:root {
  --bg: #fffdf5;
  --bg-2: #fffef9;
  --card: #ffffff;
  --border: #eee3bd;
  --border-soft: #f3ecd2;
  --text: #23201a;
  --muted: #8a8266;
  --muted-2: #b3ab90;
  --yellow: #f5b301;      /* primary gold */
  --yellow-soft: #fff4cc;
  --yellow-line: #ffd83d;
  --high: #e8590c;        /* high impact - deep orange */
  --high-bg: #ffe8d6;
  --medium: #f59f00;      /* medium - orange */
  --medium-bg: #fff0d1;
  --low: #f2c744;         /* low - yellow */
  --low-bg: #fff7d6;
  --green: #2f9e44;
  --red: #e03131;
  --radius: 14px;
  --shadow: 0 6px 20px rgba(180, 150, 20, 0.10);
}

* { box-sizing: border-box; }

/* Note: deliberately NOT setting overflow-x on html/body — doing so forces
   the browser to auto-compute overflow-y: auto on that ancestor, which turns
   it into its own scroll container and breaks position: sticky on children
   (the header/filter bar). Horizontal overflow is instead prevented at the
   individual wide-content level (min-width: 0, flex-wrap, grid, etc.). */
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(1100px 500px at 85% -12%, #fff4cc 0%, rgba(255,244,204,0) 60%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ---------- header (topbar + filter bar, sticky as one unit) ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 0 var(--yellow-line);
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 26px;
}
.brand { min-width: 0; }
.brand h1 { font-size: 18px; margin: 0; letter-spacing: 0.2px; line-height: 1.2; }
.tag { margin: 1px 0 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-actions { display: flex; align-items: center; gap: 10px; flex: none; }

.filterbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 26px 14px;
  border-top: 1px solid var(--border-soft);
}
.filter-group {
  display: flex;
  gap: 4px;
  background: #fbf6e3;
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.chip {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 7px 13px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: 0.15s;
  white-space: nowrap;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--yellow); color: #3a2c00; box-shadow: 0 2px 6px rgba(245,179,1,0.4); }
.chip.active.imp-high { background: var(--high); color: #fff; box-shadow: 0 2px 6px rgba(232,89,12,0.35); }
.chip.active.imp-medium { background: var(--medium); color: #3a2600; }
.chip.active.imp-low { background: var(--low); color: #4a3900; }

.clock {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
.refresh {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 9px;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  flex: none;
}
.refresh svg { display: block; }
.refresh:hover { border-color: var(--yellow); color: var(--yellow); }
.refresh:disabled { opacity: 0.6; cursor: default; }
.refresh.spinning svg { animation: refresh-spin 0.7s linear; }
@keyframes refresh-spin { to { transform: rotate(360deg); } }

/* ---------- banner ---------- */
.banner {
  display: none;
  margin: 14px 26px 0;
  padding: 9px 14px;
  border-radius: 10px;
  background: var(--yellow-soft);
  border: 1px solid var(--yellow-line);
  color: #6b5300;
  font-size: 12.5px;
}
.banner.show { display: block; }

/* ---------- layout ---------- */
/* Split into two <main> blocks so the sticky header (see .sticky-scope) can
   be scoped to release right where the news section begins. */
.calendar-main,
.news-main {
  display: flex;
  flex-direction: column;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}
.calendar-main { padding: 22px 26px 0; }
.news-main { padding: 22px 26px 40px; }

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 20px 24px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.panel-head { margin-bottom: 16px; }
.panel-head h2 { margin: 0 0 4px; font-size: 17px; }
.sub { font-size: 12.5px; color: var(--muted); }

/* ---------- impact legend ---------- */
.legend { display: flex; gap: 16px; margin-top: 10px; font-size: 11.5px; color: var(--muted); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.legend .l-high { background: var(--high); }
.legend .l-medium { background: var(--medium); }
.legend .l-low { background: var(--low); }

.impact-note {
  margin: 10px 0 0;
  font-size: 11.5px;
  color: #7a6a3a;
  background: var(--yellow-soft);
  border: 1px solid var(--yellow-line);
  border-radius: 8px;
  padding: 8px 10px;
  line-height: 1.5;
}

/* ---------- calendar (list) ---------- */
.cal-days { display: flex; flex-direction: column; gap: 22px; }
.day-group h3 {
  margin: 0 0 10px;
  font-size: 13px;
  letter-spacing: 0.3px;
  color: var(--muted);
  border-bottom: 1px dashed var(--border);
  padding-bottom: 8px;
}
.day-group h3 b { color: var(--text); }
.event-list { display: flex; flex-direction: column; border: 1px solid var(--border-soft); border-radius: 12px; overflow: hidden; }
.empty-day { color: var(--muted-2); font-size: 13px; padding: 10px 2px; text-align: center; }

.event-row {
  display: grid;
  grid-template-columns: 130px 100px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: var(--card);
  border-top: 1px solid var(--border-soft);
  transition: 0.15s;
}
.event-row:first-child { border-top: none; }
.event-row:hover { background: #fffaea; }
.event-row.usd { box-shadow: inset 3px 0 0 var(--yellow); }
.event-row.imp-high { box-shadow: inset 3px 0 0 var(--high); }
.event-row.usd.imp-high { box-shadow: inset 4px 0 0 var(--high), inset 3px 0 0 var(--high); }
.event-row.imp-medium { box-shadow: inset 3px 0 0 var(--medium); }
.event-row.imp-low { box-shadow: inset 3px 0 0 var(--low); }
.event-row.past { opacity: 0.82; }

.row-time { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.row-time .time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.status { font-size: 12px; font-weight: 700; white-space: nowrap; }
.status.countdown { color: #b58a00; font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 800; }
.status.countdown.soon { color: var(--medium); }
.status.countdown.live { color: var(--high); animation: pulse 1s infinite; }
.status.await { color: var(--green); }
.status.released { color: var(--muted); }
@keyframes pulse { 50% { opacity: 0.5; } }

.row-ccy { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ccy {
  font-size: 11.5px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--yellow-soft);
  border: 1px solid var(--yellow-line);
  color: #7a5c00;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.dots { display: flex; gap: 3px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #e6ddc0; }
.imp-high .dot.on { background: var(--high); }
.imp-medium .dot.on { background: var(--medium); }
.imp-low .dot.on { background: var(--low); }

.row-title { font-size: 14px; font-weight: 600; min-width: 0; }

.row-data { display: flex; gap: 16px; flex-wrap: wrap; justify-content: flex-end; }
.data-item { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; min-width: 54px; }
.data-item .lbl { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.data-item .val { font-weight: 700; font-size: 13px; }
.val.actual-up { color: var(--green); }
.val.actual-down { color: var(--red); }

/* ---------- news (grid: 3 cols desktop, 1 col mobile) ---------- */
.news-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.news-item {
  display: flex;
  flex-direction: column;
  gap: 0;
  text-decoration: none;
  color: inherit;
  background: #fffdf6;
  border: 1px solid var(--border-soft);
  border-top: 3px solid var(--muted-2);
  border-radius: 10px;
  padding: 0 0 14px;
  overflow: hidden;
  transition: 0.15s;
}
.news-item:hover { border-color: var(--yellow-line); background: #fffaea; transform: translateY(-2px); box-shadow: var(--shadow); }
.news-item.high { border-top-color: var(--high); }
.news-item.medium { border-top-color: var(--medium); }
.news-item.low { border-top-color: var(--low); }
.news-thumb {
  flex: none;
  width: 100%;
  height: 150px;
  object-fit: cover;
  background: var(--border-soft);
}
.news-body { min-width: 0; flex: 1; padding: 12px 14px 0; }
.news-item:not(.has-thumb) .news-body { padding-top: 14px; }
.news-title { font-size: 14px; font-weight: 600; line-height: 1.35; margin-bottom: 6px; }
.news-preview {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 7px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.news-meta { display: flex; flex-wrap: wrap; gap: 10px; font-size: 11.5px; color: var(--muted); }
.news-meta .src { color: #b58a00; font-weight: 700; }
.news-meta .cmt::before { content: "💬 "; }

/* ---------- misc ---------- */
.loading { color: var(--muted); font-size: 13px; padding: 20px; text-align: center; }
.error { color: var(--red); font-size: 13px; padding: 16px; text-align: center; }
.footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  padding: 18px 26px 24px;
  font-size: 11.5px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}
.footer .muted { color: var(--muted-2); }
.disclaimer {
  margin: 0;
  max-width: 640px;
  font-size: 10.5px;
  line-height: 1.6;
  color: var(--muted-2);
  text-align: center;
}
.disclaimer strong { color: var(--muted); }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: #f0e4b8; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- tablet: ease the news grid from 3 to 2 cols before it goes to 1 ---------- */
@media (max-width: 980px) and (min-width: 721px) {
  .news-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- mobile ---------- */
@media (max-width: 720px) {
  .topbar { padding: 10px 14px; }
  .tag { display: none; }
  .brand h1 { font-size: 16px; }
  .clock { display: none; }

  .filterbar { padding: 7px 10px 10px; gap: 6px; }
  .filter-group { flex-wrap: wrap; justify-content: center; gap: 3px; padding: 3px; }
  .chip { padding: 5px 9px; font-size: 11px; border-radius: 6px; }

  .calendar-main { padding: 16px 12px 0; }
  .news-main { padding: 16px 12px 32px; }
  .panel { padding: 14px 14px 18px; }
  .banner { margin: 12px 12px 0; }

  .event-row {
    grid-template-columns: 1fr;
    grid-template-areas:
      "ccy"
      "title"
      "time"
      "data";
    gap: 8px;
    padding: 12px;
  }
  .row-ccy { grid-area: ccy; justify-content: space-between; }
  .row-title { grid-area: title; }
  .row-time { grid-area: time; flex-direction: row; align-items: center; justify-content: space-between; }
  .row-data { grid-area: data; justify-content: flex-start; gap: 14px; }
  .data-item { align-items: flex-start; }

  .news-list { grid-template-columns: 1fr; gap: 12px; }
}
