:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --ink: #1d2533;
  --muted: #6b7587;
  --line: #e1e5ec;
  --brand: #215AA8;
  --brand-ink: #ffffff;
  --danger: #c62828;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 8px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 "Work Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--brand); }
h1 { font-size: 22px; margin: 0 0 16px; font-weight: 600; }
h1 small { color: var(--muted); font-weight: 400; font-size: 15px; margin-left: 6px; }
h2 { font-size: 18px; margin: 0 0 12px; font-weight: 600; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; margin: 4px 0 0; display: block; }
[hidden] { display: none !important; }

/* hlavička */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; text-decoration: none; color: var(--ink); }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; }
.top nav a {
  text-decoration: none; color: var(--ink); padding: 7px 12px; border-radius: 8px; font-weight: 500;
}
.top nav a:hover { background: var(--bg); }
.top nav a.on { background: var(--brand); color: var(--brand-ink); }
.top nav a.muted { color: var(--muted); }
main { padding: 24px; max-width: 1500px; margin: 0 auto; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* tlačítka a formuláře */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #c5ccd8; background: #fafbfc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: wait; }

label { display: block; font-weight: 500; font-size: 13.5px; margin-bottom: 12px; }
input[type=text], input[type=search], input[type=password], input[type=number], textarea, select {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px; font: inherit; font-weight: 400;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
textarea { resize: vertical; min-height: 44px; }
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(33, 90, 168, .25); border-color: var(--brand); }
input[type=color] { display: block; width: 100%; height: 38px; margin-top: 4px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
input[type=range] { width: 100%; }
label.chk { display: flex; align-items: center; gap: 8px; font-weight: 400; }
label.chk.inline { margin-top: 26px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
fieldset { border: 0; padding: 0; margin: 0 0 8px; }
legend { font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 10px; }
fieldset + fieldset { border-top: 1px solid var(--line); padding-top: 16px; }
.btn-bottom { display: flex; align-items: flex-end; padding-bottom: 12px; }

/* segmentový přepínač šablon */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 6px; }
.seg button {
  padding: 9px 8px; border: 1px solid var(--line); background: #fff; border-radius: 8px;
  font: inherit; font-size: 13px; cursor: pointer;
}
.seg button.on { border-color: var(--brand); background: rgba(33, 90, 168, .08); color: var(--brand); font-weight: 600; }

/* přehled */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 20px; }
.toolbar h1 { margin: 0; margin-right: auto; }
.filters { display: flex; gap: 8px; }
.filters input, .filters select { margin: 0; width: auto; }
.filters input { width: 240px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.post { overflow: hidden; display: flex; flex-direction: column; }
.post .thumb { display: block; background: #e9edf3; aspect-ratio: 1 / 1; }
.post .thumb.fmt-portrait { aspect-ratio: 4 / 5; }
.post .thumb.fmt-story { aspect-ratio: 9 / 16; }
.post .thumb.fmt-landscape { aspect-ratio: 1200 / 630; }
.post .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.post .meta { padding: 10px 12px 4px; flex: 1; }
.post h3 { font-size: 14px; margin: 6px 0 2px; font-weight: 600; line-height: 1.35; }
.post .meta p { margin: 0; font-size: 12px; }
.post .actions { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 12px 12px; }
.chip { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; }
.empty { padding: 40px; text-align: center; }
.pager { display: flex; gap: 4px; margin-top: 24px; justify-content: center; }
.pager a { padding: 6px 11px; border-radius: 8px; text-decoration: none; background: #fff; border: 1px solid var(--line); }
.pager a.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* editor */
.editor { display: grid; grid-template-columns: minmax(340px, 440px) 1fr; gap: 24px; align-items: start; }
.panel { padding: 20px; }
.preview { position: sticky; top: 76px; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px; margin-bottom: 16px; }
.bar .sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
.status { color: var(--muted); font-size: 13px; margin-left: auto; padding-right: 6px; }
.canvas-wrap {
  display: flex; justify-content: center; align-items: flex-start; padding: 24px; border-radius: var(--radius);
  background: repeating-conic-gradient(#e7eaf0 0% 25%, #f1f3f7 0% 50%) 50% / 24px 24px;
}
#cv { max-width: 100%; max-height: calc(100vh - 220px); width: auto; height: auto; box-shadow: 0 8px 30px rgba(0, 0, 0, .18); background: #fff; }
.icon-pick { display: flex; gap: 8px; align-items: center; }
.icon-pick select { flex: 1; }
#icon-prev { width: 40px; height: 40px; margin-top: 4px; border: 1px solid var(--line); border-radius: 8px; flex: none; }
.photo-row { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.photo-row > div:not(.photo-prev) { min-width: 0; flex: 1; }
input[type=file]::file-selector-button { font: inherit; font-weight: 500; padding: 7px 12px; margin-right: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); cursor: pointer; }
input[type=file]::file-selector-button:hover { border-color: #c5ccd8; background: #fafbfc; }
.photo-row input[type=file] { font-size: 13px; margin-bottom: 6px; display: block; width: 100%; max-width: 100%; }
.photo-prev { width: 84px; height: 84px; border-radius: 8px; background: #e9edf3 center / cover no-repeat; border: 1px solid var(--line); flex: none; }
.photo-box > label { margin-bottom: 6px; }

/* nastavení */
.settings { display: grid; gap: 24px; }
.settings section { padding: 24px; }
.logos { margin: 8px 0; }
.logo-slot input[type=file] { width: 100%; max-width: 100%; font-size: 13px; }
.logo-slot { min-width: 0; border: 1px dashed var(--line); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.logo-prev { height: 90px; border-radius: 8px; display: flex; align-items: center; justify-content: center; background: #f3f5f8; color: var(--muted); font-size: 13px; }
.logo-prev.dark { background: #16365c; color: #9fb3cc; }
.logo-prev img { max-height: 70px; max-width: 90%; }
.cat-head, .cat-row {
  display: grid; grid-template-columns: 52px 1.1fr 0.9fr 1fr 1fr 1fr 1fr 64px 52px 120px; gap: 8px; align-items: center;
}
.cat-head { font-size: 12px; color: var(--muted); font-weight: 600; padding: 0 0 6px; }
.cat-row { padding: 8px 0; border-top: 1px solid var(--line); }
.cat-row input, .cat-row select { margin: 0; }
.cat-row input[type=checkbox] { width: 18px; height: 18px; margin: 0; }
.cat-row.off { opacity: .55; }
.cat-row.dirty [data-save] { box-shadow: 0 0 0 3px rgba(33, 90, 168, .3); }
.cat-row .sw { width: 52px; height: 52px; border-radius: 8px; }
.cat-act { display: flex; gap: 4px; }
#cat-add { margin-top: 12px; }

/* toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: #1d2533; color: #fff; padding: 10px 18px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.toast.err { background: var(--danger); }

/* přihlášení */
body.login { display: grid; place-items: center; min-height: 100vh; }
.login-box { padding: 32px; width: 340px; max-width: calc(100vw - 32px); }
.login-box .btn { width: 100%; justify-content: center; }
.err { color: var(--danger); }


/* CI: dvoubarevná linka pod hlavičkou (polcený štít) */
.top { border-bottom: 0; box-shadow: inset 0 -4px 0 0 transparent; background-image: linear-gradient(90deg, #FFF100 50%, #215AA8 50%); background-size: 100% 4px; background-repeat: no-repeat; background-position: bottom; background-color: var(--card); }
h3 { font-size: 15px; margin: 20px 0 10px; font-weight: 600; }
.brand-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 8px 0 4px; }
.slot-btns { display: flex; gap: 6px; }
.logo-prev { background: #f3f5f8 repeating-conic-gradient(#eceff4 0% 25%, #f6f7fa 0% 50%) 50% / 16px 16px; }
select.pal { font-size: 13px; }
.cat-row select.pal { padding: 6px; }

/* pole kategorií: popisky jen na mobilu (na desktopu je hlavička tabulky) */
.cf { margin: 0; font-weight: 400; min-width: 0; }
.cf > span { display: none; }
.cf-chk { display: flex; justify-content: center; }

/* ---------- tablet a menší ---------- */
@media (max-width: 980px) {
  main { padding: 16px; }
  .editor { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .editor > *, .panel, fieldset { min-width: 0; }
  /* náhled nahoře, při psaní zůstává vidět */
  .preview { position: sticky; top: 0; z-index: 5; order: -1; margin: 0 -16px; padding: 8px 16px 10px; background: var(--bg); }
  .canvas-wrap { padding: 10px; }
  #cv { max-height: 36vh; }
  /* akce dole přes celou šířku */
  .bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; margin: 0; border-radius: 0; border-width: 1px 0 0;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 6px; }
  .bar .btn { justify-content: center; padding: 10px 4px; font-size: 13px; white-space: normal; text-align: center; line-height: 1.2; }
  .bar .sep { display: none; }
  .bar .status { position: absolute; top: -22px; right: 10px; font-size: 11px; background: var(--card); padding: 1px 8px; border-radius: 6px 6px 0 0; }
  body:has(.editor) main { padding-bottom: 96px; }
  body:has(.editor) .toast { bottom: 96px; }
  .top { position: static; }
  .brand-grid { grid-template-columns: 1fr 1fr; }
  .cat-head { display: none; }
  .cat-row { grid-template-columns: 52px 1fr 1fr; gap: 8px 10px; padding: 14px 0; align-items: end; }
  .cat-row .sw { grid-row: span 2; align-self: start; }
  .cf > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
  .cf-chk { flex-direction: column; align-items: flex-start; justify-content: flex-start; }
  .cat-act { grid-column: 1 / -1; justify-content: flex-end; }
}

/* ---------- telefon ---------- */
@media (max-width: 640px) {
  body { font-size: 15px; }
  /* 16px = iOS při psaní nezoomuje */
  input[type=text], input[type=search], input[type=password], input[type=number], textarea, select { font-size: 16px; padding: 10px; }
  select.pal, .cat-row select.pal { font-size: 16px; padding: 10px; }
  .top { flex-wrap: wrap; gap: 6px; padding: 10px 12px 12px; }
  .brand { font-size: 15px; }
  .top nav { width: 100%; flex-wrap: wrap; gap: 2px; }
  .top nav a { padding: 8px 10px; white-space: nowrap; font-size: 14px; }
  main { padding: 12px; }
  h1 { font-size: 19px; }
  .toolbar { gap: 8px; }
  .toolbar h1 { width: 100%; }
  .filters { width: 100%; flex-wrap: wrap; }
  .filters input { width: 100%; flex: 1 1 100%; }
  .filters select { flex: 1; }
  .toolbar > .btn.primary { width: 100%; justify-content: center; }
  .grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .post .meta { padding: 8px 10px 2px; }
  .post h3 { font-size: 13px; }
  .post .actions { padding: 6px 8px 10px; gap: 4px; }
  .post .actions .btn { flex: 1 1 auto; justify-content: center; padding: 7px 6px; }
  .panel { padding: 16px; }
  .preview { margin: 0 -12px; padding: 6px 12px 8px; }
  #cv { max-height: 34vh; }
  .row3 { grid-template-columns: 1fr; gap: 0; }
  .row2 { gap: 10px; }
  label.chk.inline { margin-top: 30px; }
  .photo-row { align-items: flex-start; }
  .settings section { padding: 16px; }
  .cat-row { grid-template-columns: 44px 1fr; }
  .cat-row .sw { width: 44px; height: 44px; grid-row: span 1; }
  .cat-row .cf:first-of-type { grid-column: 2; }
  .cat-row .cf { grid-column: 1 / -1; }
  .cat-row .cf:first-of-type { grid-column: 2; }
  .cf-chk { flex-direction: row; align-items: center; gap: 10px; }
  .cf-chk > span { margin: 0; }
  .pager { flex-wrap: wrap; }
}

@media (max-width: 400px) {
  .brand-grid { grid-template-columns: 1fr; }
  .row2 { grid-template-columns: 1fr; gap: 0; }
  label.chk.inline { margin-top: 0; }
  .btn-bottom { padding-bottom: 12px; }
}
@media (max-width: 340px) {
  .grid { grid-template-columns: 1fr; }
}
