:root {
  --bg: #101114;
  --surface: #1b1d22;
  --surface-2: #24272e;
  --text: #f3f4f6;
  --muted: #9aa0ac;
  --line: #2c2f37;
  --accent: #4f8cff;
  --danger: #ff5a5a;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

.view { min-height: 100vh; padding-bottom: calc(96px + var(--safe-bottom)); }
.hidden { display: none !important; }

/* ===== Horní lišta ===== */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.top h1 {
  flex: 1; font-size: 22px; margin: 0; font-weight: 700; text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.top h1:first-child { text-align: left; }
.icon-btn {
  border: none; background: transparent; color: var(--text);
  font-size: 21px; width: 38px; height: 40px; border-radius: 12px;
  display: grid; place-items: center; cursor: pointer; flex: 0 0 auto;
}
#btn-pin { font-size: 27px; }          /* hvězdička o něco větší, ať sedí k ostatním ikonám */
#btn-pin.pinned { color: #ffc61a; }
#btn-edit { transform: scaleX(-1); }    /* tužka hrotem doleva */
.icon-btn:active { background: var(--surface-2); }
[data-back] { font-size: 30px; line-height: 1; }
.text-btn {
  border: none; background: transparent; color: var(--accent);
  font-size: 17px; font-weight: 600; padding: 8px 4px; cursor: pointer;
}

/* ===== Hledání ===== */
.search-bar { padding: 4px 16px 8px; }
.search-bar input {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-size: 16px;
}

/* ===== Mřížka karet ===== */
.card-grid {
  list-style: none; margin: 0; padding: 8px 16px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.card-tile {
  position: relative; aspect-ratio: 1.586 / 1; border-radius: var(--radius);
  padding: 14px; cursor: pointer; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between;
  color: #fff; box-shadow: 0 4px 14px rgba(0,0,0,.35);
  transition: transform .08s ease;
}
.card-tile:active { transform: scale(.97); }
.card-tile .badge {
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
  font-weight: 800; font-size: 18px; background: rgba(255,255,255,.22);
}
.card-tile .name {
  font-weight: 700; font-size: 15px; line-height: 1.2;
  text-shadow: 0 1px 3px rgba(0,0,0,.35);
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.card-tile .pin-badge {
  position: absolute; top: 8px; right: 10px; font-size: 15px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.5));
}

/* ===== Prázdný stav ===== */
.empty { text-align: center; padding: 22vh 32px 0; color: var(--muted); }
.empty-emoji { font-size: 54px; }
.empty-title { color: var(--text); font-size: 18px; font-weight: 600; margin: 12px 0 4px; }
.empty-sub { margin: 0; font-size: 15px; }

/* ===== Detail karty ===== */
.barcode-stage { padding: 24px 20px; text-align: center; }
.barcode-holder {
  background: #fff; border-radius: 16px; padding: 22px 16px;
  display: inline-block; max-width: 100%; min-width: 70%;
}
.barcode-holder svg, .barcode-holder canvas { max-width: 100%; height: auto; }
.barcode-number {
  margin: 18px 0 6px; font-size: 20px; letter-spacing: 2px;
  font-variant-numeric: tabular-nums; word-break: break-all;
}
.barcode-hint { color: var(--muted); font-size: 14px; margin: 6px auto 0; max-width: 300px; }
.note-wrap { padding: 0 24px; }
.note {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; color: var(--muted); font-size: 15px; margin: 0;
}

/* ===== Formulář ===== */
.form { padding: 8px 16px; display: flex; flex-direction: column; gap: 16px; }
.scan-cta { text-align: center; margin-top: 4px; }
.scan-btn {
  width: 100%; padding: 16px; border-radius: 14px; border: none;
  background: var(--accent); color: #fff; font-size: 17px; font-weight: 600; cursor: pointer;
}
.scan-btn:active { filter: brightness(.92); }
.scan-sub { color: var(--muted); font-size: 14px; margin: 12px 0 0; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field > span { font-size: 14px; color: var(--muted); font-weight: 500; padding-left: 2px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-size: 16px; font-family: inherit;
}
.field textarea { resize: none; }
.field select { appearance: none; }

.color-row { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 38px; height: 38px; border-radius: 50%; cursor: pointer;
  border: 3px solid transparent;
}
.swatch.sel { border-color: var(--text); }

.delete-btn {
  margin-top: 8px; width: 100%; padding: 14px; border-radius: 12px;
  border: 1px solid var(--danger); background: transparent; color: var(--danger);
  font-size: 16px; font-weight: 600; cursor: pointer;
}

/* ===== Plovoucí tlačítko ===== */
.fab {
  position: fixed; right: 20px; bottom: calc(22px + var(--safe-bottom));
  width: 60px; height: 60px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; font-size: 34px; line-height: 1;
  box-shadow: 0 6px 20px rgba(79,140,255,.45); cursor: pointer; z-index: 20;
}
.fab:active { transform: scale(.94); }

/* ===== Skener ===== */
.scanner {
  position: fixed; inset: 0; z-index: 100; background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.reader { width: 100%; }
.reader video { width: 100% !important; height: auto !important; }
.scanner-frame {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 76%; max-width: 340px; aspect-ratio: 1.3/1;
  border: 3px solid rgba(255,255,255,.85); border-radius: 16px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); pointer-events: none;
}
.scanner-hint {
  position: absolute; bottom: calc(120px + var(--safe-bottom)); color: #fff;
  font-size: 15px; text-shadow: 0 1px 4px #000;
}
.scan-close {
  position: absolute; bottom: calc(40px + var(--safe-bottom));
  padding: 14px 40px; border-radius: 30px; border: none;
  background: #fff; color: #000; font-size: 16px; font-weight: 600; cursor: pointer;
}

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: calc(100px + var(--safe-bottom));
  transform: translateX(-50%); z-index: 200;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
  padding: 12px 20px; border-radius: 30px; font-size: 15px;
  box-shadow: 0 6px 20px rgba(0,0,0,.4); max-width: 88%; text-align: center;
}

/* Číslo verze (nenápadné) */
.version {
  text-align: center; color: var(--muted); opacity: .5;
  font-size: 12px; padding: 18px 0 6px;
}

/* Dlaždice s logem/fotkou */
.card-tile.has-image {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* Logo v detailu karty */
.card-logo-wrap { margin-bottom: 16px; }
.card-logo-wrap img {
  max-height: 72px; max-width: 60%;
  border-radius: 10px; object-fit: contain;
}

/* Výběr loga ve formuláři */
.logo-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.logo-preview {
  width: 64px; height: 64px; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--line); background: var(--surface-2); flex: 0 0 auto;
}
.logo-preview img { width: 100%; height: 100%; object-fit: cover; }
.logo-pick {
  display: inline-block; padding: 12px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font-size: 15px; cursor: pointer;
}
.logo-pick:active { background: var(--surface-2); }
.logo-remove {
  border: none; background: transparent; color: var(--danger);
  font-size: 15px; cursor: pointer; padding: 8px;
}

/* Světlý režim */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f3f6; --surface: #fff; --surface-2: #e9ebf0;
    --text: #14161a; --muted: #6b7280; --line: #e0e2e8;
  }
}
