/* Calendar tab styles. The panel owns the viewport under the 54 px top bar and never lets the page
   scroll: every box in the chain sets min-height: 0, and only a day cell and the rail list scroll.
   The chrome comes from theme.css - yellow, black and purple; the one thing that carries a hue of
   its own is the country an event belongs to. Importance stays weight and size, not another hue. */

/* The ten priority countries in the owner's importance order, then the neutral World that catches
   every other country. Chosen to stay apart from each other and from the site's yellow (#f8fa4e)
   and purple (#7d2dfe) on the black field. Tune a colour here and the chip, the event lines and
   the popover title follow; calendar.js names these variables and never spells a hex. */
:root {
  --cal-us: #4f7cff;            /* 1  United States */
  --cal-cn: #ff3b3b;            /* 2  China */
  --cal-eu: #22d3ee;            /* 3  Euro area */
  --cal-jp: #f472b6;            /* 4  Japan */
  --cal-uk: #4ade80;            /* 5  United Kingdom */
  --cal-ch: #e2e8f0;            /* 6  Switzerland */
  --cal-in: #fb923c;            /* 7  India */
  --cal-tr: #2dd4bf;            /* 8  Turkiye */
  --cal-sa: #f5b700;            /* 9  Saudi Arabia */
  --cal-kr: #c084fc;            /* 10 South Korea */
  --cal-world: #9ca3af;         /*    everything else */
}

/* One attribute, set on an event line, a chip or the open popover, tells everything inside it
   which colour to wear. Anything with no such ancestor keeps the old yellow or grey fallback. */
[data-cc="us"] { --cal-c: var(--cal-us); }
[data-cc="cn"] { --cal-c: var(--cal-cn); }
[data-cc="eu"] { --cal-c: var(--cal-eu); }
[data-cc="jp"] { --cal-c: var(--cal-jp); }
[data-cc="uk"] { --cal-c: var(--cal-uk); }
[data-cc="ch"] { --cal-c: var(--cal-ch); }
[data-cc="in"] { --cal-c: var(--cal-in); }
[data-cc="tr"] { --cal-c: var(--cal-tr); }
[data-cc="sa"] { --cal-c: var(--cal-sa); }
[data-cc="kr"] { --cal-c: var(--cal-kr); }
[data-cc="world"] { --cal-c: var(--cal-world); }

.calendar-panel {
  height: calc(100dvh - 54px);
  min-height: 420px;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  contain: layout paint;
}

.cal {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(232px, 20.5%, 330px);
  gap: 8px;
  min-height: 0;
  padding: 8px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.cal-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; gap: 5px; }

/* --- header ------------------------------------------------------------------------------- */

.cal-head { flex: none; display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; padding: 0 2px; }
.cal-nav { display: flex; align-items: center; gap: 8px; min-width: 0; }
.cal-title { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: .01em; color: var(--yellow); white-space: nowrap; }
.cal-arrow {
  width: 26px; height: 26px; flex: none; display: inline-flex; align-items: center; justify-content: center;
  padding: 0 0 2px; border: 2px solid var(--purple); border-radius: 3px;
  background: var(--ink); color: var(--yellow); font-size: 17px; line-height: 1; cursor: pointer;
}
.cal-arrow:hover:not(:disabled) { background: var(--purple); }
.cal-arrow:disabled { border-color: var(--line); color: var(--subtle); cursor: default; }
.cal-today {
  height: 22px; flex: none; padding: 0 8px; border: 2px solid var(--purple); border-radius: 3px;
  background: var(--purple); color: var(--yellow); font: inherit; font-size: 10px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; cursor: pointer;
}
.cal-today:hover { background: var(--purple-deep); }
.cal-head-note { margin: 0; color: var(--muted); font-size: 10px; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }

/* The country chips take the second header line, under the month title and across the full width:
   twelve chips need more room than the title row has left, and a strip that keeps its place at
   1280 px reads better than one that shrinks below 9.5 px. Below 900 px they wrap again. */
.cal-nav { order: 1; }
.cal-head-note { order: 2; }
.cal-chips { order: 3; flex: 1 1 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 3px 4px; min-width: 0; }
.cal-chip {
  display: inline-flex; align-items: center; gap: 4px; flex: none; height: 18px; padding: 0 6px;
  border: 1px solid var(--purple-deep); border-radius: 9px; background: var(--ink);
  color: var(--cal-c, var(--muted)); font: inherit; font-size: 9.5px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase; line-height: 1; white-space: nowrap; cursor: pointer;
}
.cal-chip-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--cal-c, var(--muted)); }
.cal-chip:hover { border-color: var(--cal-c, var(--purple)); }
.cal-chip:focus-visible { outline: 2px solid var(--purple); outline-offset: 1px; }
.cal-chip[aria-pressed="true"] { background: var(--cal-c, var(--yellow)); border-color: var(--cal-c, var(--yellow)); color: var(--ink); }
.cal-chip[aria-pressed="true"] .cal-chip-dot { background: var(--ink); }
.cal-chip--all { color: var(--yellow); border-color: var(--purple); }

.cal-dow { flex: none; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-dow span {
  padding: 2px 5px; border-radius: 2px; background: var(--yellow); color: var(--ink);
  font-size: 9.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
}

/* --- month grid --------------------------------------------------------------------------- */

.cal-grid { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }

.cal-day {
  display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden;
  border: 2px solid var(--purple-deep); border-radius: 3px; background: var(--ink);
}
.cal-day--pad { border-color: var(--line); background: transparent; opacity: .35; }
.cal-day--past { opacity: .45; }
.cal-day--today { border-color: var(--yellow); }

.cal-day-head {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 4px;
  padding: 1px 5px; border-bottom: 1px solid var(--line);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
.cal-day-num { font-size: 12px; font-weight: 600; color: var(--muted); }
.cal-day--today .cal-day-head { background: var(--yellow); border-bottom-color: var(--yellow); }
.cal-day--today .cal-day-num { color: var(--ink); font-weight: 700; }
.cal-day-mark { font-size: 8px; font-weight: 700; letter-spacing: .1em; color: var(--ink); }
.cal-day-count { font-size: 9px; color: var(--subtle); }

.cal-day-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 1px; scrollbar-width: thin; scrollbar-color: var(--purple) transparent; }
.cal-day-list::-webkit-scrollbar { width: 6px; }
.cal-day-list::-webkit-scrollbar-thumb { background: var(--purple-deep); border-radius: 3px; }

/* --- one event line ------------------------------------------------------------------------ */

.cal-event {
  width: 100%; display: flex; align-items: baseline; gap: 3px;
  padding: 1px 2px; border: 0; border-radius: 2px; background: transparent; color: var(--cal-c, var(--text));
  font: inherit; font-size: 10.5px; line-height: 1.3; text-align: left; cursor: pointer;
}
.cal-event:hover { background: var(--purple-deep); }
.cal-event:focus-visible { outline: 2px solid var(--purple); outline-offset: -2px; }
.cal-event--high { font-weight: 700; font-size: 11px; }

 /* Only a high-importance line carries the marker; a medium line is plain, lighter type. The
    marker takes the country colour on a line and stays yellow in the legend, where it explains
    importance rather than a country. */
.cal-mark { width: 6px; height: 6px; flex: none; align-self: center; border-radius: 1px; background: var(--cal-c, var(--yellow)); }

.cal-time {
  flex: none; color: var(--cal-c, var(--muted)); font-size: 9.5px; font-weight: 400; font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
.cal-cc {
  flex: none; padding: 0 2px; border-radius: 2px; background: var(--purple-deep); color: var(--cal-c, var(--yellow));
  font-size: 9px; font-weight: 600; letter-spacing: .04em;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
.cal-tag {
  flex: none; padding: 0 3px; border: 1px solid var(--purple); border-radius: 2px; color: var(--cal-c, var(--yellow));
  font-size: 8.5px; font-weight: 600; letter-spacing: .06em;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
.cal-offset { margin-left: 1px; font-size: 7.5px; vertical-align: super; color: var(--cal-c, var(--subtle)); opacity: .8; }
.cal-event-title { flex: 1 1 auto; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cal-event--tentative .cal-event-title, .cal-legend-tentative { text-decoration: underline dotted var(--subtle); text-underline-offset: 2px; }
.cal-flag { margin-left: 2px; color: var(--cal-c, var(--muted)); font-weight: 700; text-decoration: none; }

/* --- rail --------------------------------------------------------------------------------- */

.cal-rail {
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  border: 2px solid var(--purple); border-radius: 3px; background: var(--surface);
}
.cal-rail-head {
  flex: none; padding: 3px 8px; background: var(--yellow); color: var(--ink);
  font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
}
.cal-next { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 2px 4px 6px; scrollbar-width: thin; scrollbar-color: var(--purple) transparent; }
.cal-next::-webkit-scrollbar { width: 7px; }
.cal-next::-webkit-scrollbar-thumb { background: var(--purple-deep); border-radius: 3px; }
.cal-next-day {
  position: sticky; top: 0; z-index: 1; margin: 4px 0 2px; padding: 2px 4px;
  background: var(--surface); border-bottom: 1px solid var(--purple-deep); color: var(--muted);
  font-size: 9.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
.cal-next-day--today { color: var(--yellow); border-bottom-color: var(--yellow); }
.cal-next-item { padding: 1px 0 3px; }
/* The rail has room: titles wrap to two lines there instead of being cut. */
.cal-next-item .cal-event-title { white-space: normal; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cal-next-item .cal-event { align-items: flex-start; }
.cal-next-item .cal-time, .cal-next-item .cal-cc, .cal-next-item .cal-tag { margin-top: 1px; }
.cal-next-item .cal-event { gap: 4px; padding: 1px 3px; }
.cal-next-item .cal-cc { padding: 0 3px; }
.cal-next-detail {
  margin: 0 0 0 14px; color: var(--muted); font-size: 10px; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.cal-legend { flex: none; display: flex; flex-wrap: wrap; gap: 3px 9px; padding: 5px 8px; border-top: 1px solid var(--line); color: var(--muted); font-size: 9px; }
.cal-legend-item { display: inline-flex; align-items: center; gap: 4px; }
.cal-updated { flex: none; margin: 0; padding: 4px 8px; border-top: 1px solid var(--line); color: var(--subtle); font-size: 9px; }
.cal-empty { margin: 0; padding: 16px; color: var(--muted); font-size: 12px; }

/* --- popover ------------------------------------------------------------------------------- */

.cal-pop {
  width: min(520px, calc(100vw - 32px)); padding: 14px 16px 16px; border-radius: 4px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.cal-pop-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cal-pop-meta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; letter-spacing: .06em; text-transform: uppercase; }
.cal-pop-close { width: 26px; height: 26px; flex: none; border: 1px solid var(--purple); border-radius: 3px; background: var(--ink); color: var(--yellow); font-size: 16px; line-height: 1; cursor: pointer; }
.cal-pop-close:hover { background: var(--purple); }
.cal-pop-title { margin: 8px 0 4px; color: var(--cal-c, var(--yellow)); font-size: 16px; line-height: 1.25; }
.cal-pop-when { margin: 0 0 8px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.cal-pop-detail { margin: 0 0 10px; color: var(--text); font-size: 13px; line-height: 1.5; }
.cal-pop-source { display: inline-block; max-width: 100%; overflow-wrap: anywhere; color: var(--yellow); font-size: 11px; text-decoration: underline; }

/* --- narrow screens ------------------------------------------------------------------------- */
/* The month grid needs width. Below 900 px the rail moves under it and the panel gives up its
   fixed height, so a phone scrolls the page instead of squeezing seven columns into nothing. */
@media (max-width: 900px) {
  .calendar-panel { height: auto; min-height: 0; overflow: visible; }
  .cal { height: auto; grid-template-columns: minmax(0, 1fr); }
  .cal-grid { min-height: 62vh; }
  .cal-rail { max-height: 70vh; }
}
