/* RAY - one stylesheet, no framework.
 *
 * The palette and the type come from docs/design/redakcja-mockup.html: a warm
 * paper background, navy for anything the user commits to, and PAP red kept
 * scarce - the active tab, the AI button, the rule above the newsletter. Red
 * that appears everywhere stops meaning anything.
 *
 * Fonts are served from app/static/fonts, not from Google. That keeps the
 * content-security policy free of a foreign origin, keeps the newsroom working
 * when somebody else's CDN is not, and keeps who-uses-RAY-and-when to us.
 */

@font-face {
  font-family: "IBM Plex Sans";
  src: url("/static/fonts/ibm-plex-sans-latin.woff2") format("woff2");
  font-weight: 100 700;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+2000-206F, U+2122, U+2191,
    U+2193, U+2212, U+2215;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("/static/fonts/ibm-plex-sans-latin-ext.woff2") format("woff2");
  font-weight: 100 700;
  font-display: swap;
  /* Polish letters live here. */
  unicode-range: U+0100-02BA, U+0304-0308, U+0331, U+1E00-1EFF, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Source Serif 4";
  src: url("/static/fonts/source-serif-4-latin.woff2") format("woff2");
  font-weight: 200 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+2000-206F, U+2122, U+2191,
    U+2193, U+2212, U+2215;
}
@font-face {
  font-family: "Source Serif 4";
  src: url("/static/fonts/source-serif-4-latin-ext.woff2") format("woff2");
  font-weight: 200 900;
  font-display: swap;
  unicode-range: U+0100-02BA, U+0304-0308, U+0331, U+1E00-1EFF, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --paper: #f3f2ee;
  --surface: #ffffff;
  --surface-sunken: #fafaf7;
  --preview-bg: #eceef1;

  --text: #1b1f2a;
  --muted: #6b7080;
  --faint: #9a9eaa;
  --navy: #1b2a44;
  --navy-soft: #4a4f5c;
  --red: #dc371b;

  --border: #e2e0da;
  --border-strong: #d9d7d0;
  --border-mid: #c9c7bf;
  --rule: #eeece6;

  --ok: #1b6e45;
  --ok-bg: #e5f3ec;
  --warn: #8a5a00;
  --warn-bg: #fff1db;
  --danger: #b3261e;
  --danger-bg: #fbeae8;
  --info: #1b4a9a;
  --info-bg: #e9f1ff;

  --radius: 8px;
  --radius-card: 12px;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 400 14px/20px var(--sans);
  color: var(--text);
  background: var(--paper);
}

a { color: var(--navy); }
a:hover { color: var(--red); }

h1 { margin: 0 0 0.2rem; font: 700 28px/34px var(--serif); }
h2 { margin: 1.6rem 0 0.6rem; font-size: 15px; font-weight: 600; }
h3 { margin: 1.2rem 0 0.4rem; font-size: 14px; font-weight: 600; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; }

/* --- Top bar ------------------------------------------------------------- */

.topbar {
  height: 56px;
  padding: 0 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 32px;
}
.topbar .brand {
  font: 700 20px/1 var(--serif);
  letter-spacing: 0.04em;
  color: var(--navy);
  text-decoration: none;
}
.topbar nav { display: flex; gap: 24px; font-weight: 500; }
.topbar nav > a,
.topbar .menu > summary {
  padding: 17px 0;
  color: var(--navy-soft);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  list-style: none;
}
.topbar nav > a:hover, .topbar .menu > summary:hover { color: var(--text); }
.topbar nav > a.current, .topbar .menu[open] > summary {
  color: var(--text);
  border-bottom-color: var(--red);
}
.topbar .menu > summary::-webkit-details-marker { display: none; }
.topbar .spacer { flex-grow: 1; }
.topbar .who { display: flex; align-items: center; gap: 12px; color: var(--navy-soft); }

/* A details/summary dropdown: no script, so nothing to allow in the policy. */
.menu { position: relative; }
.menu > div {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 20;
  min-width: 15rem;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(27 31 42 / 12%);
  display: flex;
  flex-direction: column;
}
.menu > div a {
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
}
.menu > div a:hover { background: var(--surface-sunken); color: var(--red); }

/* --- Page shell ---------------------------------------------------------- */

main { padding: 20px 32px 32px; }
main.narrow { max-width: 46rem; }
main.wide { padding-left: 32px; padding-right: 32px; }

.lead { color: var(--muted); margin: 0 0 1.2rem; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.flush { margin: 0; }
.flush-top { margin-top: 0; }
.tight { margin-bottom: 0.3rem; }
.stack-top { margin-top: 1rem; }
.stack-bottom { margin-bottom: 1rem; }
.spaced-link { margin-left: 0.6rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px;
}

.msg {
  margin: 0 0 1rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
}
.msg.ok { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
.msg.error { border-color: var(--danger); background: var(--danger-bg); color: var(--danger); }

/* --- Controls ------------------------------------------------------------ */

button, .button {
  height: 40px;
  padding: 0 18px;
  font: 600 14px/1 var(--sans);
  color: #fff;
  background: var(--navy);
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}
button:hover, .button:hover { background: #14203a; color: #fff; }
/* An anchor styled as a button still needs to sit on the same baseline. */
.button { display: inline-block; line-height: 40px; text-decoration: none; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

button.secondary, .button.secondary {
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-mid);
}
button.secondary:hover, .button.secondary:hover {
  background: var(--surface-sunken);
  color: var(--text);
}
button.secondary.chosen { border-color: var(--navy); color: var(--navy); font-weight: 600; }

button.small { height: 32px; padding: 0 12px; font-size: 13px; }
button.tiny { height: 30px; padding: 0 10px; font-size: 12px; font-weight: 500; }
button.icon { width: 30px; padding: 0; }

/* The one red control: writing with the assistant. */
button.ai {
  height: 32px;
  padding: 0 12px;
  font: 500 13px/1 var(--sans);
  color: var(--red);
  background: var(--surface);
  border: 1px solid var(--red);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
button.ai:hover { background: #fff5f3; color: var(--red); }
button.ai:disabled { border-color: var(--border-mid); color: var(--faint); }

button.link {
  height: auto;
  padding: 0;
  font: inherit;
  color: var(--navy);
  background: none;
  border: 0;
  text-decoration: underline;
  cursor: pointer;
}
button.link:hover { background: none; color: var(--red); }

label { display: block; margin-bottom: 0.9rem; font-weight: 600; font-size: 12px; color: var(--muted); }
label .hint { display: block; font-weight: 400; color: var(--faint); }
label.checkbox { display: flex; align-items: center; gap: 0.5rem; font-weight: 400; color: var(--text); font-size: 14px; }
label.checkbox input { width: auto; margin: 0; }

input, textarea, select {
  width: 100%;
  margin-top: 6px;
  padding: 0 12px;
  height: 40px;
  font: 400 14px/38px var(--sans);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}
textarea { height: auto; padding: 10px 12px; line-height: 20px; resize: vertical; }
input[type="file"] { height: auto; padding: 8px 12px; line-height: 1.4; }
input[type="checkbox"], input[type="radio"] { height: auto; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--navy);
  outline-offset: -1px;
  border-color: var(--navy);
}

/* A pair of buttons acting as one switch. */
.segment { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.segment button {
  height: 32px;
  padding: 0 12px;
  font: 500 13px/1 var(--sans);
  color: var(--navy-soft);
  background: var(--surface);
  border: 0;
  border-radius: 0;
}
.segment button:hover { background: var(--surface-sunken); }
.segment button.chosen { background: var(--navy); color: #fff; }

.row-actions { display: inline-flex; gap: 6px; align-items: center; }
.inline-form { display: inline; }

/* --- Tables -------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.bare { background: transparent; }
table.bare th { width: 14rem; font-size: 13px; text-transform: none; letter-spacing: 0; }
table.bare th, table.bare td { border-bottom: none; padding: 0.2rem 0.7rem 0.2rem 0; }

/* --- Pills --------------------------------------------------------------- */

.tag {
  display: inline-block;
  padding: 1px 8px;
  font-size: 12px;
  line-height: 18px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--muted);
}
.tag.on { color: var(--ok); border-color: var(--ok); }
.tag.off { color: var(--danger); border-color: var(--danger); }
.tag.rank { color: var(--navy); border-color: var(--border-mid); }
.tag.brand { border-color: transparent; background: var(--info-bg); color: var(--info); }
.tag.category { border-color: transparent; background: #f0efea; color: var(--navy-soft); }
.tag.status-draft { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.tag.status-review { background: var(--info-bg); color: var(--info); border-color: transparent; }
.tag.status-scheduled { background: #ece8fb; color: #4b3b9c; border-color: transparent; }
.tag.status-sent { background: var(--ok-bg); color: var(--ok); border-color: transparent; }

/* --- Steps --------------------------------------------------------------- */

.steps { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.steps .step { display: flex; align-items: center; gap: 8px; }
.steps .step.current { color: var(--text); font-weight: 600; }
.steps .dot {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid var(--border-mid);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}
.steps .step.done .dot { background: var(--navy); border-color: var(--navy); color: #fff; }
.steps .step.current .dot { background: var(--red); border-color: var(--red); color: #fff; }
.steps .bar { width: 40px; height: 1px; background: var(--border-mid); }

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

.issuehead { display: flex; align-items: flex-end; gap: 16px; margin: 16px 0 20px; }
.issuehead .facts { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.issuehead .spacer { flex-grow: 1; }
.issuehead .actions { display: flex; gap: 8px; }

/* --- Editing screen ------------------------------------------------------ */

.editor-grid { display: flex; gap: 24px; align-items: flex-start; }
.editor-col { width: 600px; flex-shrink: 0; display: flex; flex-direction: column; gap: 16px; }
.preview-col { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
@media (max-width: 78rem) {
  .editor-grid { flex-direction: column; }
  .editor-col { width: 100%; }
}

.cardhead { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.cardhead h2 { margin: 0; white-space: nowrap; }
/* The card headers pack a title, a count and two or three controls into 600px.
   Wrapping a button label across two lines reads as a mistake, so the labels
   stay on one line and the row is allowed to be the thing that wraps. */
.cardhead { flex-wrap: wrap; }
.cardhead button, .segment button { white-space: nowrap; }
.cardhead .spacer { flex-grow: 1; }
.cardhead .count { font-size: 12px; color: var(--muted); }

.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }

/* Top five: filled slots and dashed empty ones. */
.slots { display: flex; flex-direction: column; gap: 6px; }
.slot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-sunken);
}
.slot.dragging { opacity: 0.4; }
.slot.over { border-color: var(--navy); }
.slot .grip { color: var(--border-mid); font-size: 16px; cursor: grab; }
.slot .no {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  border-radius: 999px;
  background: var(--navy);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}
.slot .what { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; }
.slot .what .title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot .what .meta { font-size: 12px; color: var(--muted); }
.slot .drop { width: 28px; height: 28px; padding: 0; border: 0; background: none; color: var(--faint); font-size: 16px; }
.slot .drop:hover { background: none; color: var(--danger); }
.slot.empty {
  justify-content: center;
  height: 40px;
  border: 1px dashed var(--border-mid);
  background: transparent;
  color: var(--faint);
  font-size: 13px;
}

/* The publication list. */
.materials { display: flex; flex-direction: column; border-top: 1px solid var(--rule); }
.material {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--rule);
}
.material.excluded { opacity: 0.55; }
.material .when { width: 44px; flex-shrink: 0; text-align: right; font-size: 12px; color: var(--muted); }
.material .body { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.material .title { font-weight: 500; }
.material .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.material .summary { font-size: 13px; color: var(--navy-soft); }
.material .summary.none { color: var(--faint); font-style: italic; }
.material .pick { display: flex; gap: 6px; flex-shrink: 0; }
.material .intop {
  height: 30px;
  padding: 0 10px;
  border-radius: 6px;
  background: var(--navy);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
}
/* The publication lead reads as text and behaves as a field. A boxed input on
   every row would turn a list of headlines into a form; the border appears when
   somebody actually goes to type. */
.material .summary {
  width: 100%;
  height: auto;
  margin: 0;
  padding: 2px 0;
  font-size: 13px;
  line-height: 19px;
  color: var(--navy-soft);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
}
.material .summary.none { color: var(--faint); font-style: italic; }
.material .summary::placeholder { color: var(--faint); font-style: italic; }
.material .summary:hover { border-color: var(--border); }
.material .summary:focus {
  padding: 2px 8px;
  background: var(--surface);
  border-color: var(--navy);
  font-style: normal;
}
.more { padding: 10px 4px; font-size: 12px; color: var(--faint); text-align: center; }

/* --- Preview ------------------------------------------------------------- */

#podglad {
  flex-grow: 1;
  overflow: auto;
  background: var(--preview-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 24px;
  display: flex;
  justify-content: center;
}
iframe.preview {
  width: 720px;
  max-width: none;
  height: 76vh;
  min-height: 480px;
  border: 0;
  background: #fff;
}
.preview-shell:has(input[name="szerokosc-podgladu"][value="telefon"]:checked) iframe.preview {
  width: 400px;
}
/* The width switch: radios that look like the segment control next to them. */
.segment label.checkbox { margin: 0; position: relative; }
.segment label.checkbox input { position: absolute; opacity: 0; width: 0; height: 0; }
.segment label.checkbox span {
  display: block;
  height: 32px;
  padding: 0 12px;
  font: 500 13px/32px var(--sans);
  color: var(--navy-soft);
  background: var(--surface);
  cursor: pointer;
}
.segment label.checkbox input:checked + span { background: var(--navy); color: #fff; }
.segment label.checkbox input:focus-visible + span { outline: 2px solid var(--red); outline-offset: -2px; }

/* --- Odds and ends ------------------------------------------------------- */

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-indicator.htmx-request { display: inline; }
.qr { width: 12rem; height: 12rem; image-rendering: pixelated; }
.tokenbox { padding: 0.6rem 0.8rem; background: var(--surface-sunken); border: 1px solid var(--border); border-radius: var(--radius); word-break: break-all; }
ul.flush { margin: 0.4rem 0 0; padding-left: 1.2rem; }
ol.toplist { margin: 0; padding-left: 1.2rem; }
details summary { cursor: pointer; }

/* --- Wizard -------------------------------------------------------------- */

/* A file input dressed as a drop target. Browsers accept a dropped file on one
   natively, so this is styling, not behaviour - and nothing to allow in the
   policy. */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 140px;
  margin-bottom: 1rem;
  padding: 20px;
  font-weight: 400;
  text-align: center;
  border: 2px dashed var(--border-mid);
  border-radius: var(--radius-card);
  background: var(--surface-sunken);
  cursor: pointer;
}
.dropzone:hover { border-color: var(--navy); background: #f6f6f2; }
.dropzone .big { font-size: 16px; font-weight: 600; color: var(--text); }
.dropzone input { width: auto; margin-top: 10px; border: 0; background: none; }

.tiles { display: flex; gap: 16px; flex-wrap: wrap; }
.tile { margin: 0; font-weight: 400; cursor: pointer; }
.tile input { position: absolute; opacity: 0; width: 0; height: 0; }
.tile .frame {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 268px;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
}
.tile .frame img {
  width: 240px;
  height: 180px;
  object-fit: cover;
  object-position: top center;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #fff;
}
.tile .name { font-weight: 600; }
.tile .what { font-size: 13px; color: var(--muted); }
.tile input:checked + .frame { border-color: var(--navy); }
.tile input:focus-visible + .frame { outline: 2px solid var(--red); outline-offset: 2px; }
