/* maluutki.pl - tokeny i komponenty (zob. DESIGN.md) */

:root {
  color-scheme: light dark;
  --bg: #F2F3F1;
  --surface: #FFFFFF;
  --surface-2: #F7F8F6;
  --border: #DADDD8;
  --border-strong: #BFC4BE;
  --text: #14181A;
  --text-muted: #596164;
  --primary: #17603A;
  --primary-hover: #12502F;
  --primary-fg: #FFFFFF;
  --primary-soft: #E3F0E8;
  --danger: #B42318;
  --danger-soft: #FCE9E7;
  --success: #1D7A46;
  --focus: #1F7AE0;
  --stripe: rgba(180, 35, 24, 0.10);
  --shadow-1: 0 1px 2px rgba(20, 24, 26, 0.06), 0 1px 1px rgba(20, 24, 26, 0.04);
  --shadow-2: 0 12px 32px rgba(20, 24, 26, 0.16), 0 2px 6px rgba(20, 24, 26, 0.08);

  --font-display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --font-body: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --sheet: cubic-bezier(0.32, 0.72, 0, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1211;
    --surface: #171B1A;
    --surface-2: #1D2221;
    --border: #2B3230;
    --border-strong: #3B4441;
    --text: #E7EBE9;
    --text-muted: #9BA4A1;
    --primary: #5CC48C;
    --primary-hover: #73D19E;
    --primary-fg: #07170E;
    --primary-soft: #1B3326;
    --danger: #F07A6E;
    --danger-soft: #3A1E1B;
    --success: #6BD39A;
    --focus: #6AAEFF;
    --stripe: rgba(240, 122, 110, 0.13);
    --shadow-1: none;
    --shadow-2: 0 16px 40px rgba(0, 0, 0, 0.5);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }
a { color: var(--primary); }
img { display: block; max-width: 100%; }
button, input, select { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.skip {
  position: absolute; left: 16px; top: -48px; z-index: 50;
  background: var(--surface); padding: 8px 12px; border-radius: var(--r-sm);
}
.skip:focus { top: 8px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.num { font-variant-numeric: tabular-nums; }
.display { font-family: var(--font-display); font-weight: 700; letter-spacing: -0.01em; }
.muted { color: var(--text-muted); }

/* ---------- układ ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-in {
  max-width: 1200px; margin: 0 auto; height: 56px;
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
}
.brand {
  font-family: var(--font-display); font-weight: 700; font-size: 22px;
  letter-spacing: 0.01em; color: var(--text); text-decoration: none;
}
.brand span { color: var(--primary); }
.topbar .spacer { flex: 1; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 16px; padding-bottom: calc(32px + env(safe-area-inset-bottom)); }

/* ---------- przyciski ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: var(--r-md);
  border: 1px solid transparent; background: transparent;
  font-weight: 600; font-size: 15px; line-height: 1; text-decoration: none; white-space: nowrap;
  cursor: pointer; user-select: none;
  transition: transform 140ms var(--ease-out), background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-primary { background: var(--primary); color: var(--primary-fg); }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost { color: var(--text); }
.btn-danger { background: var(--surface); border-color: var(--border); color: var(--danger); }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-icon { width: 44px; padding: 0; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; }

@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover { background: var(--primary-hover); }
  .btn-secondary:hover, .btn-danger:hover { border-color: var(--border-strong); }
  .btn-ghost:hover { background: var(--surface-2); }
}

/* ---------- formularze ---------- */

.field { display: grid; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; }
.input {
  width: 100%; min-height: 44px; height: 44px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-md);
  font-size: 16px;
}
.input:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.input[aria-invalid="true"] { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 13px; min-height: 0; }
.field-hint { color: var(--text-muted); font-size: 13px; }
select.input { appearance: none; background-image: none; }

.check { display: flex; gap: 10px; align-items: center; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }

/* ---------- karty ---------- */

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}

/* ---------- osoby ---------- */

.avatar {
  --size: 28px;
  display: inline-grid; place-items: center; flex: none;
  width: var(--size); height: var(--size); border-radius: 50%;
  background: var(--c); color: var(--fg);
  font: 700 calc(var(--size) * 0.42) / 1 var(--font-body); letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.crest { width: 24px; height: 24px; object-fit: contain; flex: none; }

/* ---------- dialog / arkusz ---------- */

dialog {
  border: 0; padding: 0; color: var(--text); background: var(--surface);
  border-radius: var(--r-lg); box-shadow: var(--shadow-2);
  width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  overscroll-behavior: contain;
}
dialog::backdrop { background: rgba(10, 12, 12, 0.45); }
dialog[open] { animation: dlg-in 200ms var(--ease-out); }
@keyframes dlg-in { from { opacity: 0; transform: scale(0.96); } }

@media (max-width: 640px) {
  dialog.sheet {
    margin: auto 0 0; width: 100vw; max-width: 100vw;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  dialog.sheet[open] { animation: sheet-in 320ms var(--sheet); }
  @keyframes sheet-in { from { transform: translateY(40%); opacity: 0; } }
}

.dlg-head { display: flex; align-items: flex-start; gap: 12px; padding: 20px 20px 0; }
.dlg-head h2 { font-size: 20px; flex: 1; padding-top: 8px; }
.dlg-body { padding: 16px 20px 20px; display: grid; gap: 16px; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 0 20px 20px; flex-wrap: wrap; }
.grabber { display: none; }
@media (max-width: 640px) {
  .grabber { display: block; width: 36px; height: 4px; border-radius: 2px; background: var(--border-strong); margin: 8px auto 0; }
  .dlg-foot .btn { flex: 1; }
}

/* ---------- toast ---------- */

.toasts {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translateX(-50%); display: grid; gap: 8px; width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 12px;
  background: var(--text); color: var(--bg); border-radius: var(--r-md);
  padding: 12px 16px; font-size: 15px; box-shadow: var(--shadow-2);
  pointer-events: auto; animation: toast-in 220ms var(--ease-out);
}
.toast.error { background: var(--danger); color: #fff; }
.toast button { margin-left: auto; background: none; border: 0; color: inherit; font-weight: 700; cursor: pointer; min-height: 32px; text-decoration: underline; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.empty { padding: 24px; text-align: left; color: var(--text-muted); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
  .btn:active { transform: none; }
}

/* ---------- nawigacja między projektami ---------- */

.user-slot { display: flex; align-items: center; gap: 4px; }
.me-chip { display: inline-flex; align-items: center; gap: 8px; padding: 0 8px; font-weight: 600; }

.nav-tabs { display: flex; gap: 4px; margin-left: 16px; }
.nav-tabs a {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px;
  border-radius: var(--r-md); color: var(--text-muted); font-weight: 600; font-size: 15px; text-decoration: none;
}
.nav-tabs a svg { width: 18px; height: 18px; }
.nav-tabs a[aria-current="page"] { color: var(--text); background: var(--surface); box-shadow: inset 0 0 0 1px var(--border); }
@media (hover: hover) and (pointer: fine) { .nav-tabs a:hover { color: var(--text); } }

.bottom-nav { display: none; }

@media (max-width: 640px) {
  .nav-tabs { display: none; }
  .me-name { display: none; }
  .has-bottom-nav .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 56px; color: var(--text-muted); text-decoration: none; font-size: 12px; font-weight: 600;
  }
  .bottom-nav a svg { width: 22px; height: 22px; }
  .bottom-nav a span { max-width: 100%; padding: 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bottom-nav a[aria-current="page"] { color: var(--primary); }
  .has-bottom-nav .wrap { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
  .has-bottom-nav .toasts { bottom: calc(72px + env(safe-area-inset-bottom)); }
}

/* ---------- Panel z Cycusiem: nazwa i sekcje (wspólne dla /razem i /kino) ---------- */
.r-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.r-name { font: 700 22px/1.1 var(--font-display); text-transform: uppercase; flex: 1 1 auto; min-width: max-content; }
.sec-tabs { display: flex; max-width: 100%; overflow-x: auto; gap: 4px; padding: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); }
.sec-tabs a { min-height: 36px; display: inline-flex; align-items: center; padding: 0 14px; border-radius: var(--r-sm); font-weight: 600; font-size: 14px; color: var(--text-muted); text-decoration: none; }
.sec-tabs a[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1), inset 0 0 0 1px var(--border); }
@media (max-width: 640px) {
  .r-top { padding: 0 8px; }
  /* telefon: nazwa w jednej linii, przełącznik sekcji pod nią na całą szerokość */
  .r-top .sec-tabs { width: 100%; }
  .sec-tabs a { flex: 1 1 auto; justify-content: center; padding: 0 10px; }
}

.sec-tabs .n { font-variant-numeric: tabular-nums; margin-left: 4px; color: var(--text-muted); }
.sec-tabs a { white-space: nowrap; }


/* Średnie ekrany: przy wielu projektach górne zakładki nie mieszczą się z nazwami - zostają ikony,
   pełna nazwa tylko przy bieżącym (reszta ma podpis dla czytnika ekranu i dymek). */
.nav-tabs { min-width: 0; }
@media (min-width: 641px) and (max-width: 1180px) {
  .nav-tabs a:not([aria-current="page"]) { padding: 0 10px; }
  .nav-tabs a:not([aria-current="page"]) span {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
}
