:root {
  /* Dark mode (default) */
  --bg: #0f172a;
  --bg-elev: #111c2e;
  --bg-card: #1a2540;
  --bg-card-2: #213056;
  --border: #283758;
  --text: #e7ecf5;
  --text-muted: #9aa6c1;
  --accent: #5eb1ff;
  --accent-hover: #82c0ff;
  --good: #4ade80;
  --good-rgb: 74, 222, 128;
  --bad: #f87171;
  --bad-rgb: 248, 113, 113;
  --warn: #fbbf24;
  --warn-rgb: 251, 191, 36;
  --hot: #ff7e3d;
  --hot-rgb: 255, 126, 61;
}

[data-theme="light"] {
  --bg: #f8fafc;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-card-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --good: #16a34a;
  --good-rgb: 22, 163, 74;
  --bad: #dc2626;
  --bad-rgb: 220, 38, 38;
  --warn: #d97706;
  --warn-rgb: 217, 119, 6;
  --hot: #ea580c;
  --hot-rgb: 234, 88, 12;
}

* {
  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;
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.5;
}

body {
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  color: var(--accent-hover);
}

/* ---- TOPBAR ---- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
  flex-wrap: wrap;
  gap: 8px;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  color: var(--text);
}
.brand-logo {
  font-size: 22px;
}
.brand-name {
  font-weight: 700;
  font-size: 18px;
}
.brand-tag {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: normal;
}
.topnav {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}
.topnav a {
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--bg-card);
}
.topnav a:hover {
  background: var(--bg-card-2);
}

/* ---- LAYOUT ---- */

.container {
  max-width: 1024px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 18px 48px;
  flex: 1;
}
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

h1 {
  font-size: 28px;
  margin: 0 0 6px;
}
h2 {
  font-size: 20px;
  margin: 28px 0 12px;
}
h3 {
  font-size: 17px;
  margin: 0 0 6px;
}

.subtitle {
  color: var(--text-muted);
  margin: 0 0 22px;
}

/* ---- CHIPS ---- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
}
.chip-hot {
  background: rgba(var(--hot-rgb, 255, 126, 61), 0.16);
  border-color: rgba(var(--hot-rgb, 255, 126, 61), 0.45);
  color: var(--hot);
}
.chip-frequency {
  gap: 6px;
}

/* ---- CARDS / GRIDS ---- */

.cards {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  transition:
    transform 0.05s ease,
    background 0.1s ease;
  text-align: left;
  color: inherit;
  font: inherit;
}
.card:hover {
  background: var(--bg-card-2);
  transform: translateY(-1px);
}
.card-disabled {
  cursor: default;
  opacity: 0.75;
}
.card-disabled:hover {
  background: var(--bg-card);
  transform: none;
}
.card .code {
  font-weight: 700;
  color: var(--accent);
  font-size: 14px;
}
.card .name {
  font-weight: 600;
  font-size: 15px;
}
.card .meta {
  color: var(--text-muted);
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 28px 0 12px;
}
.section-title h2 {
  margin: 0;
}
.section-title .count {
  color: var(--text-muted);
  font-size: 13px;
}

/* ---- CATALOG SEARCH ---- */

.catalog-search-wrap {
  margin-bottom: 22px;
}
.catalog-search-wrap--tight {
  margin-bottom: 18px;
}
.catalog-search-label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.catalog-search-input {
  width: 100%;
  max-width: 520px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font: inherit;
}
.catalog-search-results {
  margin-top: 12px;
  max-width: 640px;
}
.catalog-search-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.catalog-search-hit {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: inherit;
  text-decoration: none;
}
.catalog-search-hit:hover {
  background: var(--bg-card-2);
}
.catalog-search-kind {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  font-weight: 600;
}
.catalog-search-title {
  font-weight: 600;
  font-size: 15px;
}
.catalog-search-meta {
  font-size: 13px;
  color: var(--text-muted);
}
.catalog-search-empty {
  color: var(--text-muted);
  font-size: 14px;
  margin: 8px 0 0;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.tab {
  padding: 8px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
}
.tab.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}

/* ---- QUIZ ---- */

.qheader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.qheader-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.qbox {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  scroll-margin-top: 76px;
}
.qprompt {
  font-size: 1.28rem;
  line-height: 1.52;
  margin: 10px 0 22px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.qimg {
  display: block;
  max-width: 100%;
  margin: 12px auto 18px;
  border-radius: 8px;
  background: #fff;
}
.qopts {
  display: grid;
  gap: 10px;
}
.qopt {
  text-align: left;
  padding: 12px 14px;
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.qopt:hover:not(:disabled) {
  background: var(--bg-card-2);
  filter: brightness(1.2);
}
.qopt[data-state="correct"] {
  background: rgba(var(--good-rgb, 74, 222, 128), 0.18);
  border-color: var(--good);
}
.qopt[data-state="wrong"] {
  background: rgba(var(--bad-rgb, 248, 113, 113), 0.18);
  border-color: var(--bad);
}
.qopt-letter {
  font-weight: 700;
  color: var(--accent);
  min-width: 20px;
}

.qfooter {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 22px;
  flex-wrap: wrap;
  gap: 12px;
}
.qstats {
  color: var(--text-muted);
  font-size: 13px;
}

.qfooter-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

/* Quiz view: więcej miejsca nad stopką na telefonie, akcent na karcie pytania */
#app.view-quiz.container {
  min-height: calc(100dvh - 132px);
  padding-bottom: max(36px, env(safe-area-inset-bottom, 0px));
}

#app.view-quiz .qheader {
  margin-bottom: 10px;
}

#app.view-quiz .qheader h1 {
  font-size: clamp(1.2rem, 4.2vw, 1.65rem);
  line-height: 1.25;
}

#app.view-quiz .qheader .subtitle {
  margin-bottom: 10px;
  font-size: 14px;
}

.btn {
  background: var(--accent);
  color: var(--bg);
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover {
  background: var(--accent-hover);
}
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  background: var(--bg-card-2);
}
.btn-warn {
  background: transparent;
  color: var(--warn);
  border: 1px solid rgba(var(--warn-rgb, 251, 191, 36), 0.4);
  padding: 6px 10px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
}
.btn-warn:hover {
  background: rgba(var(--warn-rgb, 251, 191, 36), 0.12);
}

.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---- TEST MODE (40 pytań) ---- */

.test-progress {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.test-step {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: var(--bg-card-2);
  border: 1px solid var(--border);
}
.test-step[data-state="correct"] {
  background: var(--good);
  border-color: var(--good);
}
.test-step[data-state="wrong"] {
  background: var(--bad);
  border-color: var(--bad);
}
.test-step[data-state="current"] {
  background: var(--accent);
  border-color: var(--accent);
}

.test-summary {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  text-align: center;
}
.test-score {
  font-size: 42px;
  font-weight: 700;
  margin: 12px 0;
}
.test-score.pass {
  color: var(--good);
}
.test-score.fail {
  color: var(--bad);
}

/* ---- MODAL ---- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-backdrop.open {
  display: flex;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 540px;
  padding: 22px;
  max-height: calc(100vh - 40px);
  overflow: auto;
}
.modal h2 {
  margin: 0 0 12px;
}
.modal label {
  display: block;
  margin-top: 14px;
  font-size: 14px;
  color: var(--text-muted);
}
.modal textarea,
.modal input,
.modal select {
  width: 100%;
  margin-top: 4px;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
}
.modal textarea {
  min-height: 110px;
  resize: vertical;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* ---- TOAST ---- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--bg-card-2);
  color: var(--text);
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 60;
}
.toast.show {
  opacity: 1;
}

/* ---- COFFEE BANNER ---- */

.coffee-banner {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  max-width: 340px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  z-index: 40;
  display: none;
}
.coffee-banner.open {
  display: block;
}
.coffee-banner-title {
  font-weight: 600;
  margin-bottom: 6px;
}
.coffee-banner-body {
  color: var(--text-muted);
  font-size: 13.5px;
  margin-bottom: 12px;
}
.coffee-banner-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---- FOOTER ---- */

.footer {
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  padding: 18px 24px max(22px, calc(env(safe-area-inset-bottom, 0px) + 14px));
  color: var(--text-muted);
  font-size: 13px;
  margin-top: auto;
}
.footer-disclaimer {
  margin-bottom: 6px;
}
.footer-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.footer-spacer {
  color: var(--border);
}

/* ---- BREADCRUMB ---- */

.crumb {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.crumb a {
  color: var(--text-muted);
}
.crumb a:hover {
  color: var(--accent);
}
.crumb-sep {
  margin: 0 6px;
  opacity: 0.5;
}

/* ---- ERRORS / EMPTY STATES ---- */

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

/* ---- PSZCZELARZ / PASIEKA MAP ---- */

.home-extra-block {
  margin-top: 36px;
}

.home-extra-subsection {
  margin-top: 22px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

.section-title--sub {
  margin: 0 0 12px;
}
.section-title--sub h2,
.section-title--sub h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--text-muted);
}

.pszczelarz-extras {
  margin-top: 32px;
}

.pszczelarz-page .pszczelarz-tabs {
  margin-bottom: 22px;
}
.pszczelarz-tabs .tab {
  text-decoration: none;
  display: inline-block;
}
.pszczelarz-tabs--compact {
  margin-bottom: 14px;
}
.pszczelarz-footnote {
  margin-top: 28px;
  font-size: 13px;
  color: var(--text-muted);
}

#app.view-pasieka.container {
  max-width: none;
  width: 100%;
  padding: 0;
  margin: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 120px);
}

.pasieka-layout {
  display: flex;
  flex: 1;
  min-height: calc(100vh - 120px);
  width: 100%;
}

.pasieka-map-wrap {
  flex: 1;
  position: relative;
  min-height: 360px;
}

.pasieka-map {
  width: 100%;
  height: 100%;
  min-height: calc(100vh - 120px);
  background: var(--bg-card-2);
  z-index: 0;
}

.pasieka-map-hint {
  position: absolute;
  left: 12px;
  bottom: 12px;
  margin: 0;
  padding: 8px 12px;
  background: rgba(15, 23, 42, 0.82);
  color: #e7ecf5;
  border-radius: 8px;
  font-size: 13px;
  z-index: 500;
  pointer-events: none;
  max-width: min(420px, calc(100% - 24px));
}

[data-theme="light"] .pasieka-map-hint {
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  border: 1px solid var(--border);
}

.pasieka-panel {
  width: min(340px, 100%);
  flex-shrink: 0;
  padding: 16px 18px 24px;
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  max-height: calc(100vh - 120px);
}

.pasieka-panel-title {
  margin: 0 0 6px;
  font-size: 18px;
}

.pasieka-panel-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 16px;
}

.pasieka-label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.pasieka-search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.pasieka-search-row .catalog-search-input {
  flex: 1;
  max-width: none;
}

.pasieka-geo-results {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  max-height: 160px;
  overflow-y: auto;
}
.pasieka-geo-hit {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: none;
  background: var(--bg-card);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  margin-bottom: 4px;
}
.pasieka-geo-hit:hover {
  background: var(--bg-card-2);
}
.pasieka-geo-empty,
.pasieka-geo-loading {
  font-size: 13px;
  color: var(--text-muted);
  padding: 6px 0;
}

.pasieka-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.pasieka-bulk-radius {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.pasieka-bulk-radius-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.pasieka-bulk-radius-row .catalog-search-input {
  flex: 1;
  max-width: none;
}
.pasieka-bulk-radius-row .btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover {
  background: var(--accent-hover);
  color: var(--bg);
}

.pasieka-hive-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pasieka-hive-item {
  padding: 12px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.pasieka-hive-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.pasieka-color {
  width: 36px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
}

.pasieka-name {
  flex: 1;
  min-width: 80px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.pasieka-vis {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.pasieka-del {
  padding: 4px 8px;
  font-size: 16px;
  line-height: 1;
}

.pasieka-radius {
  width: 100%;
  max-width: none;
  margin-bottom: 8px;
}

.pasieka-center {
  font-size: 13px;
}

.pasieka-hive-empty {
  font-size: 13px;
  color: var(--text-muted);
  padding: 8px 0;
}

.pasieka-legal {
  margin-top: 18px;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.45;
}

.hive-marker-wrap {
  background: none !important;
  border: none !important;
}

.hive-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
  font-size: 14px;
  line-height: 1;
}

.leaflet-container {
  font-family: inherit;
}

@media (max-width: 900px) {
  .pasieka-layout {
    flex-direction: column;
  }
  .pasieka-panel {
    width: 100%;
    max-height: none;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .pasieka-map,
  .pasieka-map-wrap {
    min-height: 55vh;
  }
}

@media (max-width: 540px) {
  .topbar {
    padding: 10px 14px;
  }
  .container {
    padding: 16px 14px 40px;
  }
  #app.view-quiz.container {
    min-height: calc(100dvh - 112px);
    padding-bottom: max(32px, calc(env(safe-area-inset-bottom, 0px) + 24px));
  }
  .qbox {
    padding: 16px;
    scroll-margin-top: 64px;
  }
  .qprompt {
    font-size: 1.18rem;
    margin-top: 8px;
  }
  .qfooter {
    flex-direction: column;
    align-items: stretch;
  }
  .qfooter-actions {
    justify-content: stretch;
  }
  .qfooter-actions .btn {
    flex: 1;
    text-align: center;
  }
  .modal {
    padding: 18px;
  }
  .footer {
    padding: 16px 14px max(20px, calc(env(safe-area-inset-bottom, 0px) + 12px));
  }
}
