/* BRZN CMS - admin design system.
   One accent, a neutral scale and an 8px spacing rhythm. Everything else
   (cards, tables, forms, toasts) is built from those three decisions. */

:root {
  --accent: #2f6f4f;
  --accent-strong: #275c42;
  --accent-soft: #e8f2ea;
  --danger: #b23b3b;
  --danger-soft: #fbeaea;
  --warn-soft: #f7ecd3;

  --ink: #1c2024;
  --ink-2: #4a5158;
  --ink-3: #666e74;
  --line: #d3d8d3;
  --line-2: #eef0ed;
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #fbfcfa;

  --sidebar: #1b1f23;
  --sidebar-ink: #e8eae9;
  --sidebar-muted: #9aa3a9;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(16, 20, 24, 0.06);
  --shadow-lg: 0 16px 40px rgba(16, 20, 24, 0.18);
  --focus: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* --- Layout -------------------------------------------------------------- */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px;
  flex: none;
  background: var(--sidebar);
  color: var(--sidebar-ink);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}
body[data-signed-in="false"] .sidebar { display: none; }

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; padding: 4px 10px 0; }
.brand img { height: 19px; width: auto; display: block; }
.brand__label {
  color: var(--accent);
  filter: brightness(1.9);
  font-weight: 700; font-size: 11px; letter-spacing: 2px;
}

.sidebar__nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar__site {
  font-size: 11px; letter-spacing: 1.4px; text-transform: uppercase;
  color: var(--sidebar-muted); padding: 0 10px 6px;
}

.sidebar a {
  display: flex; align-items: center; gap: 10px;
  color: var(--sidebar-ink); text-decoration: none;
  padding: 9px 10px; border-radius: var(--radius-sm);
  font-size: 14.5px; opacity: 0.86;
  transition: background 0.12s ease, opacity 0.12s ease;
}
.sidebar a:hover { opacity: 1; background: rgba(255, 255, 255, 0.07); }
.sidebar a[aria-current="page"] { opacity: 1; background: rgba(255, 255, 255, 0.12); font-weight: 600; }
.sidebar a svg { flex: none; opacity: 0.75; }
.sidebar a[aria-current="page"] svg { opacity: 1; }

.sidebar__foot { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, 0.1); padding-top: 10px; }

main { flex: 1; min-width: 0; }

/* Sticky page header carrying the title and the screen's primary action. */
.page-head {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 18px clamp(20px, 3.5vw, 40px);
  background: rgba(246, 247, 245, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.page-head h1 { font-size: 21px; line-height: 1.25; margin: 0; letter-spacing: -0.2px; }
.page-head__sub { color: var(--ink-3); font-size: 13.5px; margin: 2px 0 0; }
.page-head__actions { margin-left: auto; display: flex; gap: 10px; align-items: center; }

.page-body { padding: 24px clamp(20px, 3.5vw, 40px) 72px; max-width: 1080px; }
.page-intro { color: var(--ink-2); margin: 0 0 20px; max-width: 70ch; }

@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 14px; }
  .sidebar__nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar__site { display: none; }
  .sidebar__foot { margin-top: 0; border-top: none; padding-top: 0; margin-left: auto; }
  .sidebar__me { display: none; }
}

/* --- Typography ---------------------------------------------------------- */

h2 { font-size: 17px; margin: 0; }
.muted { color: var(--ink-3); }
.hint { font-size: 13px; color: var(--ink-3); margin: 6px 0 0; }

/* --- Forms --------------------------------------------------------------- */

label { display: block; margin: 16px 0 6px; font-weight: 600; font-size: 13.5px; color: var(--ink-2); }

input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="url"], input[type="search"], textarea, select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:hover, textarea:hover, select:hover { border-color: #cfd4cf; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent); box-shadow: var(--focus);
}
input[type="file"] { font-size: 14px; }
textarea { min-height: 110px; resize: vertical; line-height: 1.55; }
textarea.body { min-height: 380px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; }

.switch { display: flex; align-items: center; gap: 9px; margin: 0; font-weight: 500; font-size: 14px; color: var(--ink-2); }
.switch input { width: 17px; height: 17px; accent-color: var(--accent); }

.field-note { font-size: 12.5px; color: var(--ink-3); margin-top: 6px; }

/* --- Buttons ------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--accent); color: #fff;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 9px 16px; font: inherit; font-size: 14.5px; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.12s ease, box-shadow 0.12s ease;
}
.btn:hover { background: var(--accent-strong); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn--ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn--ghost:hover { background: var(--surface-2); border-color: #cfd4cf; }
.btn--danger { background: var(--danger); }
.btn--danger:hover { background: #9c3232; }
.btn--quiet { background: transparent; color: var(--ink-2); border-color: transparent; }
.btn--quiet:hover { background: var(--line-2); }
.btn--sm { padding: 6px 11px; font-size: 13.5px; }
.actions { margin-top: 22px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* --- Cards, tables, pills ------------------------------------------------ */

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}
.card--narrow { max-width: 400px; margin: 12vh auto; padding: 30px; }

table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
th { text-align: left; padding: 11px 16px; font-size: 12px; letter-spacing: 0.6px; text-transform: uppercase; color: var(--ink-3); background: var(--surface-2); border-bottom: 1px solid var(--line); font-weight: 600; }
td { padding: 13px 16px; border-bottom: 1px solid var(--line-2); font-size: 14.5px; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }
.row--off td { color: var(--ink-3); }

/* Reserved widths where the content changes: a row whose publish button or
   status label comes and goes must not resize the columns around it. Minimums
   rather than a fixed layout, so the title column still flexes and does not
   collapse on a narrow window. */
.table-scroll { overflow-x: auto; }
.table--articles { min-width: 720px; }
.table--articles td { vertical-align: middle; }
.table--articles th:nth-child(2), .table--articles td:nth-child(2),
.table--articles th:nth-child(3), .table--articles td:nth-child(3) { white-space: nowrap; }
.table--articles th:nth-child(4), .table--articles td:nth-child(4) { min-width: 186px; }
.table--articles th:nth-child(5), .table--articles td:nth-child(5) { width: 92px; }
.cell-actions { text-align: right; white-space: nowrap; min-width: 196px; }
.cell-actions .btn + .btn, .cell-actions .btn + a.btn { margin-left: 6px; }
/* Wide enough for "Publikuję…" with its spinner, so pressing the button does
   not widen the column under the pointer. */
.btn--publish { min-width: 122px; }

.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--line-2); color: var(--ink-2); }
.pill--draft { background: var(--warn-soft); color: #7a5a17; }
.pill--ok { background: var(--accent-soft); color: var(--accent-strong); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.grid a.card { display: block; text-decoration: none; color: inherit; margin: 0; transition: border-color 0.12s ease, box-shadow 0.12s ease; }
.grid a.card:hover { border-color: #cfd4cf; box-shadow: 0 4px 14px rgba(16, 20, 24, 0.08); }

.empty { text-align: center; padding: 48px 24px; color: var(--ink-3); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

/* --- Toggle switch -------------------------------------------------------- */

.toggle { display: inline-flex; align-items: center; gap: 10px; margin: 0; cursor: pointer; font-weight: 500; font-size: 14px; color: var(--ink-2); }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle__track {
  width: 38px; height: 22px; flex: none; border-radius: 99px; background: #cbd0cb;
  position: relative; transition: background 0.15s ease;
}
.toggle__dot {
  position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform 0.15s ease;
}
.toggle input:checked + .toggle__track { background: var(--accent); }
.toggle input:checked + .toggle__track .toggle__dot { transform: translateX(16px); }
.toggle input:focus-visible + .toggle__track { box-shadow: var(--focus); }
.toggle input:disabled + .toggle__track { opacity: 0.5; }
.toggle__label { user-select: none; }

.row-title { font-weight: 600; color: var(--ink); text-decoration: none; margin-right: 8px; }
.row-title:hover { color: var(--accent); text-decoration: underline; }

/* --- Accordion sections --------------------------------------------------- */

.section {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 10px; box-shadow: var(--shadow-sm);
}
.section summary {
  display: flex; align-items: center; gap: 10px; padding: 15px 20px;
  font-size: 15.5px; font-weight: 600; cursor: pointer; list-style: none; border-radius: var(--radius);
}
.section summary::-webkit-details-marker { display: none; }
.section summary::before {
  content: ''; width: 0; height: 0; flex: none;
  border-left: 5px solid var(--ink-3); border-top: 4.5px solid transparent; border-bottom: 4.5px solid transparent;
  transition: transform 0.15s ease;
}
.section[open] summary::before { transform: rotate(90deg); }
.section summary:hover { background: var(--surface-2); }
.section summary:focus-visible { outline: none; box-shadow: var(--focus); }
.section__count { margin-left: auto; font-size: 13px; font-weight: 400; color: var(--ink-3); }
.section__body { padding: 4px 20px 20px; border-top: 1px solid var(--line-2); }
.section--off summary { color: var(--ink-3); }

.items { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.item { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.item summary {
  display: flex; align-items: center; gap: 9px; padding: 10px 14px;
  font-size: 14.5px; cursor: pointer; list-style: none; border-radius: var(--radius-sm);
}
.item summary::-webkit-details-marker { display: none; }
.item summary::before {
  content: ''; width: 0; height: 0; flex: none;
  border-left: 4.5px solid var(--ink-3); border-top: 4px solid transparent; border-bottom: 4px solid transparent;
  transition: transform 0.15s ease;
}
.item[open] summary::before { transform: rotate(90deg); }
.item summary:hover { background: #f3f5f1; }
.item__body { padding: 0 14px 14px; }

/* --- Toasts -------------------------------------------------------------- */

.toasts { position: fixed; left: 20px; right: 20px; bottom: 20px; z-index: 60; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; pointer-events: none; }
/* Anchored on both sides: a fixed 380px stack overflowed a 320px window and
   gave the whole panel a horizontal scrollbar. */
.toast { pointer-events: auto; max-width: 380px; }
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--ink); color: #fff; padding: 12px 14px;
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  font-size: 14px; animation: toast-in 0.16s ease-out;
}
.toast--ok { background: var(--accent-strong); }
.toast--error { background: var(--danger); }
.toast__close { margin-left: auto; background: none; border: none; color: inherit; opacity: 0.7; cursor: pointer; font-size: 16px; line-height: 1; padding: 0 2px; }
.toast__close:hover { opacity: 1; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* --- Loading skeletons ---------------------------------------------------- */

.skeleton { background: linear-gradient(90deg, #ececea 25%, #f4f5f2 50%, #ececea 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; border-radius: var(--radius-sm); }
.skeleton--row { height: 54px; margin-bottom: 8px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* --- Site switcher -------------------------------------------------------- */

.switcher { position: relative; margin-bottom: 6px; }
.switcher__current {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: rgba(255, 255, 255, 0.08); color: var(--sidebar-ink); border: none; border-radius: var(--radius-sm);
  padding: 9px 10px; font: inherit; font-size: 12.5px; font-weight: 700; letter-spacing: 0.8px;
  text-transform: uppercase; cursor: pointer; text-align: left;
}
.switcher__current:hover { background: rgba(255, 255, 255, 0.14); }
.switcher__menu {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30;
  background: var(--surface); border-radius: var(--radius); padding: 8px; box-shadow: var(--shadow-lg);
}
.switcher__menu input { font-size: 14px; padding: 8px 10px; }
.switcher__list { list-style: none; margin: 6px 0 0; padding: 0; max-height: 260px; overflow-y: auto; }
.switcher__list a { display: block; color: var(--ink); padding: 8px 10px; border-radius: var(--radius-sm); font-size: 14px; text-decoration: none; }
.switcher__list a:hover { background: var(--line-2); }
.switcher__list a[aria-current="true"] { font-weight: 700; background: var(--accent-soft); }
.switcher__empty { padding: 10px; font-size: 13px; color: var(--ink-3); }

/* --- Signed-in identity ---------------------------------------------------- */

.sidebar__me { display: flex; align-items: center; gap: 10px; padding: 4px 10px 10px; }
.sidebar__avatar { border-radius: 50%; flex: none; }
.sidebar__me-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.sidebar__me-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar__me-mail { font-size: 12px; color: var(--sidebar-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar__me-role { font-size: 10.5px; letter-spacing: 1px; text-transform: uppercase; color: var(--sidebar-muted); margin-top: 2px; }

/* --- Misc ---------------------------------------------------------------- */

.cover-preview { max-width: 260px; border-radius: var(--radius-sm); display: block; margin-top: 8px; border: 1px solid var(--line); }
.notice { padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; }
.notice--ok { background: var(--accent-soft); color: var(--accent-strong); }
.notice--error { background: var(--danger-soft); color: #8d2f2f; }
.spinner { width: 15px; height: 15px; border: 2px solid rgba(255, 255, 255, 0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* The off state of a switch is a UI boundary, so it needs 3:1 of its own, and
   the whole control is the only target in its table cell: 24px minimum. */
.toggle__track {
  height: 24px;
  background: #8f978f;
}

.toggle__dot {
  width: 18px;
  height: 18px;
}

.toggle input:checked + .toggle__track .toggle__dot { transform: translateX(16px); }

.toast__close {
  min-width: 24px;
  min-height: 24px;
  display: grid;
  place-items: center;
}

/* The horizontally scrolled article table is operated with the keyboard too. */
.table-scroll:focus-visible { box-shadow: var(--focus); }

/* Keyboard users need to reach the content without walking the whole sidebar. */
.skip {
  position: absolute;
  left: -9999px;
}

.skip:focus {
  left: 12px;
  top: 12px;
  z-index: 100;
  background: var(--surface);
  color: var(--ink);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

main:focus { outline: none; }
h1:focus { outline: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  /* The loading shimmer loops until the data arrives, which is exactly the
     kind of motion this setting asks us to stop. */
  .skeleton { background: #ececea; }
}

/* Image fields: a preview next to the picker, so what is stored is visible
   before anything is saved. */
.image-field {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.image-field__preview {
  width: 132px;
  height: 88px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.image-field__controls {
  flex: 1;
  min-width: 0;
}

.image-field input[type="file"] {
  font-size: 14px;
}

@media (max-width: 560px) {
  .image-field { flex-direction: column; }
  .image-field__preview { width: 100%; height: 160px; }
}
