:root {
  color-scheme: light dark;
  --bg: #f7f6f2;
  --surface: #ffffff;
  --line: #e3e0d8;
  --text: #1a1c19;
  --muted: #5f6b62;
  --brand: #0b3d2e;
  --brand-soft: #cde8db;
  --danger: #b3261e;
  --warn: #8a5a00;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11140f; --surface: #191c18; --line: #2b302a;
    --text: #e3e3dd; --muted: #a3ada5; --brand: #8fd6bb; --brand-soft: #17503d;
    --danger: #ff8f83; --warn: #e0b25c;
  }
}
* { box-sizing: border-box; }

/* Reguły z `display` na klasach biją domyślne [hidden] { display: none },
   więc elementy chowane atrybutem `hidden` (nakładka modalna, ekran logowania)
   zostawały na wierzchu i przechwytywały kliknięcia. */
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2 { margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.05rem; }
.mt { margin-top: 1.4rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); min-height: 1.2em; margin: .4rem 0 0; }
.warn { color: var(--warn); }
code { background: var(--bg); padding: .1em .35em; border-radius: 4px; }

/* logowanie */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 1rem; }
.login-box {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 2rem; width: min(380px, 100%); display: grid; gap: .75rem;
}

/* układ */
header {
  display: flex; gap: 1rem; align-items: center; flex-wrap: wrap;
  padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; color: var(--brand); letter-spacing: .02em; }
nav { display: flex; gap: .25rem; flex-wrap: wrap; }
nav button {
  background: none; border: 0; padding: .45rem .7rem; border-radius: 99px;
  color: var(--muted); cursor: pointer; font: inherit;
}
nav button.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
header .right { margin-left: auto; display: flex; gap: .5rem; align-items: center; }
.pill {
  font-size: .8rem; padding: .2rem .6rem; border-radius: 99px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.pill.on { border-color: var(--brand); color: var(--brand); }
main { padding: 1rem; max-width: 1200px; margin: 0 auto; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem;
}

/* formularze */
input, textarea, select, button { font: inherit; color: inherit; }
input[type=text], input[type=password], input[type=search], input[type=number],
input[type=datetime-local], textarea, select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: .5rem .65rem; width: 100%;
}
textarea { resize: vertical; font-family: inherit; }
label.block { display: block; margin: .6rem 0; }
label.block input { margin-top: .25rem; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: end; margin: .5rem 0; }
.row label { display: flex; gap: .4rem; align-items: center; white-space: nowrap; }
.row label input[type=number] { width: 5rem; }
.row .grow { flex: 1; display: block; }
.radios { display: flex; gap: 1rem; margin: .4rem 0; }
.radios label, .check { display: flex; gap: .4rem; align-items: center; cursor: pointer; }
.check { margin: .6rem 0; }
button {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: .5rem .9rem; cursor: pointer;
}
button:hover { border-color: var(--brand); }
button.primary { background: var(--brand); color: var(--surface); border-color: var(--brand); font-weight: 600; }
@media (prefers-color-scheme: dark) { button.primary { color: #04231a; } }
button.big { width: 100%; padding: .8rem; margin-top: .8rem; font-size: 1rem; }
button.ghost { background: none; }
button.danger { color: var(--danger); border-color: transparent; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* licznik */
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin: .5rem 0; }
.chips button { padding: .25rem .6rem; border-radius: 99px; font-size: .85rem; }
.counter { display: flex; gap: 1rem; align-items: center; margin: .5rem 0; flex-wrap: wrap; }
.badge {
  font-size: .75rem; padding: .15rem .5rem; border-radius: 99px;
  background: var(--brand-soft); color: var(--brand); font-weight: 600;
}
.badge.unicode { background: #f6dcd9; color: var(--danger); }
@media (prefers-color-scheme: dark) { .badge.unicode { background: #4a2320; } }
.preview {
  background: var(--bg); border: 1px dashed var(--line); border-radius: 8px;
  padding: .6rem; margin-top: .6rem; white-space: pre-wrap; word-break: break-word;
}

/* tabela kontaktów */
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .6rem; }
.toolbar input[type=search] { flex: 1 1 220px; }
.toolbar select { width: auto; }
.selbar {
  display: flex; gap: .5rem; align-items: center; flex-wrap: wrap;
  background: var(--bg); border-radius: 8px; padding: .4rem .6rem; margin-bottom: .6rem;
}
.tablewrap { overflow-x: auto; max-height: 62vh; overflow-y: auto; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); }
th { position: sticky; top: 0; background: var(--surface); z-index: 1; font-size: .82rem; color: var(--muted); }
tr.out td { opacity: .55; }
td.num { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* kampanie */
.camp { border: 1px solid var(--line); border-radius: 8px; padding: .8rem; margin-bottom: .7rem; }
.camp header { all: unset; display: flex; gap: .6rem; align-items: baseline; flex-wrap: wrap; }
.bar { height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; margin: .5rem 0; }
.bar > i { display: block; height: 100%; background: var(--brand); }
.jobs { max-height: 260px; overflow: auto; margin-top: .5rem; font-size: .85rem; }
.jobs div { display: flex; justify-content: space-between; gap: 1rem; padding: .15rem 0; }
.ok { color: var(--brand); }
.bad { color: var(--danger); }

/* modal */
.modal { position: fixed; inset: 0; background: #0008; display: grid; place-items: center; padding: 1rem; z-index: 50; }
.modal-box {
  background: var(--surface); border-radius: var(--radius); padding: 1.2rem;
  width: min(560px, 100%); max-height: 85dvh; overflow: auto;
}

/* ---------- dodatki: szablony, listy, powiadomienia, klawiatura ---------- */

/* Dwa pola obok siebie. Nie używamy tu `.row`, bo `.row label` jest ustawione
   na flex z nowrap i zderza się z etykietą, która ma mieć pole pod spodem. */
.two { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
@media (max-width: 520px) { .two { grid-template-columns: 1fr; } }

.center { text-align: center; }
.spacer { flex: 1; }
.grow { flex: 1; }
.w6 { width: 6rem; flex: none; }
.end { justify-content: flex-end; }
.big-num { font-size: 1.15rem; margin: .3rem 0; }
.pre { white-space: pre-wrap; }
.clip {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
}
button.tiny { padding: .2rem .5rem; font-size: .82rem; }
td.right-cell { white-space: nowrap; text-align: right; }
kbd {
  font: inherit; font-size: .8em; padding: .1em .4em; border-radius: 4px;
  border: 1px solid var(--line); background: var(--bg);
}
table.keys td { border: 0; padding: .2rem .6rem .2rem 0; }

/* sortowanie kolumn */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sortable.asc::after { content: " ▲"; font-size: .7em; }
th.sortable.desc::after { content: " ▼"; font-size: .7em; }
th.num, td.num { text-align: left; }

/* przeciąganie pliku */
#drop-zone.dragging { outline: 2px dashed var(--brand); outline-offset: -6px; }

/* listy (podgląd importu, szczegóły kampanii, szablony) */
.list { margin-top: .5rem; font-size: .88rem; }
.list.tall { max-height: 300px; overflow: auto; }
.list > div {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: .25rem 0; border-bottom: 1px solid var(--line);
}
.tpl {
  display: flex; gap: .5rem; align-items: center;
  padding: .45rem 0; border-bottom: 1px solid var(--line);
}
.camp-head { display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; margin-bottom: .3rem; }

/* powiadomienia */
.toasts {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 100;
  display: flex; flex-direction: column; gap: .5rem; align-items: flex-end;
}
.toast {
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--brand);
  border-radius: 8px; padding: .6rem .9rem; max-width: 380px;
  box-shadow: 0 6px 20px #0003; animation: toast-in .2s ease-out;
}
.toast.ok { border-left-color: var(--brand); }
.toast.bad { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
.toast.out { opacity: 0; transform: translateY(6px); transition: .35s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 700px) {
  .toolbar button { flex: 1 1 auto; }
  td.right-cell { text-align: left; }
}
