/* ============================================================
   Kasa — základ a sdílené komponenty
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3, h4 { font-weight: 660; letter-spacing: -0.01em; }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; }
a { color: var(--accent); text-decoration: none; }

::selection { background: var(--accent-soft-2); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Čísla a částky — vždy tabulkové */
.num, .money, .time, input[type="number"] {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

.mono { font-family: ui-monospace, "SF Mono", "Roboto Mono", monospace; }

/* ---------- Ikony ---------- */
.ic {
  width: 24px; height: 24px;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ic-sm { width: 20px; height: 20px; }
.ic-lg { width: 28px; height: 28px; }

/* ---------- Tlačítka ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--tap-sm);
  padding: 0 var(--sp-5);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--surface);
  font-weight: 560; font-size: var(--fs-base);
  cursor: pointer;
  user-select: none;
  transition: transform var(--t-fast) var(--ease), background var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .45; pointer-events: none; }

.btn--primary {
  background: var(--accent); border-color: transparent; color: var(--accent-ink);
  box-shadow: var(--e1);
}
.btn--primary:hover { background: var(--accent-strong); }
.btn--soft { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
html[data-theme="dark"] .btn--soft { color: var(--accent-strong); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn--ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn--danger { background: var(--danger); border-color: transparent; color: #fff; }
.btn--outline-danger { background: transparent; border-color: var(--danger); color: var(--danger); }

/* Velká primární akce (Zaplatit) — min 72 px */
.btn--pay {
  min-height: 76px;
  border-radius: var(--r-lg);
  font-size: var(--fs-title);
  font-weight: 640;
  width: 100%;
  letter-spacing: -0.01em;
}

.btn--icon {
  width: var(--tap-sm); height: var(--tap-sm);
  min-height: 0; padding: 0;
  border-radius: var(--r-md);
  flex: none;
}
.btn--icon-sm { width: 40px; height: 40px; min-height: 0; padding: 0; border-radius: var(--r-sm); }

/* ---------- Chipy (kategorie, filtry) ---------- */
.chiprow {
  display: flex; gap: var(--sp-2);
  overflow-x: auto;
  scrollbar-width: none;
  padding: var(--sp-1) 0;
  scroll-snap-type: x proximity;
}
.chiprow::-webkit-scrollbar { display: none; }
.chiprow > * { scroll-snap-align: start; }

.chip {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  min-height: 44px;
  padding: 0 var(--sp-4);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: var(--surface);
  font-size: var(--fs-sm); font-weight: 560;
  color: var(--ink-2);
  cursor: pointer; white-space: nowrap;
  transition: transform var(--t-fast) var(--ease), background var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.chip:active { transform: scale(.97); }
.chip[aria-pressed="true"], .chip.is-active {
  background: var(--ink); border-color: var(--ink); color: var(--bg);
}
html[data-theme="dark"] .chip[aria-pressed="true"],
html[data-theme="dark"] .chip.is-active { background: var(--ink); color: var(--bg); }
.chip .cnt { font-size: var(--fs-caption); opacity: .75; }

/* ---------- Plochy ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--e1);
}
.card--flat { box-shadow: none; }
.card-pad { padding: var(--sp-5); }

.section-title {
  font-size: var(--fs-caption);
  font-weight: 640;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ---------- Seznamy ---------- */
.rowlist { display: flex; flex-direction: column; }
.rowitem {
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: 60px;
  padding: var(--sp-2) var(--sp-2);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease);
}
.rowitem:hover { background: var(--surface-2); }
.rowitem + .rowitem { margin-top: 2px; }

.avatar {
  width: 44px; height: 44px; flex: none;
  border-radius: var(--r-full);
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
  font-weight: 660; font-size: var(--fs-base);
}
html[data-theme="dark"] .avatar { color: var(--accent-strong); }

/* ---------- Štítky / stavové značky ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px;
  border-radius: var(--r-full);
  font-size: var(--fs-caption); font-weight: 620;
  background: var(--surface-2); color: var(--ink-2);
  white-space: nowrap;
}
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--danger  { background: var(--danger-soft);  color: var(--danger); }
.badge--info    { background: var(--info-soft);    color: var(--info); }
.badge--accent  { background: var(--accent-soft);  color: var(--accent); }
html[data-theme="dark"] .badge--accent { color: var(--accent-strong); }
.badge .ic { width: 15px; height: 15px; stroke-width: 2.2; }

/* ---------- Přepínače ---------- */
.switch {
  position: relative; width: 52px; height: 32px; flex: none;
  border-radius: var(--r-full);
  background: var(--surface-3);
  border: none; cursor: pointer;
  transition: background var(--t-med) var(--ease);
}
.switch::after {
  content: ""; position: absolute; top: 4px; left: 4px;
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: var(--e1);
  transition: transform var(--t-med) var(--spring);
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }

/* ---------- Vstupní pole ---------- */
.field {
  display: flex; align-items: center; gap: var(--sp-2);
  min-height: var(--tap-sm);
  padding: 0 var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field input {
  flex: 1; min-width: 0;
  border: none; outline: none; background: transparent;
  font-size: var(--fs-base);
}
.field input::placeholder { color: var(--ink-3); }
.field .ic { color: var(--ink-3); }

.input-lg {
  width: 100%;
  min-height: 56px;
  padding: 0 var(--sp-4);
  font-size: var(--fs-title);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--surface);
}
.input-lg:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- Segmentovaný přepínač ---------- */
.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-2);
  border-radius: var(--r-md);
}
.seg button {
  border: none; background: transparent;
  min-height: 40px; padding: 0 var(--sp-4);
  border-radius: 13px;
  font-size: var(--fs-sm); font-weight: 560; color: var(--ink-2);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.seg button[aria-pressed="true"] {
  background: var(--surface); color: var(--ink);
  box-shadow: var(--e1);
}

/* ---------- Bottom sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: var(--scrim);
  opacity: 0;
  transition: opacity var(--t-med) var(--ease);
}
.sheet-backdrop.is-open { opacity: 1; }

.sheet {
  position: fixed; z-index: 61;
  left: 50%; translate: -50% 0;
  bottom: 0;
  width: min(100%, 560px);
  max-height: min(92dvh, 900px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--e3);
  transform: translateY(105%);
  transition: transform var(--t-slow) var(--spring);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sheet.is-open { transform: translateY(0); }
.sheet.is-closing { transform: translateY(105%); transition: transform var(--t-med) var(--ease); }

.sheet--wide { width: min(100%, 720px); }

.sheet-grip {
  display: flex; justify-content: center;
  padding: 10px 0 4px;
  cursor: grab; touch-action: none;
  flex: none;
}
.sheet-grip::before {
  content: ""; width: 40px; height: 5px; border-radius: 3px;
  background: var(--line-2);
}
.sheet-head {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-5) var(--sp-3);
  flex: none;
}
.sheet-title { font-size: var(--fs-title); font-weight: 640; flex: 1; min-width: 0; }
.sheet-sub { font-size: var(--fs-sm); color: var(--ink-2); font-weight: 460; }
.sheet-body {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 0 var(--sp-5) var(--sp-5);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.sheet-foot {
  flex: none;
  display: flex; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  padding-bottom: calc(var(--sp-4) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: var(--surface);
}

/* Šířkové varianty na terminálu: sheet jako plovoucí karta */
@media (min-width: 1025px) {
  .sheet {
    bottom: auto; top: 50%; translate: -50% -50%;
    border-radius: var(--r-xl);
    max-height: min(86dvh, 860px);
    transform: translateY(24px); opacity: 0;
    transition: transform var(--t-slow) var(--spring), opacity var(--t-med) var(--ease);
  }
  .sheet.is-open { transform: translateY(0); opacity: 1; }
  .sheet.is-closing { transform: translateY(24px); opacity: 0; }
}

/* ---------- Toasty + undo ---------- */
#toast-root {
  position: fixed; z-index: 90;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--sp-3));
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
  pointer-events: none;
  width: min(92vw, 480px);
}
@media (min-width: 601px) { #toast-root { bottom: var(--sp-6); } }

.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: 52px;
  padding: var(--sp-2) var(--sp-4);
  background: color-mix(in srgb, var(--ink) 94%, transparent);
  color: var(--bg);
  border-radius: var(--r-md);
  box-shadow: var(--e3);
  font-size: var(--fs-sm);
  animation: toast-in var(--t-slow) var(--spring);
  max-width: 100%;
}
.toast.is-out { animation: toast-out var(--t-med) var(--ease) forwards; }
.toast .ic { color: var(--accent-strong); }
html[data-theme="dark"] .toast .ic { color: var(--accent); }
.toast .ic--warn { color: var(--warning); }
.toast-msg { flex: 1; }
.toast-undo {
  border: none; background: transparent;
  color: var(--accent-strong);
  font-weight: 660; font-size: var(--fs-sm);
  cursor: pointer; padding: var(--sp-2) var(--sp-2);
  border-radius: var(--r-sm);
}
html[data-theme="dark"] .toast-undo { color: var(--accent); }
.toast-undo:hover { background: rgba(255,255,255,.08); }

@keyframes toast-in { from { opacity: 0; transform: translateY(16px) scale(.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px) scale(.97); } }

/* ---------- Skeletony ---------- */
.skel {
  border-radius: var(--r-sm);
  background: linear-gradient(100deg, var(--surface-2) 40%, var(--surface-3) 50%, var(--surface-2) 60%);
  background-size: 200% 100%;
  animation: skel 1.4s linear infinite;
  min-height: 14px;
}
@keyframes skel { from { background-position: 180% 0; } to { background-position: -20% 0; } }

/* ---------- Prázdné stavy ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-3);
  text-align: center;
  padding: var(--sp-12) var(--sp-6);
  color: var(--ink-2);
}
.empty .ic { width: 44px; height: 44px; color: var(--ink-3); stroke-width: 1.4; }
.empty-title { font-size: var(--fs-title); font-weight: 620; color: var(--ink); }
.empty p { font-size: var(--fs-sm); max-width: 34ch; }

/* ---------- Pulz widgetu při změně ---------- */
@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 var(--accent-soft-2); }
  100% { box-shadow: 0 0 0 14px transparent; }
}
.pulse { animation: pulse-ring 900ms var(--ease) 1; border-radius: var(--r-lg); }

/* ---------- Stisk / haptika na kartách ---------- */
.pressable { transition: transform var(--t-fast) var(--ease); cursor: pointer; }
.pressable:active { transform: scale(.97); }

/* ---------- Posuvníky ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 5px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }
