/*
 * Wygląd aplikacji (wariant A): panel boczny, gęste tabele, małe przyciski, stonowane kolory.
 *
 * Ładowany po Pico CSS. Pico zostaje jako baza formularzy i tabel, a tutaj nadpisujemy jego
 * zmienne (rozmiary, kolory) i dokładamy komponenty: panel boczny, nagłówek strony, karty,
 * zakładki, plakietki, kafelki. Style edytora i rysunku są w app.css.
 */

/* --- Zmienne: kolory i rozmiary (motyw jasny, html data-theme="light") --- */

:root[data-theme="light"] {
  --ui-bg: #f4f6f8;
  --ui-surface: #ffffff;
  --ui-line: #e3e7ec;
  --ui-head: #eef4f8;
  --ui-row: #f8fafb;
  --ui-text: #1f2933;
  --ui-muted: #6b7785;
  --ui-primary: #1f6f9a;
  --ui-primary-dark: #185a7e;
  --ui-primary-soft: #e6f0f6;
  --ui-ok: #2f855a;
  --ui-ok-soft: #e3f3ea;
  --ui-warn: #b7791f;
  --ui-warn-soft: #fbf1df;
  --ui-bad: #c53030;
  --ui-bad-soft: #fbe6e6;
  --ui-sidebar: 232px;

  --pico-font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --pico-font-size: 13.5px;
  --pico-line-height: 1.45;
  --pico-font-weight: 400;
  --pico-border-radius: 6px;
  --pico-spacing: 1rem;
  --pico-typography-spacing-vertical: 0.75rem;
  --pico-block-spacing-vertical: 0.9rem;
  --pico-block-spacing-horizontal: 1.15rem;
  --pico-form-element-spacing-vertical: 0.38rem;
  --pico-form-element-spacing-horizontal: 0.65rem;
  --pico-outline-width: 2px;

  --pico-background-color: var(--ui-bg);
  --pico-color: var(--ui-text);
  --pico-muted-color: var(--ui-muted);
  --pico-muted-border-color: var(--ui-line);
  --pico-h1-color: var(--ui-text);
  --pico-h2-color: var(--ui-text);
  --pico-h3-color: var(--ui-text);
  --pico-primary: var(--ui-primary);
  --pico-primary-background: var(--ui-primary);
  --pico-primary-border: var(--ui-primary);
  --pico-primary-underline: rgba(31, 111, 154, 0.4);
  --pico-primary-hover: var(--ui-primary-dark);
  --pico-primary-hover-background: var(--ui-primary-dark);
  --pico-primary-hover-border: var(--ui-primary-dark);
  --pico-primary-focus: rgba(31, 111, 154, 0.22);
  --pico-primary-inverse: #fff;
  --pico-secondary: #4b5763;
  --pico-secondary-background: #ffffff;
  --pico-secondary-border: #d5dbe1;
  --pico-secondary-inverse: var(--ui-text);
  --pico-secondary-hover: var(--ui-text);
  --pico-secondary-hover-background: #f1f4f7;
  --pico-secondary-hover-border: #c4ccd4;
  --pico-secondary-focus: rgba(75, 87, 99, 0.2);
  --pico-card-background-color: var(--ui-surface);
  --pico-card-sectioning-background-color: var(--ui-surface);
  --pico-card-border-color: var(--ui-line);
  --pico-card-box-shadow: none;
  --pico-form-element-background-color: #ffffff;
  --pico-form-element-border-color: #d5dbe1;
  --pico-form-element-focus-color: var(--ui-primary);
  --pico-table-border-color: var(--ui-line);
  --pico-table-row-stripped-background-color: var(--ui-row);
  --pico-del-color: var(--ui-bad);
  --pico-ins-color: var(--ui-ok);
}

h1 { --pico-font-size: 1.5rem; --pico-font-weight: 600; margin-bottom: 0; }
h2 { --pico-font-size: 1.1rem; --pico-font-weight: 600; }
h3 { --pico-font-size: 1rem; --pico-font-weight: 600; }
small { font-size: 0.89em; }

/* Przyciski i pola: wysokość ok. 32 px; obramowany „secondary” zamiast szarego tła */
button,
[role="button"],
input:not([type="checkbox"], [type="radio"]),
select,
textarea {
  font-size: 1rem;
}

button.secondary,
[role="button"].secondary,
button.outline.secondary,
[role="button"].outline.secondary {
  color: var(--ui-text);
  background: #fff;
  border-color: #d5dbe1;
}

button.secondary:hover,
[role="button"].secondary:hover {
  background: #f1f4f7;
  border-color: #c4ccd4;
  color: var(--ui-text);
}

button.small,
[role="button"].small {
  padding: 0.15rem 0.55rem;
  font-size: 0.89rem;
  margin: 0;
}

/* Tabele: pas nagłówka, liczby do prawej */
table {
  font-size: 0.96rem;
}

thead th,
thead td {
  background: var(--ui-head);
  font-weight: 600;
  font-size: 0.89rem;
  color: #34404c;
  white-space: nowrap;
  border-bottom: 0;
}

tfoot th,
tfoot td {
  background: var(--ui-row);
  font-weight: 600;
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Karty (article Pico): cienka ramka zamiast cienia */
article {
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  margin-bottom: 1rem;
}

article > header {
  border-bottom: 1px solid var(--ui-line);
  padding-block: 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

article > header .spacer,
.spacer {
  margin-left: auto;
}

article > footer {
  border-top: 1px solid var(--ui-line);
  padding-block: 0.7rem;
}

/* --- Układ: panel boczny + treść --- */

body {
  background: var(--ui-bg);
}

.app {
  display: grid;
  grid-template-columns: var(--ui-sidebar) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 1rem 0.75rem;
  background: var(--ui-surface);
  border-right: 1px solid var(--ui-line);
  overflow-y: auto;
}

.who {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 0.8rem;
  margin-bottom: 1.1rem;
  border-radius: 8px;
  background: var(--ui-primary);
  color: #fff;
  text-decoration: none;
}

.who:hover {
  color: #fff;
  background: var(--ui-primary-dark);
}

.who .avatar {
  flex: none;
  width: 2.2rem;
  height: 2.2rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  font-weight: 600;
  font-size: 0.9rem;
}

.who b {
  display: block;
  font-weight: 600;
  line-height: 1.2;
}

.who small {
  display: block;
  opacity: 0.85;
  font-size: 0.8rem;
}

.nav-section {
  margin: 0.9rem 0.6rem 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ui-muted);
  text-transform: uppercase;
}

.nav a,
.nav span.soon {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
  color: #3a4652;
  font-weight: 500;
  text-decoration: none;
}

.nav a:hover {
  background: #f1f4f7;
}

.nav a.active {
  background: var(--ui-primary-soft);
  color: var(--ui-primary);
}

.sidebar .icon {
  flex: none;
  width: 1.15rem;
  height: 1.15rem;
}

/* Pico układa nav w wiersz z odstępami; menu boczne to zwykła kolumna */
.sidebar .nav {
  display: block;
}

.nav .sub a {
  padding: 0.35rem 0.7rem 0.35rem 2.5rem;
  font-weight: 400;
  font-size: 0.93rem;
}

.nav .sub a::before {
  content: "";
  width: 5px;
  height: 5px;
  margin-left: -0.9rem;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}

.nav span.soon {
  color: var(--ui-muted);
  cursor: default;
}

.sidebar-bottom {
  margin-top: auto;
  padding-top: 1rem;
}

.sidebar-bottom form {
  margin: 0;
}

.sidebar-bottom .nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 0;
  background: none;
  color: #3a4652;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  border-radius: 6px;
}

.sidebar-bottom .nav-link:hover {
  background: #f1f4f7;
}

.sidebar-bottom a.nav-link.active {
  background: var(--ui-primary-soft);
  color: var(--ui-primary);
}

.content {
  min-width: 0;
  padding: 1.4rem 2rem 2rem;
}

/* Zwinięty panel: same ikony (kalkulator, przycisk »/« na dole panelu) */
.app.collapsed {
  --ui-sidebar: 60px;
}

.app.collapsed .sidebar {
  padding-inline: 0.5rem;
  align-items: center;
}

.app.collapsed .who {
  padding: 0;
  background: none;
}

/* Logo firmy zamiast inicjałów (ustawienia instancji) */
.who img.avatar {
  object-fit: contain;
  border-radius: 6px;
  background: #fff;
  padding: 2px;
}

.login-logo {
  display: block;
  max-width: 10rem;
  max-height: 3.5rem;
  margin-bottom: 0.6rem;
}

.app.collapsed .who span.avatar {
  background: var(--ui-primary);
}

.app.collapsed .label,
.app.collapsed .nav-section,
.app.collapsed .nav .sub,
.app.collapsed .who div {
  display: none;
}

.app.collapsed .nav a,
.app.collapsed .nav span.soon,
.app.collapsed .sidebar-bottom .nav-link {
  justify-content: center;
  padding: 0.6rem;
}

/* Telefon, wąski tablet: panel staje się paskiem u góry */
@media (max-width: 860px) {
  .app,
  .app.collapsed {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 1fr; /* pasek menu tylko tak wysoki, jak trzeba */
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.25rem;
    overflow-x: auto;
    padding: 0.5rem 0.75rem;
    border-right: 0;
    border-bottom: 1px solid var(--ui-line);
  }

  .who {
    margin: 0 0.5rem 0 0;
    padding: 0.35rem 0.6rem;
  }

  .who small,
  .who div,
  .nav-section,
  .nav .sub,
  .nav-settings,
  .collapse-toggle {
    display: none !important;
  }

  .sidebar .nav {
    display: flex;
    flex-wrap: nowrap;
  }

  .nav a {
    padding: 0.4rem 0.55rem;
  }

  .sidebar-bottom {
    display: flex;
    margin: 0 0 0 auto;
    padding: 0;
  }

  /* w pasku u góry konto i wylogowanie tylko jako ikony */
  .sidebar-bottom .label {
    display: none !important;
  }

  .app.collapsed .label {
    display: inline;
  }

  .content {
    padding: 1rem;
  }

  /* iOS powiększa stronę po kliknięciu w pole z tekstem mniejszym niż 16 px */
  input:not([type="checkbox"], [type="radio"]),
  select,
  textarea {
    font-size: 16px;
  }
}

/* --- Nagłówek strony: wstecz, tytuł, opis, akcje --- */

.page-head {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 1.1rem;
  flex-wrap: wrap;
}

.page-head .back {
  flex: none;
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--ui-line);
  border-radius: 50%;
  background: var(--ui-surface);
  color: var(--ui-muted);
  text-decoration: none;
  font-size: 1.1rem;
  line-height: 1;
}

.page-head .back:hover {
  color: var(--ui-primary);
  border-color: #c4ccd4;
}

.page-head .titles {
  min-width: 0;
}

.page-head .sub {
  margin: 0.15rem 0 0;
  color: var(--ui-muted);
  font-size: 0.89rem;
}

.page-head .actions {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.page-head .actions form {
  margin: 0;
}

.page-head .actions button,
.page-head .actions [role="button"] {
  margin: 0;
}

/* --- Zakładki (w karcie albo nad treścią) --- */

.tabs {
  display: flex;
  justify-content: flex-start;
  gap: 0;
  overflow-x: auto;
  overflow-y: hidden;
  border-bottom: 1px solid var(--ui-line);
  margin: calc(var(--pico-block-spacing-vertical) * -1) calc(var(--pico-block-spacing-horizontal) * -1)
    var(--pico-block-spacing-vertical);
  padding: 0 0.5rem;
}

/* Zakładki jako osobny pasek nad kartami (rozkrój, wycena, raport) */
.tabs.bar {
  margin: 0 0 1rem;
  background: var(--ui-surface);
  border: 1px solid var(--ui-line);
  border-radius: 8px;
}

.tabs.bar a {
  margin-bottom: 0;
}

.tabs a {
  padding: 0.7rem 0.95rem;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  color: var(--ui-muted);
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
}

.tabs a:hover {
  color: var(--ui-text);
}

.tabs a.active {
  color: var(--ui-primary);
  border-bottom-color: var(--ui-primary);
}

.tabs .count {
  margin-left: 0.3rem;
  color: var(--ui-muted);
  font-weight: 400;
}

/* --- Plakietki (statusy projektu, stan wycieraczki) --- */

.badge,
.status {
  display: inline-block;
  padding: 0.12rem 0.6rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
  background: var(--ui-primary-soft);
  color: var(--ui-primary);
}

.badge.ok,
.status-zamowiony,
.status-wydany {
  background: var(--ui-ok-soft);
  color: var(--ui-ok);
}

.badge.warn,
.status-w_produkcji {
  background: var(--ui-warn-soft);
  color: var(--ui-warn);
}

.badge.bad,
.status-anulowany {
  background: var(--ui-bad-soft);
  color: var(--ui-bad);
}

.badge.muted,
.status-nowy {
  background: #eef1f4;
  color: #4b5763;
}

/* --- Kafelki z liczbami --- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat {
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  background: var(--ui-surface);
}

.stat .label {
  color: var(--ui-muted);
  font-size: 0.89rem;
}

.stat .value {
  margin-top: 0.1rem;
  font-size: 1.35rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat .value small {
  font-size: 0.6em;
  font-weight: 400;
  color: var(--ui-muted);
}

/* --- Lista „etykieta: wartość” --- */

.kv {
  display: grid;
  grid-template-columns: minmax(7rem, max-content) 1fr;
  gap: 0.45rem 1.2rem;
  margin: 0;
}

.kv dt {
  color: var(--ui-muted);
}

.kv dd {
  margin: 0;
}

/* Pasek filtrów nad tabelą (szukaj, status) */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0;
}

.filters input,
.filters select,
.filters button {
  width: auto;
  margin: 0;
}

.filters input[type="search"] {
  flex: 1 1 16rem;
}

/* Tabela w karcie: od krawędzi do krawędzi */
article > .table-wrap {
  margin-inline: calc(var(--pico-block-spacing-horizontal) * -1);
  overflow-x: auto;
}

article > .table-wrap:last-child {
  margin-bottom: calc(var(--pico-block-spacing-vertical) * -1);
}

article > .table-wrap table {
  margin: 0;
}

article > .table-wrap th:first-child,
article > .table-wrap td:first-child {
  padding-left: var(--pico-block-spacing-horizontal);
}

article > .table-wrap th:last-child,
article > .table-wrap td:last-child {
  padding-right: var(--pico-block-spacing-horizontal);
}

.empty {
  padding: 1.5rem 0;
  text-align: center;
  color: var(--ui-muted);
}

/* Karty obok siebie */
.cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: 0 1rem;
}

/* Logowanie: karta na środku, bez panelu (jedna kolumna zamiast panelu + treści) */
.app.bare {
  grid-template-columns: minmax(0, 1fr);
}

.bare .content {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

.login {
  width: min(24rem, 100%);
}

/* Fieldset tylko do wyłączania pól (cennik bez uprawnień), bez ramki */
fieldset.plain {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

/* Ustawienia instancji */
.settings-cols {
  align-items: start;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0 1rem;
}

.logo-preview {
  margin-bottom: 1rem;
  padding: 0.75rem;
  border: 1px solid var(--ui-line);
  border-radius: 6px;
  background: #fff;
}

.logo-preview img {
  display: block;
  max-width: 100%;
  max-height: 5rem;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.row-actions button {
  width: auto;
  margin: 0;
}
