:root {
  --bg: #f4f2ec;
  --surface: #fffefb;
  --sunken: #ebe8df;
  --ink: #1d1c19;
  --muted: #6a665c;
  --line: #d9d5c9;
  --accent: #0a6a4b;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe6;
  --warn: #9a5a00;
  --warn-soft: #fbedcf;
  --bad: #a3271b;
  --bad-soft: #f9dfda;
  --claude: #c2571a;
  --gemini: #2456c9;
  --deepseek: #6b3fc4;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171613;
    --surface: #201f1b;
    --sunken: #131210;
    --ink: #ece9e1;
    --muted: #a09b8e;
    --line: #37352e;
    --accent: #4cc497;
    --accent-ink: #0c1a14;
    --accent-soft: #1b3329;
    --warn: #e4b05a;
    --warn-soft: #3a2e15;
    --bad: #f08a7c;
    --bad-soft: #3d1f1b;
    --claude: #e58a52;
    --gemini: #7da2f5;
    --deepseek: #a98bf0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }

.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }

/* ---------- pasek boczny ---------- */
.side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 22px;
  padding: 20px 14px; border-right: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: -0.01em; padding: 0 8px; }
.side-label { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 8px 6px; }
.side-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; padding: 7px 8px; border: 0; border-radius: 6px;
  background: none; text-align: left; cursor: pointer;
}
.side-item:hover { background: var(--sunken); }
.side-item[aria-current="true"] { background: var(--ink); color: var(--bg); }
.side-item .count {
  min-width: 22px; padding: 0 6px; border-radius: 10px; text-align: center;
  font-size: 12px; font-weight: 600; background: var(--accent); color: var(--accent-ink);
}
.side-item.add { color: var(--muted); }
.new-project { display: flex; gap: 6px; padding: 4px 8px; }
.new-project input { min-width: 0; flex: 1; }
.jobs { margin-top: auto; font-size: 13px; color: var(--muted); padding: 0 8px; }
.job { display: flex; gap: 8px; align-items: baseline; padding: 4px 0; }
.job::before {
  content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
}

/* ---------- logowanie ---------- */
.shell.locked { grid-template-columns: 1fr; }
.shell.locked .side { display: none; }
.shell.locked main { max-width: none; display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login { width: min(360px, 100%); padding: 26px; margin: 0; }
.login h1 { font-size: 20px; letter-spacing: -0.01em; margin-bottom: 18px; }
.login .btn { width: 100%; }
input[type="password"] { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }

/* ---------- treść ---------- */
main { padding: 26px 32px 60px; max-width: 1080px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.head h1 { font-size: 24px; letter-spacing: -0.02em; line-height: 1.2; }
.head p { color: var(--muted); }
.tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: var(--warn-soft); color: var(--warn); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; margin-bottom: 14px; }
.card h3 { font-size: 17px; letter-spacing: -0.01em; }
.card-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.meta { color: var(--muted); font-size: 13px; }
.to { font-size: 13px; text-align: right; }
.to label { font-weight: 400; color: var(--muted); }
.to { flex: 0 1 300px; }
.to input { width: 100%; margin-bottom: 4px; font-weight: 600; text-align: right; }
.why { font-size: 14px; color: var(--muted); margin-bottom: 12px; max-width: 80ch; }

.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: var(--sunken); color: var(--muted); white-space: nowrap; }
.tag.ok { background: var(--accent-soft); color: var(--accent); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- przyciski i pola ---------- */
.btn {
  padding: 7px 13px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.quiet { border-color: transparent; background: none; color: var(--muted); }
.btn.quiet:hover { color: var(--ink); background: var(--sunken); }
.btn.danger:hover { color: var(--bad); border-color: var(--bad); }
.btn:disabled { opacity: 0.5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type="text"], input[type="email"], input[type="number"], select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface);
}
input[type="number"] { width: 76px; }
select { width: auto; }
textarea { resize: vertical; min-height: 72px; line-height: 1.5; }
#p-description { min-height: 170px; }
#p-ai_guidelines, textarea[data-field="definition"] { min-height: 96px; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.hint { font-size: 13px; color: var(--muted); font-weight: 400; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 200px; }
.row > .field.narrow { flex: 0 0 auto; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; font-size: 14px; }
.check input { width: auto; }

/* ---------- szkic w kolejce ---------- */
.variants { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.variant {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface); cursor: pointer; font-size: 13px;
}
.variant::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.variant[data-provider="claude"]::before { background: var(--claude); }
.variant[data-provider="gemini"]::before { background: var(--gemini); }
.variant[data-provider="deepseek"]::before { background: var(--deepseek); }
.variant[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); font-weight: 600; }
.variant:disabled { opacity: 0.55; cursor: default; text-decoration: line-through; }
.variant .score { font-variant-numeric: tabular-nums; }
.judge { font-size: 13px; color: var(--muted); margin-bottom: 12px; min-height: 20px; }
.draft .subject { font-weight: 600; margin-bottom: 8px; }
.draft textarea.body { min-height: 190px; }
.footer-preview {
  margin: 8px 0 14px; padding: 8px 10px; border-left: 3px solid var(--line);
  font: inherit; font-size: 13px; color: var(--muted); white-space: pre-wrap;
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions .spacer { flex: 1; }
.incoming { background: var(--sunken); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.incoming pre, .thread pre { margin: 6px 0 0; font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- tabele ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td a { color: inherit; }
td .sub { display: block; font-size: 12px; color: var(--muted); }
td select { padding: 3px 6px; font-size: 13px; }
td .actions { flex-wrap: nowrap; justify-content: flex-end; gap: 2px; }
td .btn { padding: 4px 9px; font-size: 13px; }
.thread td { background: var(--sunken); }
.thread .msg { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.thread .msg:last-child { border-bottom: 0; }

/* ---------- wyniki ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.tile b { display: block; font-size: 28px; letter-spacing: -0.02em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.tile span { font-size: 13px; color: var(--muted); }
.section-title { font-size: 16px; margin: 24px 0 10px; }
.log { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.log li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; gap: 12px; }
.log time { flex: none; width: 108px; color: var(--muted); font-size: 13px; }

.empty { padding: 28px 0; color: var(--muted); max-width: 62ch; }
.empty h3 { color: var(--ink); font-size: 17px; margin-bottom: 8px; }
.steps { margin: 12px 0 0; padding-left: 20px; }
.steps li { margin-bottom: 6px; }
.steps li.done { color: var(--accent); }
code { font-family: Consolas, "Cascadia Mono", monospace; font-size: 13px; background: var(--sunken); padding: 1px 5px; border-radius: 4px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: min(560px, 92vw); padding: 10px 16px; border-radius: 8px;
  background: var(--ink); color: var(--bg); font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity 0.15s;
}
.toast.show { opacity: 1; }
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); gap: 12px; padding: 14px 12px; }
  #nav { display: flex; gap: 4px; overflow-x: auto; }
  #nav .side-item { width: auto; white-space: nowrap; }
  main { padding: 18px 16px 48px; }
  .to { text-align: left; flex-basis: 100%; }
  .to input { text-align: left; }
}
