:root {
  --bg: #0b0b14;
  --card: rgba(18, 18, 34, 0.72);
  --card-strong: rgba(18, 18, 34, 0.9);
  --line: rgba(255, 255, 255, 0.1);
  --text: #f5f5fa;
  --muted: #a9a9c0;
  --accent: #ff3d6e;
  --accent2: #7b5cff;
  --grad: linear-gradient(135deg, var(--accent), var(--accent2));
  --ok: #2fd27a;
  --warn: #ffb020;
  --danger: #ff4d5e;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: #ff8fb0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
body:not(.is-admin) .admin-only { display: none !important; }
body.is-admin .user-only { display: none !important; }

/* ---------- Pozadí ---------- */
.bg, .bg-photo, .bg-shade { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.bg {
  background:
    radial-gradient(60% 40% at 15% 10%, rgba(255, 61, 110, 0.35), transparent 70%),
    radial-gradient(60% 45% at 90% 30%, rgba(123, 92, 255, 0.35), transparent 70%),
    radial-gradient(70% 50% at 50% 100%, rgba(0, 200, 255, 0.15), transparent 70%),
    var(--bg);
}
.bg-photo {
  background-size: cover;
  background-position: center 40%;
  filter: brightness(0.7) saturate(1.1);
  opacity: 0;
  transition: opacity 0.8s ease;
}
.bg-photo.show { opacity: 1; }
.bg-shade {
  background: linear-gradient(180deg, rgba(11, 11, 20, 0.45) 0%, rgba(11, 11, 20, 0.35) 30%, rgba(11, 11, 20, 0.75) 75%, rgba(11, 11, 20, 0.9) 100%);
}

/* ---------- Obrazovky ---------- */
.screen { position: relative; z-index: 1; height: 100dvh; overflow-y: auto; padding: 20px; }
.screen.center { display: flex; align-items: center; justify-content: center; }
.glass {
  background: var(--card);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
}
.auth-card {
  width: 100%; max-width: 400px; padding: 28px 22px; border-radius: 24px; box-shadow: var(--shadow); text-align: center;
}
.auth-card h1 { margin: 6px 0 4px; font-size: 1.6rem; }
.auth-card form, .auth-card .stack { text-align: left; margin-top: 18px; }
.logo {
  width: 64px; height: 64px; margin: 0 auto; border-radius: 20px; display: grid; place-items: center;
  font-size: 32px; background: var(--grad); box-shadow: 0 8px 24px rgba(255, 61, 110, 0.4);
}
.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.15); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.load-fail { position: absolute; bottom: 20%; left: 20px; right: 20px; text-align: center; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-top: 18px; border-radius: 14px; background: rgba(255, 255, 255, 0.06); }
.seg button { border: 0; background: transparent; padding: 10px; border-radius: 10px; cursor: pointer; color: var(--muted); font-weight: 600; }
.seg button.active { background: rgba(255, 255, 255, 0.12); color: var(--text); }

/* ---------- Formuláře ---------- */
.stack { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); font-weight: 600; }
input, textarea, select {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.3); color: var(--text); font-size: 16px; outline: none;
}
input:focus, textarea:focus { border-color: rgba(255, 61, 110, 0.7); box-shadow: 0 0 0 3px rgba(255, 61, 110, 0.18); }
textarea { resize: vertical; min-height: 80px; }
input[type="file"] { padding: 10px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.hint { font-size: 0.82rem; color: var(--muted); margin: 0; font-weight: 400; }
.msg { min-height: 1.2em; margin: 12px 0 0; font-size: 0.9rem; }
.msg.error { color: #ff8a96; }
.msg.ok { color: var(--ok); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.08); color: var(--text);
  padding: 11px 16px; border-radius: 12px; font-weight: 700; cursor: pointer; text-decoration: none;
  transition: transform 0.08s ease, opacity 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn.primary { background: var(--grad); border-color: transparent; box-shadow: 0 6px 18px rgba(255, 61, 110, 0.3); }
.btn.ghost { background: rgba(255, 255, 255, 0.06); }
.btn.danger { background: rgba(255, 77, 94, 0.15); border-color: rgba(255, 77, 94, 0.4); color: #ff9aa4; }
.btn.danger-solid { background: #e5394d; border-color: transparent; color: #fff; box-shadow: 0 6px 18px rgba(229, 57, 77, 0.35); }
.confirm-box { text-align: center; }
.confirm-box h2 { margin: 14px 0 6px; }
.confirm-box p { margin: 0 0 18px; }
.check-row { flex-direction: row; align-items: center; gap: 10px; font-weight: 600; color: var(--text); cursor: pointer; }
.check-row input { width: 20px; height: 20px; flex: 0 0 20px; accent-color: var(--accent); }
.btn.success { background: rgba(47, 210, 122, 0.16); border-color: rgba(47, 210, 122, 0.45); color: #7ff0b0; }
.btn.small { padding: 7px 12px; font-size: 0.85rem; border-radius: 10px; }
.btn.block { width: 100%; }
.icon-btn {
  width: 40px; height: 40px; flex: 0 0 40px; display: grid; place-items: center; border-radius: 12px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); cursor: pointer; font-size: 1.1rem;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.08); font-size: 0.85rem; cursor: pointer; max-width: 100%;
}

/* ---------- Layout aplikace ---------- */
#app { position: relative; z-index: 1; height: 100dvh; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; }
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  border-width: 0 0 1px; border-radius: 0 0 18px 18px;
}
.brand { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-logo { width: 32px; height: 32px; flex: 0 0 32px; border-radius: 10px; display: grid; place-items: center; background: var(--grad); font-size: 17px; }
.nick-chip { max-width: 40vw; }
.nick-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 14px 28px; -webkit-overflow-scrolling: touch; }
main.chat-mode { overflow: hidden; padding: 0; display: flex; flex-direction: column; }
.view-title { margin: 14px 2px 12px; font-size: 1.5rem; text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6); }
.list { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); border-radius: var(--radius); border: 1px dashed var(--line); background: rgba(0, 0, 0, 0.25); }

.tabbar {
  display: flex; padding: 6px 6px calc(env(safe-area-inset-bottom) + 6px);
  border-width: 1px 0 0; border-radius: 18px 18px 0 0;
}
.tabbar button {
  flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px; border: 0; background: transparent; color: var(--muted); font-size: 0.72rem; font-weight: 700; cursor: pointer; border-radius: 12px;
}
.tabbar .ti { font-size: 1.35rem; line-height: 1; filter: grayscale(0.6); }
.tabbar button.active { color: var(--text); background: rgba(255, 255, 255, 0.08); }
.tabbar button.active .ti { filter: none; }
.badge {
  position: absolute; top: 2px; left: calc(50% + 8px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 0.7rem; font-style: normal; line-height: 18px; text-align: center;
}

/* ---------- Karty ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.card.pending { border-color: rgba(255, 176, 32, 0.55); }
.card-head { display: flex; align-items: flex-start; gap: 10px; }
.card-head h3 { flex: 1; margin: 0; font-size: 1.12rem; word-break: break-word; }
.tag { flex: 0 0 auto; padding: 3px 9px; border-radius: 999px; font-size: 0.72rem; font-weight: 800; background: rgba(255, 255, 255, 0.1); }
.tag.warn { background: rgba(255, 176, 32, 0.18); color: #ffd27a; }
.tag.ok { background: rgba(47, 210, 122, 0.18); color: #7ff0b0; }
.tag.accent { background: var(--grad); color: #fff; }
.card-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; font-size: 0.8rem; color: var(--muted); }
.card-foot .spacer { flex: 1; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.text { white-space: pre-wrap; word-break: break-word; margin: 10px 0 0; }

/* Výdaje */
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.summary .card { padding: 14px; }
.summary .label { font-size: 0.75rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.summary .value { font-size: 1.35rem; font-weight: 800; margin-top: 2px; }
.summary .value.debt { color: #ff9aa4; }
.summary .value.clear { color: #7ff0b0; }
.money { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 14px; margin-top: 10px; }
.money .total { font-size: 1.6rem; font-weight: 800; }
.money .split { color: var(--muted); }
.money .split b { color: var(--text); font-size: 1.1rem; }
.progress { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.1); margin-top: 12px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--ok), #9cf5c4); border-radius: 3px; transition: width 0.3s; }
.payers { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.payer {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 999px; font-size: 0.88rem; font-weight: 600;
  border: 1px solid rgba(255, 77, 94, 0.45); background: rgba(255, 77, 94, 0.12); color: #ffc2c8; cursor: default;
}
.payer.paid { border-color: rgba(47, 210, 122, 0.5); background: rgba(47, 210, 122, 0.15); color: #b6f7d2; }
.payer.me { box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5); }
body.is-admin .payer { cursor: pointer; }

/* Obrázky */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 12px; }
.thumbs.single { grid-template-columns: minmax(0, 220px); }
.thumb { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: rgba(255, 255, 255, 0.06); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.thumbs.single .thumb { aspect-ratio: auto; }
.thumbs.single .thumb img { height: auto; max-height: 280px; object-fit: contain; background: #fff; }
.thumbs.wide { grid-template-columns: 1fr; }
.thumbs.wide .thumb { aspect-ratio: 16 / 10; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.thumb .remove {
  position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; border: 0;
  background: rgba(0, 0, 0, 0.7); color: #fff; cursor: pointer; font-size: 0.9rem;
}
.thumb.removed img { opacity: 0.25; }

/* Program */
.day-head { margin: 10px 2px -4px; font-weight: 800; font-size: 0.95rem; color: #ffd0dc; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7); }
.time-badge { flex: 0 0 auto; padding: 4px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.1); font-weight: 800; font-variant-numeric: tabular-nums; }
.card.next { border-color: rgba(255, 61, 110, 0.7); box-shadow: 0 0 0 1px rgba(255, 61, 110, 0.4), var(--shadow); }
.card.past > * { opacity: 0.6; }

/* Chat */
#view-chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-list { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 12px 8px; -webkit-overflow-scrolling: touch; }
.center-btn { display: flex; margin: 4px auto 12px; }
.chat-day { text-align: center; margin: 14px 0 8px; }
.chat-day span { font-size: 0.75rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: rgba(0, 0, 0, 0.5); color: var(--muted); }
.msg-row { display: flex; margin: 3px 0; }
.msg-row.mine { justify-content: flex-end; }
.bubble {
  position: relative; max-width: 82%; padding: 8px 12px; border-radius: 18px 18px 18px 6px;
  background: var(--card-strong); border: 1px solid var(--line);
}
.mine .bubble { border-radius: 18px 18px 6px 18px; background: linear-gradient(135deg, rgba(255, 61, 110, 0.92), rgba(123, 92, 255, 0.92)); border-color: transparent; }
.bubble .who { font-size: 0.75rem; font-weight: 800; margin-bottom: 2px; }
.bubble .body { white-space: pre-wrap; word-break: break-word; }
.bubble .meta { font-size: 0.68rem; opacity: 0.7; text-align: right; margin-top: 2px; }
.bubble img { display: block; max-width: 100%; max-height: 300px; border-radius: 12px; margin: 4px 0; cursor: zoom-in; }
.bubble .del {
  position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; border-radius: 50%;
  border: 1px solid var(--line); background: #2a2a40; color: #ff9aa4; font-size: 0.75rem; cursor: pointer; display: none;
}
body.is-admin .bubble .del { display: block; }
.chat-preview { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--card-strong); border-top: 1px solid var(--line); }
.chat-preview img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; }
.chat-bar { display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px; border-width: 1px 0 0; }
.chat-bar textarea { min-height: 42px; max-height: 140px; padding: 10px 14px; border-radius: 21px; resize: none; line-height: 1.35; }
.chat-bar .attach { height: 42px; width: 42px; flex-basis: 42px; border-radius: 50%; }
.send-btn { width: 42px; height: 42px; flex: 0 0 42px; border-radius: 50%; border: 0; background: var(--grad); color: #fff; font-size: 1.1rem; cursor: pointer; }
.send-btn:disabled { opacity: 0.5; }

/* Nákupy */
.shop-extra { display: grid; grid-template-columns: 1fr 1.25fr 1fr; gap: 8px; }
.shop-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin: 10px 2px -4px; font-weight: 800; color: #ffd0dc; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7); }
.shop-head .muted { font-weight: 600; font-size: 0.82rem; }
.shop-group { padding: 2px 14px; }
.shop-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.shop-item:first-child { border-top: 0; }
.check {
  width: 32px; height: 32px; flex: 0 0 32px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.35);
  background: transparent; color: #fff; font-weight: 900; cursor: pointer; display: grid; place-items: center;
}
.shop-item.bought .check { background: var(--ok); border-color: var(--ok); color: #0b2a19; }
.si-main { flex: 1; min-width: 0; }
.si-name { font-weight: 700; word-break: break-word; }
.shop-item.bought .si-name, .shop-item.bought .si-price { text-decoration: line-through; opacity: 0.55; }
.qty { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.12); font-size: 0.8rem; font-weight: 700; text-decoration: none; }
.si-meta { font-size: 0.75rem; color: var(--muted); }
.si-price { font-weight: 800; white-space: nowrap; }
.mini-btn { width: 32px; height: 32px; flex: 0 0 32px; border-radius: 10px; font-size: 0.85rem; }

/* Admin */
.admin-section { margin-bottom: 16px; }
.admin-section h3 { margin: 0 0 10px; font-size: 1.05rem; }
.user-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.user-row:first-of-type { border-top: 0; }
.user-row .name { flex: 1; min-width: 120px; font-weight: 700; word-break: break-all; }
.bg-preview { width: 100%; max-height: 220px; object-fit: cover; border-radius: 12px; margin: 8px 0; }

/* Chip input (kdo platí) */
.chips-input { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.3); }
.chips-input .chip { cursor: default; color: var(--text); }
.chips-input .chip button { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 0 0 0 2px; font-size: 1rem; line-height: 1; }
.chips-input input { flex: 1; min-width: 120px; border: 0; background: transparent; padding: 6px; box-shadow: none; }
.crew-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 6px 0; }
.crew-pick { padding: 12px 6px; font-weight: 700; justify-content: center; opacity: 0.6; }
.crew-pick.active { opacity: 1; background: var(--grad); border-color: transparent; color: #fff; }
.preview-line { padding: 12px 14px; border-radius: 12px; background: rgba(255, 255, 255, 0.06); font-weight: 700; }
.preview-line b { font-size: 1.15rem; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- Modal, lightbox, toast ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, 0.6); animation: fade 0.15s ease;
}
.modal-card {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; padding: 20px 18px calc(env(safe-area-inset-bottom) + 20px);
  border-radius: 24px 24px 0 0; background: rgba(20, 20, 36, 0.94); animation: up 0.2s ease;
}
.modal-card h2 { margin: 0 0 14px; font-size: 1.3rem; }
@media (min-width: 640px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 24px; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }

.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, 0.94); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
.lightbox img { max-width: 100%; max-height: calc(100dvh - 110px); object-fit: contain; border-radius: 8px; background: #fff; }
.lightbox-bar { display: flex; gap: 10px; margin-top: 14px; }

.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 72px); z-index: 70; transform: translate(-50%, -20px);
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 14px; background: #24243a; border: 1px solid var(--line);
  box-shadow: var(--shadow); font-weight: 600; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #4a1d27; border-color: rgba(255, 77, 94, 0.5); }
.toast.ok { background: #173a2a; border-color: rgba(47, 210, 122, 0.5); }
