:root {
  --ink: #1d2733;
  --ink-2: #4a5866;
  --muted: #7b8794;
  --line: #e3e6ea;
  --bg: #f6f5f2;
  --card: #ffffff;
  --accent: #e8a33d;
  --accent-ink: #1d2733;
  --danger: #c0392b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 40, .06), 0 4px 14px rgba(20, 30, 40, .06);
  --bar: #1d2733;          /* horní lišta */
  --solid: #1d2733;        /* tmavé štítky, toast */
  --on-solid: #ffffff;
  --solid-hover: #33414f;
  --line-strong: #c8ced5;  /* rámeček při najetí */
  --input-bg: #ffffff;
  --input-line: #cfd5dc;
  --img-bg: #dde1e5;       /* místo pro obrázek, než se načte */
  --tint: #fff8ec;         /* jemné zvýraznění akcentem */
  --dropzone-bg: #fafafa;
  --dropzone-line: #c6ccd3;
  --veil: rgba(255, 255, 255, .75);
  --warn-bg: #fff1d6; --warn-ink: #6b4500; --warn-line: #f0c674;
  /* okno se zvětšenou fotkou */
  --lb-bg: #f3f2ee;
  --lb-panel: #ffffff;
  --lb-line: #e3e6ea;
  --lb-text: #1d2733;
  --lb-muted: #7b8794;
  --lb-btn: rgba(29, 39, 51, .08);
  --lb-btn-hover: rgba(29, 39, 51, .16);
  --lb-btn-ink: #1d2733;
  --lb-link: #a8650a;
  --lb-tag-bg: #ffffff;
  --lb-tag-hover: #fff8ec;
  color-scheme: light;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

/* ---------- Tmavý režim ---------- */
:root[data-theme="dark"] {
  --ink: #e4e9ee;
  --ink-2: #b4bec8;
  --muted: #8794a1;
  --line: #2b3541;
  --bg: #11161c;
  --card: #1a2129;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  --bar: #0b1015;
  --solid: #2f3c4a;
  --on-solid: #ffffff;
  --solid-hover: #3d4d5e;
  --line-strong: #46525f;
  --input-bg: #121920;
  --input-line: #36424f;
  --img-bg: #252e38;
  --tint: #2e2618;
  --dropzone-bg: #151b22;
  --dropzone-line: #3a4654;
  --veil: rgba(17, 22, 28, .78);
  --warn-bg: #3a2c10; --warn-ink: #f6d08a; --warn-line: #6b5420;
  --danger: #e2584a;
  --lb-bg: #0b0f13;
  --lb-panel: #151c24;
  --lb-line: #26303b;
  --lb-text: #ffffff;
  --lb-muted: #8f9ba8;
  --lb-btn: rgba(255, 255, 255, .08);
  --lb-btn-hover: rgba(255, 255, 255, .18);
  --lb-btn-ink: #ffffff;
  --lb-link: #e8a33d;
  --lb-tag-bg: #1f2933;
  --lb-tag-hover: #2b3845;
  color-scheme: dark;
}
:root.theme-anim, :root.theme-anim * { transition: background-color .25s ease, border-color .25s ease, color .25s ease !important; }

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
a { color: inherit; }
img { display: block; max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
[hidden] { display: none !important; }

body:not(.is-admin) .admin-only { display: none !important; }
body.is-admin .guest-only { display: none !important; }

/* ---------- Horní lišta ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .6rem clamp(.8rem, 3vw, 2rem);
  background: var(--bar); color: #fff;
}
.brand { display: flex; align-items: center; gap: .5rem; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.brand svg { width: 26px; height: 26px; fill: var(--accent); }
.nav { display: flex; align-items: center; gap: .25rem; margin-left: auto; flex-wrap: wrap; }
.theme-toggle { flex: none; }
.nav a, .nav .linklike { text-decoration: none; padding: .45rem .7rem; border-radius: 8px; color: #dfe5eb; font: inherit; }
.nav a:hover, .nav .linklike:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav a.active { color: #fff; box-shadow: inset 0 -2px 0 var(--accent); border-radius: 0; }
.nav a.btn-accent { color: var(--accent-ink); }
.nav a.btn-accent.active { box-shadow: none; }
.theme-toggle {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid rgba(255,255,255,.2);
  background: transparent; color: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { background: rgba(255,255,255,.1); }
.theme-toggle svg { width: 18px; height: 18px; fill: currentColor; }
.theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .moon { display: block; }
@media (max-width: 600px) {
  .topbar { gap: .4rem 1rem; }
  .theme-toggle { order: 1; margin-left: auto; }
  .nav { order: 2; margin-left: 0; width: 100%; }
}

/* ---------- Upozornění na úložiště ---------- */
.storage-banner {
  padding: .6rem clamp(.8rem, 3vw, 2rem); text-align: center; font-size: .95rem;
}
.storage-banner.warn { background: var(--warn-bg); color: var(--warn-ink); border-bottom: 1px solid var(--warn-line); }
.storage-banner.over { background: var(--danger); color: #fff; animation: glow 2s ease-in-out infinite; }
@keyframes glow { 50% { background: #e0533f; } }
@media (prefers-reduced-motion: reduce) { .storage-banner.over { animation: none; } }

/* ---------- Obecné ---------- */
main { padding: 1.2rem clamp(.8rem, 3vw, 2rem) 4rem; max-width: 1500px; margin: 0 auto; }
.narrow { max-width: 820px; margin: 0 auto; }

.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--line-strong); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.btn-accent:hover { background: #f0b04f; border-color: #f0b04f; }
.btn.btn-danger { color: var(--danger); }
.btn.btn-danger:hover { border-color: var(--danger); }
.btn-small { padding: .3rem .6rem; font-size: .88rem; }
.linklike { background: none; border: 0; cursor: pointer; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; font-size: 1rem; line-height: 1; color: var(--ink);
}
.icon-btn:hover { border-color: var(--line-strong); }

.page-head { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }
.page-head h1 { margin: 0; }
.page-head .count { color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 4rem 1rem; }
.empty .btn { margin-top: 1rem; }
.error { color: var(--danger); }
.spinner { margin: 3rem auto; width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.load-more { display: flex; justify-content: center; margin-top: 1.5rem; }

/* ---------- Filtry ---------- */
.filters {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: end;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .7rem; margin-bottom: 1rem;
}
.filters label { display: flex; flex-direction: column; gap: .2rem; font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.filters select, .filters input { min-width: 130px; }
.filters .grow { flex: 1 1 200px; }
.filters .grow input { width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: -.4rem 0 1rem; }
.chip {
  display: inline-flex; align-items: center; gap: .35rem; padding: .25rem .4rem .25rem .7rem;
  border-radius: 999px; background: var(--solid); color: var(--on-solid); font-size: .85rem;
}
.chip button { background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 50%; width: 20px; height: 20px; cursor: pointer; line-height: 1; }

input, select, textarea {
  font: inherit; color: var(--ink); padding: .5rem .6rem; border-radius: 8px;
  border: 1px solid var(--input-line); background: var(--input-bg); min-height: 2.5rem;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
textarea { resize: vertical; min-height: 6rem; }

/* ---------- Galerie ---------- */
.gallery {
  display: grid; gap: 6px;
  grid-template-columns: repeat(auto-fill, minmax(min(240px, 45vw), 1fr));
}
.gallery a {
  position: relative; display: block; aspect-ratio: 3 / 2; overflow: hidden; border-radius: 6px;
  background: var(--img-bg);
}
.gallery img { width: 100%; height: 100%; object-fit: cover; transition: transform .25s ease; }
.gallery a:hover img { transform: scale(1.04); }
.gallery a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 100; background: var(--lb-bg); color: var(--lb-text);
  display: grid; grid-template-columns: 1fr 340px;
}
.lb-stage { position: relative; display: flex; align-items: center; justify-content: center; min-height: 0; padding: 1rem 3.5rem; }
.lb-stage img { max-width: 100%; max-height: calc(100vh - 2rem); object-fit: contain; border-radius: 4px; }
.lb-info { background: var(--lb-panel); padding: 1.2rem; overflow-y: auto; border-left: 1px solid var(--lb-line); }
.lb-info h2 { font-size: 1.15rem; }
.lb-info .meta dt { color: var(--lb-muted); }
.lb-info a { color: var(--lb-link); }
.lb-btn {
  position: absolute; background: var(--lb-btn); color: var(--lb-btn-ink); border: 0;
  width: 44px; height: 44px; border-radius: 50%; font-size: 1.4rem; cursor: pointer;
}
.lb-btn:hover { background: var(--lb-btn-hover); }
.lb-prev { left: .7rem; top: 50%; transform: translateY(-50%); }
.lb-next { right: .7rem; top: 50%; transform: translateY(-50%); }
.lb-close { right: .7rem; top: .7rem; }
.lb-toggle { display: none; }
.lb-counter { position: absolute; left: 1rem; top: 1rem; color: var(--lb-muted); font-size: .9rem; }

@media (max-width: 800px) {
  .lightbox { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .lb-stage { padding: 3.2rem .4rem 1rem; }
  .lb-stage img { max-height: calc(100vh - 8rem); }
  .lb-info { max-height: 45vh; border-left: 0; border-top: 1px solid var(--lb-line); }
  .lightbox.info-hidden .lb-info { display: none; }
  .lb-toggle { display: block; right: 4rem; top: .7rem; font-size: 1rem; }
  .lb-prev, .lb-next { top: auto; bottom: 1rem; transform: none; }
}

/* ---------- Údaje záznamu ---------- */
.meta { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; margin: 0 0 1rem; }
.meta dt { color: var(--muted); font-size: .9rem; }
.meta dd { margin: 0; }
.note { white-space: pre-wrap; line-height: 1.5; }

.loco-tags { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 1rem; }
.loco-tag {
  display: inline-flex; align-items: stretch; border-radius: 6px; overflow: hidden;
  text-decoration: none; font-size: .9rem; border: 1px solid var(--solid);
}
.loco-tag .s { background: var(--solid); color: var(--on-solid); padding: .2rem .5rem; font-weight: 700; }
.loco-tag .n { background: var(--card); color: var(--ink); padding: .2rem .5rem; }
.loco-tag .o { background: var(--card); color: var(--muted); padding: .2rem .5rem .2rem 0; }
.loco-tag a { text-decoration: none; }
.loco-tag a.s:hover { background: var(--solid-hover); }
.loco-tag a.n:hover { background: var(--tint); }
.loco-tag em { font-style: normal; color: var(--muted); }
.lb-info .loco-tag { border-color: var(--accent); }
.lb-info .loco-tag .s { background: var(--accent); color: var(--accent-ink); }
.lb-info .loco-tag .n, .lb-info .loco-tag .o { background: var(--lb-tag-bg); color: var(--lb-text); }
.lb-info .loco-tag .o, .lb-info .loco-tag em { color: var(--lb-muted); }
.lb-info .loco-tag a.n:hover { background: var(--lb-tag-hover); }
.lb-info .loco-tag a.s:hover { background: #f0b04f; }

/* ---------- Deník ---------- */
.diary { display: grid; gap: 1rem; }
.entry-card {
  display: grid; grid-template-columns: 300px 1fr; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.entry-card .cover { position: relative; display: block; background: var(--img-bg); aspect-ratio: 3 / 2; height: 100%; }
.entry-card .cover img { width: 100%; height: 100%; object-fit: cover; }
.entry-card .cover .badge {
  position: absolute; right: .5rem; bottom: .5rem; background: rgba(0,0,0,.65); color: #fff;
  font-size: .8rem; padding: .15rem .5rem; border-radius: 999px;
}
.entry-card .body { padding: 1rem 1.2rem; min-width: 0; }
.entry-card h2 { font-size: 1.15rem; margin-bottom: .3rem; }
.entry-card h2 a { text-decoration: none; }
.entry-card h2 a:hover { text-decoration: underline; }
.entry-card .sub { color: var(--muted); margin-bottom: .7rem; font-size: .92rem; }
.entry-card .excerpt { color: var(--ink-2); margin: 0; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
@media (max-width: 680px) {
  .entry-card { grid-template-columns: 1fr; }
}

/* ---------- Detail ---------- */
.detail-head { display: flex; gap: .5rem; align-items: flex-start; flex-wrap: wrap; margin-bottom: 1rem; }
.detail-head h1 { flex: 1 1 300px; margin: 0; }
.detail-photos { display: grid; gap: .6rem; margin-bottom: 1.5rem; }
.detail-photos a { display: block; border-radius: 8px; overflow: hidden; background: var(--img-bg); }
.detail-photos img { width: 100%; height: auto; }
.detail-photos.many { grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); }
.detail-photos.many a { aspect-ratio: 3 / 2; }
.detail-photos.many img { height: 100%; object-fit: cover; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; box-shadow: var(--shadow); }
.back { display: inline-block; margin-bottom: .8rem; color: var(--ink-2); text-decoration: none; }
.back:hover { text-decoration: underline; }

/* ---------- Formulář ---------- */
.form { display: grid; gap: 1.2rem; }
.form fieldset { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); padding: 1rem 1.2rem 1.2rem; margin: 0; }
.form legend { font-weight: 700; padding: 0 .4rem; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field > span { font-size: .9rem; font-weight: 600; color: var(--ink-2); }
.field small { color: var(--muted); }
.row { display: grid; gap: .8rem; align-items: end; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.row + .row, .row + .field, .field + .row, .field + .field { margin-top: .8rem; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .4rem;
  border: 2px dashed var(--dropzone-line); border-radius: var(--radius); padding: 1.6rem; text-align: center;
  color: var(--ink-2); cursor: pointer; background: var(--dropzone-bg);
}
.dropzone.over { border-color: var(--accent); background: var(--tint); }
.dropzone strong { color: var(--ink); }
.thumbs { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-top: .8rem; }
.thumb { position: relative; border-radius: 8px; overflow: hidden; background: var(--img-bg); aspect-ratio: 3 / 2; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .tools { position: absolute; inset: auto 0 0 0; display: flex; gap: 4px; justify-content: center; padding: 4px; background: linear-gradient(transparent, rgba(0,0,0,.6)); }
.thumb .tools button { width: 28px; height: 28px; border-radius: 6px; border: 0; background: rgba(255,255,255,.9); color: #1d2733; cursor: pointer; }
.thumb .cover-label { position: absolute; left: 6px; top: 6px; background: var(--accent); color: var(--accent-ink); font-size: .72rem; font-weight: 700; padding: .1rem .4rem; border-radius: 4px; }
.thumb .progress { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--veil); color: var(--ink); font-weight: 700; }
.thumb.failed .progress { color: var(--danger); background: var(--veil); padding: .5rem; text-align: center; font-size: .85rem; }

.loco-rows { display: grid; gap: .6rem; }
.loco-row { display: grid; grid-template-columns: 1fr 1.4fr 1fr 1.2fr auto; gap: .5rem; align-items: end; }
.loco-row .field { gap: .2rem; }
.loco-row .field > span { font-size: .78rem; }
.loco-row input { width: 100%; min-width: 0; }
@media (max-width: 680px) {
  .loco-row { grid-template-columns: 1fr 1fr; padding-bottom: .6rem; border-bottom: 1px solid var(--line); }
  .loco-row .icon-btn { justify-self: end; grid-column: 2; }
}
.form-actions { display: flex; gap: .6rem; justify-content: flex-end; flex-wrap: wrap; position: sticky; bottom: 0; padding: .8rem 0; background: linear-gradient(transparent, var(--bg) 30%); }

/* ---------- Lokomotivy ---------- */
.series-list { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); }
.series-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.series-card h2 { display: flex; justify-content: space-between; align-items: baseline; font-size: 1.3rem; }
.series-card h2 a { text-decoration: none; }
.series-card h2 a:hover { text-decoration: underline; }
.series-card h2 small { font-size: .85rem; color: var(--muted); font-weight: 400; }
.series-card ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .35rem; }
.series-card li a { display: inline-block; padding: .2rem .5rem; border: 1px solid var(--line); border-radius: 6px; text-decoration: none; font-size: .9rem; }
.series-card li a:hover { border-color: var(--accent); background: var(--tint); }
.series-card li small { color: var(--muted); }
.stats { display: flex; gap: 1.5rem; flex-wrap: wrap; color: var(--ink-2); margin-bottom: 1rem; }
.stats b { font-size: 1.4rem; color: var(--ink); display: block; }

/* ---------- Přihlášení ---------- */
.login { max-width: 360px; margin: 4rem auto; }
.login form { display: grid; gap: .8rem; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%) translateY(200%); visibility: hidden;
  background: var(--solid); color: var(--on-solid); padding: .7rem 1.1rem; border-radius: 8px; z-index: 200;
  transition: transform .25s ease, visibility .25s; max-width: 90vw; box-shadow: var(--shadow);
}
#toast.show { transform: translateX(-50%) translateY(0); visibility: visible; }
#toast.err { background: var(--danger); }
