/* ============================================================================
   Portal dokumentów audytowych - Grupa Progres
   Bez zewnętrznych fontów i bez zależności z CDN. Kolor wiodący pobrany
   bezpośrednio z logo (assets/Grupa Progres Nowe logo-06.png): #EF7D00.

   Uwaga o kontraście: jasny #EF7D00 nie nadaje się ani na tekst na bieli (2,8:1),
   ani jako tło pod biały napis (2,9:1). Marka występuje więc w dwóch odcieniach:
   --brand-bright (#EF7D00) tam, gdzie nic nie jest pisane, oraz --brand (#A24E00)
   wszędzie tam, gdzie na kolorze stoi biały tekst (5,8:1). WCAG AA jest spełnione.
   ========================================================================== */

:root {
  /*
   * Napis na pomarańczowym tle jest BIAŁY (decyzja z 31.07.2026), więc samo tło
   * musi być ciemniejsze niż firmowy #EF7D00 - biel na nim daje tylko 2,9:1,
   * czyli poniżej progu czytelności. Poniższe #A24E00 to ten sam odcień z palety
   * (dotąd używany jako --brand-ink do tekstu) i daje z bielą 5,8:1.
   *
   * Jasny #EF7D00 zostaje jako --brand-bright i służy tam, gdzie nic na nim nie
   * jest pisane: obwódki, akcenty, wypełnienia. Tam kontrast tekstu nie wchodzi w grę.
   */
  --brand:        #A24E00;
  --brand-hover:  #8C4300;
  --brand-active: #733700;
  --brand-bright: #EF7D00;

  /*
   * Kolor przycisku głównego (decyzja z 31.07.2026). Granat zamiast pomarańczu:
   * akcja odróżnia się od marki, a nie konkuruje z nią o uwagę.
   * Biel na #15154B daje 17,2:1, czyli z ogromnym zapasem ponad próg WCAG AA.
   */
  --action:        #15154B;
  --action-hover:  #1E1E6B;
  --action-active: #0D0D33;
  --brand-ink:    #A24E00;  /* pomarańcz zdatny na tekst */
  --on-brand:     #FFFFFF;  /* napis na pomarańczowym tle - biały */
  --brand-tint:   #FFF4E8;

  --bg:        #F6F5F2;
  --surface:   #FFFFFF;
  --surface-2: #FBFAF8;
  --ink:       #1C1B19;
  --ink-2:     #55524C;
  --muted:     #6B6862;
  --border:    #DEDAD2;
  --border-2:  #C9C4B9;

  --ok:      #1B6E42;
  --ok-bg:   #E8F5ED;
  --warn:    #8A5300;
  --warn-bg: #FFF3DF;
  --err:     #A8231C;
  --err-bg:  #FDECEA;
  --on-err:  #FFFFFF;  /* napis na czerwonym tle - w ciemnym motywie odwrotnie */

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(28, 27, 25, .06), 0 4px 14px rgba(28, 27, 25, .05);
  --focus: 0 0 0 3px rgba(239, 125, 0, .45);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
          "Noto Sans", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas,
          "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #171614;
    --surface:   #201F1C;
    --surface-2: #262420;
    --ink:       #F2F0EC;
    --ink-2:     #C7C3BB;
    --muted:     #A6A199;
    --border:    #38352F;
    --border-2:  #4A463E;

    /* W ciemnym motywie jasniejszy pomarancz jest czytelny jako TEKST,
       ale pod bialym napisem nadal musi byc ciemne tlo - stad --brand bez zmian. */
    --brand-ink: #FFA24D;
    --brand-tint:#2C2117;

    /* Granat #15154B na ciemnej karcie (#201F1C) jest praktycznie nieodroznialny
       od tla - przycisk glowny przestalby wygladac jak przycisk. Rozjasniamy go
       na tyle, zeby odcinal sie od powierzchni, zachowujac biel jako napis (9,7:1). */
    --action:        #3A3A8C;
    --action-hover:  #4747A8;
    --action-active: #2C2C6B;

    --ok:      #7BD3A0;
    --ok-bg:   #17301F;
    --warn:    #F0BE6B;
    --warn-bg: #33280F;
    --err:     #F0938C;
    --err-bg:  #35201D;
    --on-err:  #2A100D;

    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 4px 14px rgba(0, 0, 0, .35);
  }
}

*, *::before, *::after { box-sizing: border-box; }

/* Atrybut hidden MUSI wygrywać z regułami display z klas (.banner, .topbar__user,
   .brand-fallback mają display: flex/grid, co w przeciwnym razie nadpisuje
   regułę [hidden] { display: none } z arkusza przeglądarki). */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; font-weight: 650; }
h1 { font-size: 1.65rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: .95rem; }
p  { margin: 0 0 .75rem; }
p:last-child { margin-bottom: 0; }

code {
  font-family: var(--mono);
  font-size: .875em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .1em .35em;
  word-break: break-word;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 3px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--brand);
  color: var(--on-brand);
  padding: .6rem 1rem;
  font-weight: 600;
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

.wrap {
  max-width: 62rem;
  margin: 0 auto;
  padding: 0 1rem;
}

/* ─────────────────────────── Pasek górny ─────────────────────────── */

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1rem;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.topbar__brand { display: flex; align-items: center; gap: .7rem; min-width: 0; }

.brand-logo { width: 34px; height: 34px; object-fit: contain; flex: none; }

.brand-fallback {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  background: var(--brand);
  color: var(--on-brand);
  font-weight: 800;
  border-radius: var(--radius-sm);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: .95rem; }
.brand-text span { font-size: .8rem; color: var(--muted); }

.topbar__user { display: flex; align-items: center; gap: .6rem; }
.user-name { font-size: .9rem; font-weight: 600; }

/* ─────────────────────────── Karty ─────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.page-title { font-size: 1.35rem; margin: 0 0 1rem; }

.card--center { text-align: center; padding: 2.5rem 1.5rem; }
.card--center .lead { max-width: 34rem; margin: 0 auto 1.5rem; color: var(--ink-2); }

.card__title {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding-bottom: .6rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

/* Numeracja kroków w tym samym granacie co przyciski - jeden system kolorów
   dla wszystkiego, co prowadzi pracownika przez zadanie. */
.step-no {
  flex: none;
  width: 1.6rem; height: 1.6rem;
  display: grid; place-items: center;
  background: var(--action);
  color: #FFFFFF;
  border-radius: 50%;
  font-size: .85rem;
  font-weight: 700;
}

/* ─────────────────────────── Przyciski ─────────────────────────── */

.btn {
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  padding: .55rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  transition: background-color .12s ease, border-color .12s ease;
}
.btn:hover:not(:disabled) { background: var(--surface); border-color: var(--action); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn--primary {
  background: var(--action);
  border-color: var(--action);
  color: #FFFFFF;
}
.btn--primary:hover:not(:disabled) { background: var(--action-hover); border-color: var(--action-hover); }
.btn--primary:active:not(:disabled) { background: var(--action-active); }

/*
 * Przycisk wymagający ponowienia (rotacja linku). Odbiorcy trzymają w skrzynce
 * adres, który przestał działać - sam czerwony akapit nad linkiem bywa przewijany,
 * więc akcja naprawcza musi być widoczna także na samym przycisku.
 * Pierścień robimy na box-shadow, żeby nie ruszyć metryki przycisku.
 */
.btn--attention {
  background: var(--err);
  border-color: var(--err);
  color: var(--on-err);
  box-shadow: 0 0 0 3px var(--err-bg);
}
.btn--attention:hover:not(:disabled) { background: var(--err); border-color: var(--err); }

.btn--ghost { background: transparent; }
.btn--sm { padding: .3rem .7rem; font-size: .85rem; }
.btn--lg { padding: .75rem 1.6rem; font-size: 1.05rem; }
.btn--icon { padding: .25rem .5rem; font-size: .8rem; }

/* ─────────────────────────── Pola formularza ─────────────────────────── */

.field { margin-bottom: 1.25rem; }
.field:last-child { margin-bottom: 0; }
.field--narrow input { max-width: 16rem; }

label {
  display: block;
  font-weight: 600;
  font-size: .9rem;
  margin-bottom: .3rem;
}

input[type="text"], input[type="email"], input[type="date"], select {
  font: inherit;
  width: 100%;
  padding: .5rem .65rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
}
input:focus-visible, select:focus-visible {
  border-color: var(--brand);
  box-shadow: var(--focus);
  outline: none;
}
input[readonly] { background: var(--surface-2); color: var(--ink-2); }
/* Zablokowane pola kroku 1 mają WYGLĄDAĆ na zablokowane celowo. Pole nieodróżnialne
   od aktywnego, w które nie da się nic wpisać, pracownik czyta jako awarię portalu. */
input:disabled, select:disabled {
  background: var(--surface-2);
  color: var(--muted);
  cursor: not-allowed;
}
input[aria-invalid="true"] { border-color: var(--err); }

.hint    { font-size: .82rem; color: var(--muted); margin: .3rem 0 0; }
.preview { font-size: .85rem; color: var(--ink-2); margin: .35rem 0 0; }
.error   { font-size: .85rem; color: var(--err); font-weight: 600; margin: .35rem 0 0; }
.muted   { color: var(--muted); }
.small   { font-size: .82rem; }

.status { font-size: .88rem; margin: .75rem 0 0; }
.status--ok   { color: var(--ok); font-weight: 600; }
.status--warn { color: var(--warn); font-weight: 600; }
.status--err  { color: var(--err); font-weight: 600; }

/* ─────────────────────────── Banery ─────────────────────────── */

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem;
  padding: .7rem .9rem;
  border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: .9rem;
  margin: 0 0 1rem;
}
.banner--inline { margin-bottom: 1rem; }
.banner--err  { background: var(--err-bg);  border-color: var(--err);  color: var(--err); }
.banner--warn { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }

/* ─────────────────────────── Tożsamość ─────────────────────────── */

.identity {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1rem;
}
.identity__col {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .8rem .9rem;
}
.identity__src { color: var(--brand-ink); margin-bottom: .5rem; font-size: .85rem; }

.kv { margin: 0; font-size: .88rem; }
.kv > div { display: flex; gap: .5rem; padding: .15rem 0; flex-wrap: wrap; }
.kv dt { color: var(--muted); min-width: 9rem; margin: 0; }
.kv dd { margin: 0; font-weight: 600; word-break: break-word; }
.kv--row { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: .25rem 1rem; margin: 1rem 0; }

/* ─────────────────────────── Chipsy z adresami ─────────────────────────── */

.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .5rem; }
.chips:empty { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  background: var(--brand-tint);
  border: 1px solid var(--brand);
  color: var(--ink);
  border-radius: 999px;
  padding: .2rem .3rem .2rem .7rem;
  font-size: .85rem;
  max-width: 100%;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button {
  font: inherit;
  line-height: 1;
  border: 0;
  background: transparent;
  color: var(--brand-ink);
  cursor: pointer;
  border-radius: 50%;
  width: 1.35rem; height: 1.35rem;
  flex: none;
  font-size: 1rem;
}
.chip button:hover { background: var(--brand); color: var(--on-brand); }

.chip-input { display: flex; gap: .5rem; }
.chip-input input { flex: 1 1 auto; min-width: 0; }

/* ─────────────────────────── Strefa upuszczania ─────────────────────────── */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .2rem;
  text-align: center;
  padding: 1.75rem 1rem;
  border: 2px dashed var(--border-2);
  border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color .12s ease, background-color .12s ease;
}
.dropzone:hover, .dropzone.is-over {
  border-color: var(--brand);
  background: var(--brand-tint);
}
.dropzone strong { font-size: 1rem; }
.dropzone span { font-size: .88rem; color: var(--muted); }

/* ─────────────────────────── Tabela plików ─────────────────────────── */

/* position: relative jest tu konieczne. Bez niego elementy .visually-hidden
   z wnętrza tabeli (pozycjonowane absolutnie) uciekają do bloku zawierającego
   całą stronę, rozciągają dokument i wywołują poziome przewijanie na telefonie. */
.table-scroll { overflow-x: auto; margin-top: 1rem; position: relative; }

.files { width: 100%; border-collapse: collapse; font-size: .88rem; min-width: 40rem; }
.files th, .files td {
  text-align: left;
  padding: .5rem .6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.files th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.files tbody tr:last-child td { border-bottom: 0; }
.files .cell-name { font-weight: 600; word-break: break-word; max-width: 20rem; }
.files .cell-name small { display: block; font-weight: 400; color: var(--muted); }
.files select { font-size: .85rem; padding: .3rem .4rem; min-width: 9rem; }
.files td.cell-actions { text-align: right; white-space: nowrap; }

.pill {
  display: inline-block;
  font-size: .78rem;
  font-weight: 600;
  padding: .1rem .5rem;
  border-radius: 999px;
  border: 1px solid;
  white-space: nowrap;
}
.pill--wait { color: var(--muted); border-color: var(--border-2); background: var(--surface-2); }
.pill--work { color: var(--warn); border-color: var(--warn); background: var(--warn-bg); }
.pill--ok   { color: var(--ok);   border-color: var(--ok);   background: var(--ok-bg); }
.pill--err  { color: var(--err);  border-color: var(--err);  background: var(--err-bg); }
/* Pominięty duplikat to decyzja pracownika, nie awaria - wygląd neutralny,
   celowo taki sam jak „oczekuje", żeby nie przyciągał wzroku jak błąd. */
.pill--skip { color: var(--muted); border-color: var(--border-2); background: var(--surface-2); }

.cell-status .error { font-weight: 400; margin-top: .25rem; }

/* ─────────────────────────── Duplikaty ─────────────────────────── */

.dup {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: .35rem;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: .1rem .45rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  border: 1px solid;
  white-space: nowrap;
}
.badge--warn { color: var(--warn); border-color: var(--warn); background: var(--warn-bg); }

.dup__action { font-size: .8rem; padding: .15rem .3rem; }

/* Wybór trybu folderu w kroku 1 */
.field--group { border: 1px solid var(--border-2); border-radius: .5rem; padding: .75rem 1rem; }
.field--group legend { padding: 0 .35rem; font-weight: 600; font-size: .9rem; }
.radio { display: inline-flex; align-items: center; gap: .4rem; margin-right: 1.25rem; }
.radio input { margin: 0; }
#existingWrap { margin-top: .75rem; }
#selExisting { flex: 1 1 auto; min-width: 0; }

/* ─────────────────────────── Paski postępu ─────────────────────────── */

.progress {
  height: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 1rem;
}
.progress--mini { height: 5px; margin-top: .3rem; }

.progress__bar {
  height: 100%;
  width: 0;
  background: var(--brand);
  transition: width .2s ease;
}
.progress__label { font-size: .88rem; color: var(--ink-2); margin: .5rem 0 0; }

/* ─────────────────────────── Drzewo folderów ─────────────────────────── */

.tree { list-style: none; margin: .75rem 0 0; padding: 0; }
.tree ul { list-style: none; margin: 0; padding-left: 1.4rem; border-left: 1px solid var(--border); }

.tree__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
  padding: .35rem .4rem;
  border-radius: var(--radius-sm);
}
.tree__row:hover { background: var(--surface-2); }
.tree__row label { margin: 0; font-weight: 500; display: flex; align-items: center; gap: .45rem; cursor: pointer; }
.tree__row input[type="radio"] { width: auto; accent-color: var(--brand); flex: none; }
.tree__name { word-break: break-word; }
.tree__count { font-size: .78rem; color: var(--muted); }
.tree__actions { margin-left: auto; display: flex; gap: .35rem; }

/* ─────────────────────────── Dziennik zadania ─────────────────────────── */

.log {
  list-style: none;
  margin: 1rem 0 0;
  padding: .6rem .8rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .85rem;
  max-height: 16rem;
  overflow-y: auto;
}
.log li { padding: .15rem 0; display: flex; gap: .6rem; }
.log li time { color: var(--muted); font-family: var(--mono); font-size: .8rem; flex: none; }
.log li.is-err  { color: var(--err); font-weight: 600; }
.log li.is-ok   { color: var(--ok); }

/* ─────────────────────────── Wynik ─────────────────────────── */

.copy-row { display: flex; gap: .5rem; }
.copy-row input { flex: 1 1 auto; min-width: 0; font-family: var(--mono); font-size: .82rem; }

.run-row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-top: 1rem; }

.footer { padding: 1rem; text-align: center; }

/* ─────────────────────────── Spinner ─────────────────────────── */

.spinner {
  width: 28px; height: 28px;
  margin: 0 auto .75rem;
  border: 3px solid var(--border-2);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media (max-width: 32rem) {
  .card { padding: 1rem; }
  h1 { font-size: 1.35rem; }
  .kv dt { min-width: 100%; }
  .chip-input { flex-wrap: wrap; }
}

/* ─────────────────────────── Edytor wiadomości ─────────────────────────── */

.mail-editor {
  margin: 1rem 0;
  border: 1px solid var(--border-2);
  border-radius: .5rem;
  padding: .5rem .9rem .9rem;
}
.mail-editor > summary {
  cursor: pointer;
  font-weight: 600;
  padding: .35rem 0;
}
.mail-editor textarea {
  width: 100%;
  font-family: inherit;
  font-size: .92rem;
  line-height: 1.5;
  resize: vertical;
}
