:root {
  --bg: #f5f3fa;
  --surface: #ffffff;
  --text: #221b33;
  --muted: #6b6478;
  --primary: #5b21b6;
  --primary-dark: #3b0764;
  --accent: #7c3aed;
  --border: #e3ddef;
  --danger: #b91c1c;
  --ok: #15803d;
  --warn: #b45309;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17121f;
    --surface: #241d33;
    --text: #f1edf8;
    --muted: #a99fc0;
    --primary: #a78bfa;
    --primary-dark: #c4b5fd;
    --accent: #8b5cf6;
    --border: #362b4a;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: 2rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.1rem;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
}

.icon-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
}

.tabs {
  display: flex;
  overflow-x: auto;
  gap: 0.4rem;
  padding: 0.6rem 0.7rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 3.4rem;
  z-index: 9;
  scrollbar-width: thin;
}

.tab {
  flex: 0 0 auto;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}

.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem;
}

.panel { display: none; }
.panel.active { display: block; }

h2 {
  font-size: 1.05rem;
  margin: 0.4rem 0 0.8rem;
  color: var(--primary-dark);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin-bottom: 0.8rem;
}

.form { display: flex; flex-direction: column; gap: 0.6rem; }

.form input, .form select, .form textarea,
.modal input, .modal select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.form label, .modal label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
  flex: 1;
}

.form-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.form-row > * { flex: 1; min-width: 130px; }

.btn {
  padding: 0.6rem 1rem;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 0.92rem;
  cursor: pointer;
}

.btn:active { opacity: 0.85; }

.btn.secondary {
  background: transparent;
  border: 1px solid var(--primary);
  color: var(--primary);
}

.btn.danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}

.actions-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}

.filter-row {
  margin-bottom: 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.filter-row select { padding: 0.3rem 0.5rem; border-radius: 8px; border: 1px solid var(--border); }

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
}

.item-title {
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.item-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  margin-left: 0.4rem;
}

.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.warn { background: #fef3c7; color: var(--warn); }
.badge.danger { background: #fee2e2; color: var(--danger); }
.badge.muted { background: var(--border); color: var(--muted); }

.item-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.item-actions button {
  font-size: 0.78rem;
  padding: 0.3rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.item-actions button.danger { color: var(--danger); border-color: var(--danger); }

.muted { color: var(--muted); }
.hint { font-size: 0.78rem; color: var(--muted); margin-top: 0.2rem; }

.chat-history {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.7rem;
  min-height: 40vh;
}

.chat-msg {
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius);
  max-width: 85%;
  font-size: 0.92rem;
  white-space: pre-wrap;
}

.chat-msg.user {
  background: var(--primary);
  color: #fff;
  align-self: flex-end;
}

.chat-msg.bot {
  background: var(--surface);
  border: 1px solid var(--border);
  align-self: flex-start;
}

.chat-msg .meta {
  display: block;
  font-size: 0.7rem;
  opacity: 0.7;
  margin-top: 0.3rem;
}

.chat-input-row {
  display: flex;
  gap: 0.5rem;
  position: sticky;
  bottom: 0.5rem;
}

.chat-input-row input {
  flex: 1;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 1rem;
}

/* [hidden] má v UA stylesheetu display:none se stejnou specificitou jako .modal – bez
   tohoto pravidla by autorský styl vyhrál a modal by zůstal (neviditelně) nad stránkou
   i se zapnutým atributem hidden, a blokoval by kliky na zbytek UI. */
.modal:not([hidden]) {
  display: flex;
}

.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.2rem;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 30;
  max-width: 90vw;
  text-align: center;
}

.toast.error { background: var(--danger); color: #fff; }

qr-img {
  max-width: 160px;
  display: block;
  margin-top: 0.4rem;
}
