/* public/styles/base.css */
/* =========================================================
   Morzkulc App UI (mobile-first, modern, lightweight)
   Dark default + optional Light via [data-theme="light"]
   ========================================================= */

/* --- CSS reset (light) --- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; }
img, svg { display: block; max-width: 100%; }

/* --- Theme tokens --- */
:root {
  --font-sans: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;

  --space-1: 6px;
  --space-2: 10px;
  --space-3: 14px;
  --space-4: 18px;
  --space-5: 24px;

  --shadow-1: 0 10px 30px rgba(0, 0, 0, 0.20);
  --shadow-2: 0 16px 40px rgba(0, 0, 0, 0.28);

  --ring: 0 0 0 3px rgba(120, 160, 255, 0.35);

  color-scheme: dark;

  /* Default = DARK */
  --bg: #0b0f17;
  --surface: #101828;
  --surface-2: #0f172a;
  --text: #e6e8ee;
  --text-muted: rgba(230, 232, 238, 0.70);
  --border: rgba(230, 232, 238, 0.12);

  --primary: #8ab4ff;
  --primary-2: rgba(138, 180, 255, 0.14);

  --danger: #ff6b6b;
  --danger-2: rgba(255, 107, 107, 0.14);

  --ok: #4ade80;
  --ok-2: rgba(74, 222, 128, 0.14);

  --input-bg: rgba(255, 255, 255, 0.06);
  --input-border: rgba(255, 255, 255, 0.10);
  --input-placeholder: rgba(230, 232, 238, 0.40);
}

/* Light theme overrides */
:root[data-theme="light"] {
  color-scheme: light;

  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f2f4f8;
  --text: #0c1220;
  --text-muted: rgba(12, 18, 32, 0.65);
  --border: rgba(12, 18, 32, 0.12);

  --primary: #2f6fed;
  --primary-2: rgba(47, 111, 237, 0.12);

  --danger: #d92d20;
  --danger-2: rgba(217, 45, 32, 0.10);

  --ok: #039855;
  --ok-2: rgba(3, 152, 85, 0.10);

  --input-bg: rgba(12, 18, 32, 0.04);
  --input-border: rgba(12, 18, 32, 0.12);
  --input-placeholder: rgba(12, 18, 32, 0.35);
}

/* Respect OS preference ONLY when user didn't choose explicitly */
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-2: #f2f4f8;
    --text: #0c1220;
    --text-muted: rgba(12, 18, 32, 0.65);
    --border: rgba(12, 18, 32, 0.12);

    --primary: #2f6fed;
    --primary-2: rgba(47, 111, 237, 0.12);

    --danger: #d92d20;
    --danger-2: rgba(217, 45, 32, 0.10);

    --ok: #039855;
    --ok-2: rgba(3, 152, 85, 0.10);

    --input-bg: rgba(12, 18, 32, 0.04);
    --input-border: rgba(12, 18, 32, 0.12);
    --input-placeholder: rgba(12, 18, 32, 0.35);
  }
}

/* --- Base layout --- */
body {
  font-family: var(--font-sans);
  line-height: 1.35;
  background: radial-gradient(1200px 700px at 20% 0%, rgba(138, 180, 255, 0.08), transparent 55%),
              radial-gradient(900px 600px at 90% 10%, rgba(74, 222, 128, 0.06), transparent 60%),
              var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* --- Thinking indicator --- */
.thinking {
  color: var(--text-muted);
  font-size: 13px;
  padding: 12px 0;
}

.thinking .dot {
  animation: dotPulse 1.2s ease-in-out infinite;
  opacity: 0;
}
.thinking .dot:nth-child(2) { animation-delay: 0.2s; }
.thinking .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
  0%, 100% { opacity: 0; }
  50%       { opacity: 1; }
}

h1, h2, h3 { margin: 0 0 var(--space-2) 0; letter-spacing: -0.02em; }
h1 { font-size: 18px; }
h2 { font-size: 18px; }
h3 { font-size: 14px; color: var(--text-muted); font-weight: 600; }

p { margin: 0 0 var(--space-2) 0; color: var(--text-muted); }

/* Container */
body > header,
#appRoot,
#appShell {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding-left: var(--space-3);
  padding-right: var(--space-3);
}

/* --- Header --- */
header {
  position: sticky;
  top: 0;
  z-index: 50;
  padding-top: var(--space-3);
  padding-bottom: var(--space-2);
  backdrop-filter: blur(10px);
  background: linear-gradient(to bottom, rgba(0,0,0,0.25), rgba(0,0,0,0.0));
}

:root[data-theme="light"] header {
  background: linear-gradient(to bottom, rgba(255,255,255,0.85), rgba(255,255,255,0.0));
}

header .headerRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

header .headerActions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ── Baner "nowa wersja aplikacji" w headerze — widoczny na każdym ekranie po zalogowaniu ── */
.swUpdateBanner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: var(--space-2);
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(74, 222, 128, 0.35);
  background: var(--ok-2);
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

/* --- Buttons --- */
button {
  appearance: none;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.03));
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button:hover { transform: translateY(-1px); border-color: rgba(138, 180, 255, 0.35); }
button:active { transform: translateY(0px); }

button:focus-visible { outline: none; box-shadow: var(--ring); }

button.primary {
  border-color: rgba(138, 180, 255, 0.45);
  background: linear-gradient(180deg, rgba(138, 180, 255, 0.22), rgba(138, 180, 255, 0.12));
}

button.ghost {
  background: transparent;
}

/* Przyciski anulujące BIEŻĄCĄ, niezapisaną jeszcze akcję (zamknij modal bez zapisu,
   odrzuć formularz) — delikatny czerwony akcent, żeby wizualnie odróżnić od
   neutralnego .ghost, ale bez sugestii że coś zostaje skasowane/nieodwracalnie
   zmienione (od tego jest .ghostDanger poniżej). */
button.ghostCancel {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.25);
}

button.ghostCancel:hover {
  border-color: rgba(248, 113, 113, 0.55);
  background: rgba(248, 113, 113, 0.08);
}

/* Przyciski realnie kasujące/anulujące już istniejący, zapisany stan (np. anulowanie
   aktywnej rezerwacji) — intensywniejszy czerwony, sygnalizujący nieodwracalną akcję. */
button.ghostDanger {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.45);
}

button.ghostDanger:hover {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.14);
}

button.iconBtn {
  width: 42px;
  height: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 14px;
}

button[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
}

/* --- App shell --- */
#appShell { margin-top: var(--space-2); }

/* --- Nav --- */
#nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

#nav button {
  border-radius: 999px;
  padding: 10px 14px;
}

/* Przycisk „Start" = ikona domku + etykieta (etykieta ukrywana na mobile) */
.navHomeBtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.navHomeBtn svg { display: block; flex-shrink: 0; }

/* Mobile: bottom nav bar */
@media (max-width: 720px) {
  #nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    padding: 8px 12px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    border-bottom: 0;
    background: rgba(16, 24, 40, 0.88);
    backdrop-filter: blur(16px);
    max-width: 100%;
    margin: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 6px;
    scrollbar-width: none;
  }

  #nav::-webkit-scrollbar { display: none; }

  :root[data-theme="light"] #nav {
    background: rgba(255, 255, 255, 0.88);
  }

  #nav button {
    flex: 0 0 auto;
    min-height: 44px;
    font-size: 12px;
    padding: 8px 14px;
    white-space: nowrap;
  }

  /* Mobile: „Start" jako sama ikona domku (oszczędność miejsca) */
  .navHomeBtn .navLabel { display: none; }
  .navHomeBtn { padding: 8px 12px; }
}

/* --- View --- */
#view { padding: var(--space-4) 0; }

/* Dolny pasek nav (fixed) zasłania treść — rezerwujemy miejsce na mobile.
   WAŻNE: ta reguła MUSI być PO bazowym `#view { padding: ... }` powyżej,
   inaczej shorthand `padding` nadpisuje `padding-bottom` (kolejność źródła). */
@media (max-width: 720px) {
  #view { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
}

/* --- Card / form --- */
.card {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.03));
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-1);
  max-width: 560px;
}

.card.center { margin: 0 auto; }
.card.wide { max-width: 980px; }

:root[data-theme="light"] .card {
  background: linear-gradient(180deg, rgba(12,18,32,0.02), rgba(12,18,32,0.01));
}

.row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
}

label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  padding: 12px 12px;
  border: 1px solid var(--input-border);
  border-radius: 12px;
  font-size: 15px;
  color: var(--text);
  background: var(--input-bg);
  transition: box-shadow 120ms ease, border-color 120ms ease;
}

/* Powyższe width:100% jest myślane dla pól tekstowych/select — bez tego
   wyjątku checkbox/radio dziedziczą je też i rozciągają się na całą
   szerokość wiersza (odkryte na .clubEventItemRow — łatwo przeoczyć przy
   dodawaniu nowego checkboxa bez własnej klasy). */
input[type="checkbox"],
input[type="radio"] {
  width: auto;
  flex: none;
}

input::placeholder,
textarea::placeholder { color: var(--input-placeholder); }

input:focus,
select:focus,
textarea:focus {
  outline: none;
  box-shadow: var(--ring);
  border-color: rgba(138, 180, 255, 0.45);
}

/* Natywna lista opcji select — ciemne tło domyślnie (dark-first), jasne tylko w light mode */
select option {
  background-color: #101828;
  color: #e8eaf0;
}

:root[data-theme="light"] select option {
  background-color: #ffffff;
  color: #0b0f17;
}

@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] select option {
    background-color: #ffffff;
    color: #0b0f17;
  }
}

textarea {
  resize: vertical;
  min-height: 88px;
}

.hint { font-size: 12px; color: var(--text-muted); }

.err {
  margin-top: var(--space-2);
  color: var(--danger);
  background: var(--danger-2);
  border: 1px solid rgba(255, 107, 107, 0.35);
  padding: 10px 12px;
  border-radius: 12px;
}

.ok {
  margin-top: var(--space-2);
  color: var(--ok);
  background: var(--ok-2);
  border: 1px solid rgba(74, 222, 128, 0.35);
  padding: 10px 12px;
  border-radius: 12px;
}

.actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
  margin-top: var(--space-2);
}

.actions button { min-height: 44px; padding: 12px 14px; }

.checkRow {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  margin: var(--space-3) 0;
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255,255,255,0.03);
}

:root[data-theme="light"] .checkRow { background: rgba(12,18,32,0.02); }

.checkRow input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--primary);
}

.codeBlock {
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px;
  border-radius: 14px;
  overflow: auto;
}

:root[data-theme="light"] .codeBlock {
  background: rgba(12,18,32,0.04);
}


@media (max-width: 380px) {
  body > header,
  #appRoot,
  #appShell {
    padding-left: var(--space-2);
    padding-right: var(--space-2);
  }

  button { font-size: 13px; }
}

/* --- Zakładki modułu (np. panel Zarząd: Administracja / Raporty) --- */
.modTabs { display: flex; gap: 6px; margin: 12px 0 4px; flex-wrap: wrap; }
.modTab { padding: 8px 18px; border-radius: 10px; border: 1px solid var(--border); background: transparent; color: var(--text); font-size: 14px; font-weight: 600; cursor: pointer; transition: background 0.15s, color 0.15s; }
.modTab.active, .modTab:hover { background: var(--primary); color: #fff; border-color: transparent; }

/* Kafelki nawigacji modułu (Godzinki, Ranking) — zamiast zakładek-przycisków.
   3 w rzędzie także na telefonie; więcej kafelków zawija się do kolejnego rzędu. */
.modTiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

/* Na szerszym ekranie wszystkie kafelki w jednym rzędzie (--tile-count ustawia moduł). */
@media (min-width: 720px) {
  .modTiles { grid-template-columns: repeat(var(--tile-count, 3), minmax(0, 1fr)); }
}

.modTile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 76px;
  padding: 10px 6px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.modTile:hover,
.modTile.active {
  background: var(--primary);
  border-color: transparent;
  color: #fff;
}

.modTileIcon {
  display: flex;
}

/* Kafelek dodawania wyróżniony nawet gdy nieaktywny — żeby nie ginął obok przełączników widoku */
.modTileAdd {
  border: 2px dashed var(--primary);
  color: var(--primary);
}

.modTileAdd .modTileIcon {
  width: 30px;
  height: 30px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
}

.modTileAdd.active .modTileIcon,
.modTileAdd:hover .modTileIcon {
  background: #fff;
  color: var(--primary);
}

/* --- Raport (panel Raporty w panelu Zarząd) --- */
.reportControls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 8px 0; }
.reportLabel { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.reportControls select, .reportControls input[type="date"], .reportControls input[type="search"] { width: auto; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.reportControls input[type="search"] { width: 220px; max-width: 100%; }
#reportCustomDates { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.reportCats { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 6px 0 4px; }
.reportCats label { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--text); cursor: pointer; }
.reportCats input[type="checkbox"] { width: 18px; height: 18px; flex: none; margin: 0; accent-color: var(--primary); }

@media (max-width: 480px) {
  .reportControls { flex-direction: column; align-items: stretch; }
  .reportLabel { flex-direction: column; align-items: flex-start; gap: 4px; width: 100%; }
  .reportControls select, .reportControls input[type="date"], .reportControls input[type="search"] { width: 100%; }
  #reportCustomDates { width: 100%; }
}
.reportTable { width: 100%; border-collapse: collapse; font-size: 13px; }
.reportTable th { background: var(--surface-2); color: var(--text); font-weight: 700; padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.reportTable td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; color: var(--text); }
.reportTable tr:last-child td { border-bottom: none; }
.reportPerson { font-weight: 700; }
.reportEmail { font-size: 12px; color: var(--text-muted); }
.reportItem { padding: 1px 0; }
.reportTerm { white-space: nowrap; }
.kluczeCheck { color: var(--success, #4a4); font-weight: 700; }
.kluczeDash { color: var(--text-muted); }

/* --- Wymuszone anulowanie rezerwacji (raport Wypożyczenia sprzętu) --- */
.dangerBtn { border-color: var(--danger); color: var(--danger); background: transparent; font-size: 12px; padding: 6px 10px; white-space: nowrap; }
.dangerBtn:hover { background: var(--danger-2); }
.cancelForm { display: flex; flex-direction: column; gap: 6px; min-width: 200px; }
.cancelReasonInput { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 13px; }
.cancelFormBtns { display: flex; gap: 6px; }
.cancelFormBtns button { font-size: 12px; padding: 6px 10px; min-height: auto; }

/* --- Karty do zatwierdzenia (panel Zarząd: godzinki/imprezy) — na desktopie
   treść po lewej + przyciski po prawej w jednym wierszu; na mobile treść i
   przyciski schodzą w osobne wiersze, a Zatwierdź/Odrzuć rozjeżdżają się do
   przeciwległych krawędzi (space-between), żeby zminimalizować przypadkowe
   kliknięcia na wąskim ekranie. */
.approvalCard {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
}

.approvalCardMain { display: grid; gap: 2px; min-width: 0; }
.approvalCardTitle { font-size: 14px; font-weight: 800; color: var(--text); line-height: 1.3; }
.approvalCardSubtitle { font-size: 12px; color: var(--text-muted); line-height: 1.4; }

.approvalCardActions { display: flex; gap: 6px; flex-shrink: 0; }

.approveBtn { border-color: rgba(74, 222, 128, 0.4); background: var(--ok-2); color: var(--ok); }
.approveBtn:hover { border-color: var(--ok); }

.rejectBtn { border-color: var(--danger); color: var(--danger); background: transparent; }
.rejectBtn:hover { background: var(--danger-2); }

@media (max-width: 600px) {
  .approvalCard { flex-direction: column; align-items: stretch; gap: 8px; }
  .approvalCardActions { justify-content: space-between; }
}

/* --- Launcher raportów (kafelki pogrupowane + szukajka) --- */
.reportLauncher { margin-top: 8px; }
.reportSearch { width: 100%; max-width: 360px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); margin-bottom: 8px; }
.reportCatHead { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin: 14px 0 8px; }
.reportGrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 380px) { .reportGrid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.reportTile { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left; padding: 12px; border-radius: 12px; border: 1px solid var(--border); background: rgba(255,255,255,0.04); color: var(--text); cursor: pointer; transition: border-color 0.15s, background 0.15s; }
:root[data-theme="light"] .reportTile { background: rgba(12,18,32,0.03); }
.reportTile:hover { border-color: var(--primary); background: rgba(255,255,255,0.07); }
.reportTileLabel { font-weight: 800; font-size: 14px; }
.reportTileDesc { font-size: 12px; color: var(--text-muted); line-height: 1.35; }
.reportDetailHead { display: flex; align-items: center; gap: 12px; margin: 8px 0 12px; flex-wrap: wrap; }
.reportDetailTitle { margin: 0; font-size: 16px; }
.duesOk { color: var(--ok); font-weight: 700; }
.duesBad { color: var(--danger); font-weight: 700; }
.reportPdfBtn { margin-left: auto; }

/* Nagłówek widoczny tylko na wydruku/PDF (ekran: ukryty). */
.reportPrintHeader { display: none; }
.reportPrintTitle { font-size: 16px; font-weight: 800; }
.reportPrintDate { font-size: 11px; color: var(--text-muted); }

/* --- Druk raportu → „Zapisz jako PDF" (izolujemy sam raport) --- */
@media print {
  body.printingReport * { visibility: hidden; }
  body.printingReport #reportDetailBody,
  body.printingReport #reportDetailBody * { visibility: visible; }
  body.printingReport #reportDetailBody {
    position: absolute; left: 0; top: 0; width: 100%; margin: 0; padding: 0;
    background: #fff; color: #000;
  }
  /* Interaktywne kontrolki nie wchodzą do PDF (zostają dane + wybrany zakres/widok w <select>). */
  body.printingReport #reportDetailBody button,
  body.printingReport #reportDetailBody input[type="search"],
  body.printingReport #reportDetailBody input[type="checkbox"],
  body.printingReport #reportDetailBody .reportCats { display: none !important; }
  body.printingReport .reportPrintHeader { display: block !important; margin-bottom: 10px; }
  /* Czytelne kolory na białym papierze niezależnie od motywu. */
  body.printingReport #reportDetailBody,
  body.printingReport .reportTable,
  body.printingReport .reportTable th,
  body.printingReport .reportTable td,
  body.printingReport .reportPerson,
  body.printingReport .reportItem,
  body.printingReport .reportTerm,
  body.printingReport .reportCatHead,
  body.printingReport .reportPrintTitle,
  body.printingReport .reportLabel,
  body.printingReport select,
  body.printingReport .hint { color: #000 !important; }
  body.printingReport .reportEmail,
  body.printingReport .reportPrintDate { color: #555 !important; }
  body.printingReport .reportTable th {
    background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  body.printingReport .duesOk { color: #0a7a16 !important; }
  body.printingReport .duesBad { color: #c0271a !important; }
}
