/* Forex Factory calendar panel.
   Dark by default (cTrader's default theme); ?theme=light|auto switches. */

:root {
  color-scheme: dark;
  --bg: #1f2227;
  --text: #d6dae1;
  --muted: #8a92a0;
  --accent: #5ba3ff;
  --warn: #f0b429;
  --bar-h: 34px;
  --day-h: 24px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --text: #1f2328;
  --muted: #667085;
  --accent: #0b62d6;
  --warn: #d98e00;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    color-scheme: light;
    --bg: #ffffff;
    --text: #1f2328;
    --muted: #667085;
    --accent: #0b62d6;
    --warn: #d98e00;
  }
}
:root {
  /* Derived from --bg/--text so a custom ?bg= still gets matching surfaces. */
  --surface: color-mix(in srgb, var(--bg) 91%, var(--text));
  --line: color-mix(in srgb, var(--bg) 80%, var(--text));
  --line-soft: color-mix(in srgb, var(--bg) 93%, var(--text));
  /* Today's rows sit on a slightly brighter band (light grey on the light theme). */
  --today: color-mix(in srgb, var(--bg) 92%, var(--text));
  --today-line: color-mix(in srgb, var(--bg) 86%, var(--text));
  --today-head: color-mix(in srgb, var(--bg) 83%, var(--text));
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 12px/18px "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---- toolbar ---- */
.bar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 6px;
  height: var(--bar-h);
  padding: 0 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.impacts { display: flex; flex: none; gap: 2px; }
.tog {
  display: grid;
  place-items: center;
  width: 22px;
  height: 24px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 4px;
  background: none;
}
.tog[aria-pressed="true"] { border-color: var(--line); background: var(--bg); }
.tog[aria-pressed="false"] img { opacity: .35; filter: grayscale(1); }
.tog:hover { border-color: var(--muted); }
.btn {
  flex: none;
  height: 24px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
#ccy-btn { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
#ccy-btn[aria-expanded="true"] { border-color: var(--accent); }
.grow { flex: 1; }
.stale {
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--warn);
  color: #1b1b1b;
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  cursor: help;
}

/* ---- currency filter dropdown ---- */
.panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 8px;
  right: 8px;
  max-width: 320px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgb(0 0 0 / .35);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--bg);
  font-size: 11px;
  font-weight: 600;
}
.chip:hover { border-color: var(--muted); }
.chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 22%, var(--bg));
}

/* ---- day groups ---- */
.day {
  position: sticky;
  top: var(--bar-h);
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  height: var(--day-h);
  margin: 0;
  padding: 0 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
}
.today-tag {
  display: none;
  padding: 0 5px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font-size: 10px;
  line-height: 14px;
  letter-spacing: 0;
}
.today .day { background: var(--today-head); color: var(--text); }
.today .today-tag { display: inline-block; }

/* ---- event rows ---- */
.events { margin: 0; padding: 0; list-style: none; }
.ev {
  display: grid;
  grid-template-columns: 50px 46px 14px minmax(0, 1fr);
  column-gap: 7px;
  padding: 3px 8px;
  border-bottom: 1px solid var(--line-soft);
  /* Clears both sticky bars and leaves a couple of past rows visible above. */
  scroll-margin-top: calc(var(--bar-h) + var(--day-h) + 44px);
}
.ev { --row: var(--bg); }
.today .ev {
  --row: var(--today);
  background: var(--row);
  border-bottom-color: var(--today-line);
}
.ev:hover { background: color-mix(in srgb, var(--row) 94%, var(--text)); }
/* Dim the content rather than the row, so today's band stays even behind past events. */
.ev.past > * { opacity: .5; }
.ev.next,
.ev.next:hover {
  background: color-mix(in srgb, var(--accent) 16%, var(--row));
  box-shadow: inset 2px 0 0 var(--accent);
}

.time { color: var(--muted); text-align: right; white-space: nowrap; }
.time.special { font-size: 10.5px; }
.time.rep { visibility: hidden; }
.next .time { color: var(--text); }

.ccy {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 18px;
  font-size: 11px;
  font-weight: 600;
}
.flag {
  flex: none;
  width: 16px;
  height: 12px;
  border-radius: 1px;
  /* Keeps white/dark flags from bleeding into the background. */
  box-shadow: 0 0 0 1px rgb(128 128 128 / .35);
}
.impact { width: 14px; height: 12px; margin-top: 3px; }

.title { min-width: 0; overflow-wrap: anywhere; }
.title a { color: inherit; text-decoration: none; }
.title a:hover { color: var(--accent); text-decoration: underline; }
.eta {
  display: inline-block;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--bg);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 15px;
  white-space: nowrap;
}
.eta:empty { display: none; }

.vals {
  grid-column: 4;
  display: flex;
  flex-wrap: wrap; /* very narrow panels: previous drops under forecast */
  gap: 0 10px;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 16px;
}
.val { overflow-wrap: anywhere; }
.val .k { margin-right: 3px; opacity: .75; }
.val.empty { display: none; }

/* Wide panels (e.g. Trade Watch): forecast/previous become aligned columns. */
@media (min-width: 480px) {
  .ev { grid-template-columns: 50px 46px 14px minmax(0, 1fr) auto; }
  .vals { grid-column: 5; grid-row: 1; flex-wrap: nowrap; gap: 12px; font-size: 12px; line-height: 18px; }
  .val {
    width: 6.6em;
    overflow: hidden;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .val.empty { display: block; visibility: hidden; }
}

/* ---- messages / footer ---- */
.msg { margin: 0; padding: 28px 12px; color: var(--muted); text-align: center; }
.msg .btn { margin-top: 10px; }
.foot { padding: 8px; color: var(--muted); font-size: 11px; line-height: 16px; text-align: center; }
.foot a { color: inherit; }
.foot a:hover { color: var(--accent); }
