:root {
  --bg: #f7f5f2;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --border: #e5e1da;
  --accent: #c2410c;
  --accent-hover: #9a3412;
  --accent-soft: #fff1e8;
  --ok: #15803d;
  --ok-soft: #e8f6ec;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1e2125;
    --text: #e8e6e3;
    --muted: #9aa0a6;
    --border: #2e3237;
    --accent: #fb923c;
    --accent-hover: #fdba74;
    --accent-soft: #3a2518;
    --ok: #4ade80;
    --ok-soft: #173023;
    --danger: #f87171;
    --danger-soft: #3a1d1d;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; padding-bottom: 2rem; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
h1 { font-size: 1.6rem; line-height: 1.2; margin: .25rem 0; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { margin: 0; }
.wrap { width: 100%; max-width: 960px; margin: 0 auto; padding: 0 1rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none; }

/* Topbar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 56px; }
.logo { font-weight: 700; font-size: 1.15rem; text-decoration: none; color: var(--text); white-space: nowrap; }
.nav { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; justify-content: flex-end; }
.nav a { text-decoration: none; }
.inline { display: inline; margin: 0; }

/* Buttons */
.btn, button.link {
  font: inherit;
  cursor: pointer;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .6rem 1.1rem;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
@media (prefers-color-scheme: dark) { .btn { color: #1a1a1a; } }
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
@media (prefers-color-scheme: dark) { .btn:hover { color: #1a1a1a; } }
.btn-sm { padding: .35rem .8rem; font-size: .875rem; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); border-color: var(--muted); color: var(--text); }
.btn-soft { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.btn-soft:hover { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn-danger { background: transparent; color: var(--danger); border-color: transparent; }
.btn-danger:hover { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); }
button.link:hover { color: var(--accent-hover); text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Forms */
input, textarea, select {
  font: inherit;
  width: 100%;
  padding: .6rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  min-width: 0;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; font-size: .9rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.row-form { display: flex; gap: .5rem; align-items: stretch; }
.row-form input { flex: 1; }
.item-form { display: grid; gap: .75rem; grid-template-columns: 1fr; }
.item-form .full { grid-column: 1 / -1; }
.item-form .btn { justify-self: start; }
@media (min-width: 640px) {
  .item-form { grid-template-columns: 1fr 1fr; }
}

/* Cards & layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin: 1.25rem 0 1rem; }
.crumbs { margin-top: 1rem; font-size: .9rem; }
.crumbs a { text-decoration: none; }
.section-title { margin-top: 2rem; }
.empty { color: var(--muted); text-align: center; padding: 1.5rem 1rem; border: 1px dashed var(--border); border-radius: var(--radius); }
.hint { background: var(--accent-soft); padding: .6rem .9rem; border-radius: 8px; font-size: .925rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

.grid { list-style: none; padding: 0; margin: 0; display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.list-card { display: block; text-decoration: none; color: var(--text); height: 100%; margin: 0; transition: border-color .15s, transform .15s; }
.list-card:hover { border-color: var(--accent); color: var(--text); transform: translateY(-1px); }
.list-card h3 { margin-bottom: .25rem; overflow-wrap: anywhere; }

/* Flash */
.flash { padding: .7rem 1rem; border-radius: 8px; margin: 1rem 0; }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--danger-soft); color: var(--danger); }

/* Hero */
.hero { text-align: center; padding: 3rem 0 2rem; }
.hero h1 { font-size: clamp(1.8rem, 5vw, 2.6rem); }
.lead { font-size: 1.1rem; color: var(--muted); max-width: 40rem; margin: 1rem auto 1.5rem; }
.hero .actions { justify-content: center; }
.features { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.features p { margin-bottom: 0; color: var(--muted); }

/* Auth */
.auth { max-width: 420px; margin: 2rem auto; }

/* Share */
.share .row-form { margin-top: .4rem; }
.more { margin-top: .75rem; }
.more summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.more[open] summary { margin-bottom: .75rem; }
.more .row-form { margin-bottom: .75rem; }

/* Items */
.items { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .75rem; }
.item {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem;
  display: grid; gap: .6rem; grid-template-columns: 1fr; box-shadow: var(--shadow);
  scroll-margin-top: 72px;
}
.item:target { border-color: var(--accent); }
.item-title { font-size: 1.05rem; overflow-wrap: anywhere; }
.item-title a { text-decoration: none; }
.item-title a:hover { text-decoration: underline; }
.item-host { font-size: .85rem; }
.item-notes { margin: .35rem 0 0; white-space: pre-line; overflow-wrap: anywhere; }
.item.is-owned .item-title, .item.is-owned .item-title a { text-decoration: line-through; color: var(--muted); }
.item.is-done { border-left: 4px solid var(--ok); }
.item-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.item-actions form { margin: 0; }
.badges { display: flex; gap: .4rem; flex-wrap: wrap; }
.badges:empty { display: none; }
.badge { display: inline-block; font-size: .78rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); justify-self: start; }
.badge-owned { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge-done { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge-important { background: #fde8ec; color: #be123c; border-color: transparent; }
@media (prefers-color-scheme: dark) { .badge-important { background: #3b1820; color: #fda4af; } }
.item.is-important:not(.is-owned) { border-color: #f4a6b5; }
.item.is-important:not(.is-owned):target { border-color: var(--accent); }

label.check { flex-direction: row; align-items: center; gap: .5rem; cursor: pointer; }
label.check input { width: auto; margin: 0; accent-color: var(--accent); }

.my-comment {
  margin: .5rem 0 0; padding: .45rem .7rem; border-radius: 8px;
  background: var(--accent-soft); font-size: .9rem; white-space: pre-line; overflow-wrap: anywhere; text-align: left;
}
.my-comment-label { font-weight: 600; }

/* Tryb edycji: formularz zastępuje treść elementu */
.item.is-editing { display: block; }
.item.is-editing > :not(.item-edit) { display: none; }
.item-edit[hidden] { display: none; }
.form-buttons { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

.copy-form { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.copy-form select { width: auto; max-width: 14rem; padding: .35rem .5rem; font-size: .875rem; }


/* Admin table */
.table-wrap { padding: 0; overflow: hidden; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .7rem .9rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.table tr:last-child td { border-bottom: 0; }
.table tr.pending { background: var(--accent-soft); }
.table td.actions { justify-content: flex-end; }
@media (max-width: 640px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border-bottom: 1px solid var(--border); padding: .5rem 0; }
  .table td { border: 0; padding: .25rem .9rem; }
  .table td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: .85rem; }
  .table td.actions { justify-content: flex-start; display: flex; }
}

/* Mobile tweaks */
@media (max-width: 520px) {
  .hide-sm { display: none; }
  .row-form { flex-direction: column; }
  h1 { font-size: 1.4rem; }
  .page-head > form, .page-head > .btn { width: 100%; }
  .page-head > form .btn { width: 100%; }
}

.footer { padding: 1.5rem 1rem; font-size: .85rem; text-align: center; }

/* Miniatury */
/* Układ elementu: miniatura w lewej kolumnie na całą wysokość, treść po prawej */
.item { grid-template-columns: auto minmax(0, 1fr); column-gap: 1rem; align-items: start; }
.item-main { display: contents; }
.item .thumb { grid-column: 1; grid-row: 1 / span 3; }
.item-text, .item .badges, .item-actions { grid-column: 2; }
/* odstępy marginesami, żeby puste wiersze siatki nie zajmowały miejsca */
.item { row-gap: 0; }
.item .badges { margin-top: .5rem; }
.item .badges:not(:has(*)) { display: none; }
.item-actions { margin-top: .75rem; }
.thumb {
  flex: 0 0 auto;
  width: 72px; height: 72px;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.thumb-empty { background: var(--bg); font-size: 1.6rem; opacity: .55; }
.item.is-owned .thumb img { opacity: .45; filter: grayscale(.6); }
.thumb-actions { margin-top: .6rem; }
@media (min-width: 720px) {
  .thumb { width: 96px; height: 96px; }
  .item { grid-template-columns: auto minmax(0, 1fr) auto; }
  .item .thumb { grid-row: 1 / span 2; }
  .item-text { grid-column: 2 / -1; grid-row: 1; }
  .item-actions { grid-column: 2; grid-row: 2; }
  .item .badges { grid-column: 3; grid-row: 2; justify-self: end; align-self: end; margin-top: .75rem; }
  .item-notes { text-align: right; margin-left: auto; max-width: 70%; }
}


/* Formularz dodawania z podglądem linku */
.add-item { display: flex; flex-direction: column; gap: .75rem; }
.add-item .btn { align-self: flex-start; }
.add-item-body { display: flex; gap: 1rem; align-items: flex-start; }
.add-item-fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .75rem; }
.add-item .more { margin-top: 0; }
.add-item .more[open] summary { margin-bottom: .5rem; }
.preview-status { margin: -.35rem 0 0; min-height: 1.2em; color: var(--muted); }
.preview-status:empty { display: none; }
.preview-status.is-ok { color: var(--ok); }
.preview-status.is-warn { color: var(--accent); }
.preview-status.is-loading::before {
  content: ''; display: inline-block; width: .8em; height: .8em; margin-right: .4em; vertical-align: -.1em;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite;
}
.add-item.is-loading .thumb { opacity: .5; }
/* Miniatura w formularzu: cała klikalna, ołówek w prawym dolnym rogu otwiera modal */
.thumb-btn { position: relative; flex: 0 0 auto; padding: 0; border: 0; background: none; cursor: pointer; border-radius: 10px; }
.thumb-btn .thumb { pointer-events: none; }
.thumb-pencil {
  position: absolute; right: -6px; bottom: -6px;
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  font-size: .8rem; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border); box-shadow: 0 1px 3px rgba(0,0,0,.15);
  transition: border-color .15s, transform .15s;
}
.thumb-btn:hover .thumb-pencil, .thumb-btn:focus-visible .thumb-pencil { border-color: var(--accent); transform: scale(1.08); }

/* Modal ze zdjęciem */
.thumb-dialog {
  width: min(32rem, calc(100vw - 2rem)); padding: 1.1rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.thumb-dialog::backdrop { background: rgba(0,0,0,.45); }
.thumb-dialog[open] { display: flex; flex-direction: column; gap: .75rem; }
.thumb-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.thumb-dialog-head h3 { margin: 0; font-size: 1.05rem; }
.thumb-dialog-foot { display: flex; justify-content: flex-end; }
.thumb-dialog .paste-zone, .thumb-dialog [data-clear-manual] { margin: 0; }
.thumb-dialog .thumb-actions { margin-top: 0; }

.paste-zone {
  display: flex; flex-direction: column; align-items: center; gap: .2rem; text-align: center;
  padding: .8rem; margin-bottom: .6rem; border: 2px dashed var(--border); border-radius: 10px;
  color: var(--muted); font-size: .9rem; cursor: pointer;
}
.paste-zone:focus, .paste-zone:hover { border-color: var(--accent); color: var(--text); outline: none; }
.paste-zone kbd { font: inherit; font-size: .8em; padding: 0 .3em; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); }
.file-pick { display: inline; font-weight: 400; font-size: inherit; color: var(--accent); text-decoration: underline; cursor: pointer; }
[data-clear-manual] { margin: -.2rem 0 .6rem; }
.add-item input[readonly][aria-busy="true"] { opacity: .55; cursor: progress; background: var(--surface); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Listy prywatne / profil */
.new-list { display: flex; flex-direction: column; gap: .6rem; }
.new-list label.check { font-weight: 400; color: var(--muted); }
.privacy-form { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .75rem; }
.share .hint { margin: 0; }
