/* Coach Catalogue — soft dusty-lavender palette, mobile first.
   Dark mode follows the phone's system setting; photos keep their own
   light tile (slightly dimmed) so white-background shots don't glare. */

:root {
  --bg: #f7f6f9;
  --card: #ffffff;
  --ink: #2e2a3b;
  --ink-soft: #75708a;
  --brand: #6e6390;
  --brand-light: #a49bc4;
  --accent: #b26a8c;
  --gold: #c9a24b;
  --gold-ink: #8a6b1f;
  --line: #e7e4ee;
  --chip-bg: #f7f6f9;
  --chip-ink: #75708a;
  --chip-line: #e7e4ee;
  --chip-gold-bg: transparent;
  --field: #ffffff;
  --photo-bg: #f0eef5;
  --photo-dim: none;
  --topbar-grad: linear-gradient(120deg, #6e6390, #8a7fae);
  --shadow: 0 2px 12px rgba(60, 50, 90, 0.08);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16141d;
    --card: #221f2c;
    --ink: #eae7f3;
    --ink-soft: #a29cb8;
    --brand: #9184bd;
    --brand-light: #7a6f9e;
    --accent: #c98aa6;
    --gold: #d3b264;
    --gold-ink: #e3c87e;
    --line: #363140;
    --chip-bg: #363048;
    --chip-ink: #d6d0ea;
    --chip-line: #4f4868;
    --chip-gold-bg: rgba(211, 178, 100, 0.14);
    --field: #2b2837;
    --photo-bg: #dcd9e4;
    --photo-dim: brightness(0.87);
    --topbar-grad: linear-gradient(120deg, #3f3857, #55496f);
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }

/* ---------- Login ---------- */

.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.login-logo { font-size: 44px; }

.login-card h1 {
  margin: 8px 0 2px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.login-sub {
  margin: 0 0 20px;
  color: var(--ink-soft);
  font-size: 14px;
}

.login-card input {
  width: 100%;
  margin-bottom: 12px;
}

.login-card .btn { width: 100%; }

.login-error {
  color: var(--accent);
  font-size: 14px;
  margin: 10px 0 0;
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--topbar-grad);
  color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}

.brand {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.topbar-actions { display: flex; gap: 6px; }

.icon-btn {
  position: relative;
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #fff;
  font-size: 16px;
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
}

.icon-btn.has-dot::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
}

/* Fixed-height popup: the title and the Nice button always stay visible;
   only the changelog list in the middle scrolls. */
#news-dialog { overflow: hidden; }

.news-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 48px);
  box-sizing: border-box;
}

.news-body h2 { margin: 0 0 10px; font-weight: 700; flex: 0 0 auto; }

#news-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.news-body .dialog-buttons {
  flex: 0 0 auto;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

#news-list h3 { margin: 14px 0 0; font-size: 15px; }

#news-list h3:first-child { margin-top: 0; }

.news-date {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--ink-soft);
}

#news-list ul {
  margin: 0 0 10px;
  padding-left: 20px;
  font-size: 14px;
}

#news-list li { margin-bottom: 4px; }

/* ---------- Toolbar ---------- */

.toolbar {
  padding: 12px 16px 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#search {
  width: 100%;
  font-size: 16px;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
}

.tab {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

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

.filter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  color: var(--ink-soft);
}

.owned-filter { display: flex; align-items: center; gap: 6px; white-space: nowrap; }

/* ---------- Grid of cards ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  padding: 12px 16px 96px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
}

.card-photo {
  aspect-ratio: 1 / 1;
  width: 100%;
  object-fit: cover;
  background: var(--photo-bg);
  filter: var(--photo-dim);
  display: block;
}

.card-photo-placeholder {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  background: var(--photo-bg);
}

.card-body { padding: 10px 12px 12px; }

.card-name {
  font-weight: 600;
  font-size: 14px;
  margin: 0 0 6px;
  line-height: 1.3;
}

.card-chips { display: flex; flex-wrap: wrap; gap: 4px; }

.chip {
  font-size: 11px;
  background: var(--chip-bg);
  border: 1px solid var(--chip-line);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--chip-ink);
}

.chip-gold {
  border-color: var(--gold);
  color: var(--gold-ink);
  background: var(--chip-gold-bg);
}

.owned-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--gold);
  color: #fff;
  border-radius: 999px;
  font-size: 12px;
  padding: 3px 8px;
  box-shadow: var(--shadow);
}

.card-photo-wrap { position: relative; }

.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 48px 24px;
}

/* ---------- Bulk selection ---------- */

.card.selected {
  outline: 3px solid var(--brand);
  outline-offset: -3px;
}

.card.selected::after {
  content: "✓";
  position: absolute;
  top: 8px;
  left: 8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card { position: relative; }

.bulk-bar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(60, 50, 90, 0.18);
  padding: 10px 14px;
  font-size: 14px;
  color: var(--ink);
}

.bulk-hint {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0 0 14px;
}

#bulk-form { padding: 20px; overflow-y: auto; max-height: calc(100dvh - 48px); }

#bulk-form h2 { margin: 0 0 6px; font-weight: 700; }

.bulk-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}

.bulk-row > input[type="checkbox"] { margin-top: 26px; }

.bulk-row > label {
  flex: 1;
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
}

.bulk-owned-label { margin-top: 2px; }

.bulk-owned-value { flex: 1; margin: 0 !important; }

/* ---------- FAB ---------- */

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(178, 106, 140, 0.35);
  cursor: pointer;
}

/* ---------- Dialog / form ---------- */

dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 0;
  background: var(--card);
  color: var(--ink);
  overscroll-behavior: contain;
}

/* Scrollable regions inside dialogs must not chain scroll to the page. */
#item-form,
#bulk-form,
.cat-list {
  overscroll-behavior: contain;
}

body:has(dialog[open]) { overflow: hidden; }

dialog::backdrop { background: rgba(46, 42, 59, 0.45); }

#item-form {
  padding: 20px;
  overflow-y: auto;
  max-height: calc(100dvh - 48px);
}

#item-form h2 {
  margin: 0 0 14px;
  font-weight: 700;
}

#item-form label {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 12px;
}

.req { color: var(--accent); }

input[type="text"],
input[type="url"],
input[type="search"],
input[type="password"],
select,
textarea {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  color: var(--ink);
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand-light);
  border-color: transparent;
}

.custom-input { margin-top: 6px; }

.form-type {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--brand);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.check-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-size: 15px !important;
  color: var(--ink) !important;
}

.upload-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
}

.btn-small { padding: 7px 12px; font-size: 14px; }

.cat-dialog-body { padding: 20px; }

.cat-list {
  list-style: none;
  margin: 14px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 50vh;
  overflow-y: auto;
}

.cat-list li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cat-list li span { flex: 1; }

.upload-status { font-size: 13px; color: var(--brand-light); }

.photo-preview {
  width: 100%;
  max-height: 180px;
  object-fit: contain;
  border-radius: 10px;
  margin-bottom: 12px;
  background: var(--bg);
  cursor: zoom-in;
}

/* Full-screen photo viewer */
#photo-lightbox {
  background: transparent;
  box-shadow: none;
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  padding: 0;
}

#photo-lightbox img {
  width: 100vw;
  height: 100dvh;
  object-fit: contain;
  display: block;
  cursor: zoom-out;
}

#photo-lightbox::backdrop { background: rgba(10, 8, 16, 0.88); }

.dialog-buttons {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.spacer { flex: 1; }

.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 15px;
  cursor: pointer;
}

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn-danger {
  background: var(--card);
  border-color: var(--accent);
  color: var(--accent);
}
