:root {
  --bg: #f3f4f1;
  --surface: #ffffff;
  --surface-2: #f8f9f7;
  --border: #dfe3dd;
  --border-strong: #c5ccc4;
  --text: #1b221f;
  --muted: #5d6963;
  --accent: #1f6f5c;
  --accent-hover: #185a4a;
  --accent-soft: #e2f0ec;
  --accent-text: #ffffff;
  --profile-soft: #eceef3;
  --profile-text: #4a5470;
  --warn-soft: #fff4dc;
  --warn-border: #f0d28b;
  --warn-text: #6b4b00;
  --danger: #b3261e;
  --flash: #fff2bf;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 20 / 6%), 0 2px 8px rgb(16 24 20 / 4%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513;
    --surface: #181d1b;
    --surface-2: #1d2321;
    --border: #2b3330;
    --border-strong: #3a4440;
    --text: #e6ebe8;
    --muted: #9aa6a0;
    --accent: #4fb89b;
    --accent-hover: #6fcbb1;
    --accent-soft: #1d3530;
    --accent-text: #08130f;
    --profile-soft: #252a36;
    --profile-text: #b3bbd3;
    --warn-soft: #33290f;
    --warn-border: #6a5418;
    --warn-text: #f3d68f;
    --danger: #ff8a80;
    --flash: #3b3517;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 84px;
}

h2 {
  font-size: 1rem;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

code { font-size: .85em; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand svg { width: 30px; height: 30px; fill: none; stroke: var(--accent); stroke-width: 3; }
.brand strong { display: block; font-size: 1.05rem; }
.brand span { color: var(--muted); font-size: .85rem; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 20px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 24px;
  align-items: start;
}
.side { position: sticky; top: 20px; display: grid; gap: 20px; max-height: calc(100vh - 124px); overflow: auto; }
.main { display: grid; gap: 20px; min-width: 0; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .side { position: static; max-height: none; overflow: visible; }
  .topbar { padding: 12px 16px; }
  .brand span { display: none; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; margin-bottom: 4px; }
.card-head h2 { margin-bottom: 8px; }
.step {
  display: inline-grid;
  place-items: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: .75rem;
}
.legend, .hint { color: var(--muted); font-size: .82rem; margin: 0; }

/* ---------- tags ---------- */
.tag {
  display: inline-block;
  font-style: normal;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 4px;
  vertical-align: 1px;
  margin-left: 4px;
}
.tag.ai { background: var(--accent-soft); color: var(--accent); }
.tag.profile { background: var(--profile-soft); color: var(--profile-text); }

/* ---------- form ---------- */
fieldset {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 0;
  padding: 14px 0 6px;
  min-width: 0;
}
legend {
  font-weight: 600;
  font-size: .88rem;
  padding: 0 8px 0 0;
}
.grid { display: grid; gap: 0 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 640px) { .g2, .g3 { grid-template-columns: 1fr; } }

.field { display: block; margin: 0 0 12px; min-width: 0; }
.field > span { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 4px; }
.field.narrow { max-width: 260px; }

input, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 10px;
  transition: border-color .15s, box-shadow .15s, background-color .6s;
}
textarea { resize: vertical; min-height: 44px; }
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
input[type="date"] { font-variant-numeric: tabular-nums; }
.is-missing { border-color: var(--danger); }
.just-filled { background: var(--flash); }

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-size: .9rem;
  font-weight: 500;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.btn.small { padding: 5px 10px; font-size: .82rem; }
.btn.block { width: 100%; }
.btn.icon { padding: 4px 8px; line-height: 1; }
.link {
  font: inherit;
  font-size: .78rem;
  border: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0 0 0 6px;
}
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

/* ---------- upload ---------- */
.dropzone {
  display: grid;
  justify-items: center;
  gap: 4px;
  text-align: center;
  padding: 26px 16px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color .15s, background-color .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone svg { width: 28px; height: 28px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dropzone span { color: var(--muted); font-size: .8rem; }

.file-list { list-style: none; margin: 12px 0; padding: 0; display: grid; gap: 6px; }
.file-list:empty { display: none; }
.file-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: .85rem;
  padding: 6px 6px 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.file-list li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list small { color: var(--muted); margin-left: 6px; }
.dropzone + .file-list:empty + .btn { margin-top: 14px; }

.status { font-size: .85rem; color: var(--muted); margin: 10px 0 0; min-height: 1.2em; }
.status.error { color: var(--danger); }
.status.busy::before {
  content: "";
  display: inline-block;
  width: 12px; height: 12px;
  margin-right: 8px;
  vertical-align: -1px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- summary ---------- */
.summary dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 12px; font-size: .85rem; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; overflow-wrap: anywhere; white-space: pre-line; }
.callout { border-radius: 8px; padding: 10px 12px; font-size: .85rem; margin-bottom: 12px; }
.callout.warn { background: var(--warn-soft); border: 1px solid var(--warn-border); color: var(--warn-text); }

/* ---------- spis ---------- */
.spis { list-style: none; margin: 4px 0 12px; padding: 0; display: grid; gap: 6px; counter-reset: spis; }
.spis li {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 72px auto;
  gap: 8px;
  align-items: center;
  counter-increment: spis;
}
.spis li::before { content: counter(spis) "."; color: var(--muted); font-size: .85rem; text-align: right; font-variant-numeric: tabular-nums; }
.spis input { padding: 6px 8px; }
.spis .page { text-align: center; font-variant-numeric: tabular-nums; }
.spis .tools { display: flex; gap: 2px; }
@media (max-width: 640px) {
  .spis li { grid-template-columns: 20px minmax(0, 1fr) 56px; }
  .spis .tools { grid-column: 2 / -1; justify-content: flex-end; }
}

/* ---------- settings ---------- */
.settings summary { cursor: pointer; font-weight: 600; font-size: .95rem; }
.settings details[open] summary { margin-bottom: 10px; }
.settings .hint { margin-bottom: 12px; }

/* ---------- action bar ---------- */
.actionbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  z-index: 10;
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.missing { margin: 0; font-size: .82rem; color: var(--muted); min-width: 0; }
.missing.has { color: var(--danger); }
@media (max-width: 760px) {
  body { padding-bottom: 150px; }
  .actionbar { flex-direction: column; align-items: stretch; padding: 10px 16px; }
  .actions .btn { flex: 1; }
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: .85rem;
  z-index: 20;
  max-width: calc(100vw - 32px);
}
.toast.error { background: var(--danger); color: #fff; }
