:root {
  color-scheme: light;
  --bg: #f8f4ff;
  --card: #ffffff;
  --text: #1f2937;
  --text-on-dark: #5b21b6;
  --muted: #6b7280;
  --muted-on-dark: #a78bfa;
  --primary: #7c3aed;
  --primary-strong: #6d28d9;
  --primary-light: #ede9fe;
  --primary-lighter: #f5f3ff;
  --danger: #ef4444;
  --border: #ede9fe;
  --accent: #f59e0b;
  --heading: #5b21b6;
}

* {
  box-sizing: border-box;
}

html {
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  font-family: 'Baloo 2', cursive;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.container {
  width: min(1100px, 92%);
  margin: 0 auto;
}

.main-content {
  padding: 1rem 0 2rem;
  flex: 1;
}

.footer {
  border-top: 2px solid var(--border);
  padding: 1rem 0;
  margin-top: auto;
  font-size: 0.85rem;
  color: var(--muted);
}
.footer-link {
  color: var(--muted);
  text-decoration: none;
}
.footer-link:hover {
  text-decoration: underline;
  color: var(--primary);
}

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fff;
  border-bottom: 2px solid var(--border);
  padding: 0.75rem 0;
}

.brand {
  color: var(--heading);
  text-decoration: none;
  font-weight: 800;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.brand-logo {
  height: 2rem;
  width: auto;
}

h1, h2, h3, p {
  margin: 0;
}

h1 {
  font-size: 1.5rem;
  color: var(--heading);
  font-weight: 800;
}

h2 {
  font-size: 1.2rem;
  color: var(--heading);
  font-weight: 800;
}

h3 {
  color: var(--heading);
  font-weight: 800;
}

.card {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 1.25rem;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
}

.stack {
  display: grid;
  gap: 0.75rem;
  min-width: 0;
}

.stack-sm {
  display: grid;
  gap: 0.25rem;
}

.row {
  display: flex;
}

.between {
  justify-content: space-between;
}

.center {
  align-items: center;
}

.wrap {
  flex-wrap: wrap;
}

.gap-sm {
  gap: 0.5rem;
}

.add-floor-form {
  align-items: center;
}

.add-floor-form input {
  flex: 0 1 280px;
  min-width: 180px;
}

.add-room-inline-form {
  align-items: center;
}

.add-room-inline-form input[type="text"] {
  flex: 0 1 280px;
  min-width: 180px;
}

.grid {
  display: grid;
  gap: 0.75rem;
}

.cols-2 {
  grid-template-columns: 1fr;
}

.cols-3 {
  grid-template-columns: 1fr;
}

input {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 11px;
  padding: 0.65rem 0.7rem;
  font-size: 0.95rem;
  font-family: 'Baloo 2', cursive;
}

input:focus {
  outline: none;
  border-color: var(--primary);
}

select {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 11px;
  padding: 0.65rem 0.7rem;
  font-size: 0.95rem;
  background: #fff;
  font-family: 'Baloo 2', cursive;
}

select:focus {
  outline: none;
  border-color: var(--primary);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 11px;
  padding: 7px 16px;
  height: 2.3rem;
  min-width: 7rem;
  width: fit-content;
  max-width: 100%;
  white-space: nowrap;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-family: 'Baloo 2', cursive;
  cursor: pointer;
  font-size: 0.9rem;
}

.button:hover {
  background: var(--primary-strong);
}

.button-light {
  background: var(--primary-light);
  color: var(--primary);
}

.button-light:hover {
  background: #ddd6fe;
}

/* ── Nav-specific buttons ────────────────────────── */
.nav-btn-primary {
  background: var(--primary);
  color: #fff;
  border-radius: 11px;
  padding: 7px 16px;
  font-weight: 700;
}

.nav-btn-outline {
  background: #fff;
  color: var(--primary);
  border: 2px solid var(--border);
  border-radius: 11px;
  padding: 5px 14px;
  font-weight: 700;
}
.nav-btn-outline:hover {
  background: var(--primary-light);
}

.nav-btn-icon {
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 9px;
  width: 33px;
  height: 33px;
  min-width: 33px;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  overflow: visible;
}
.nav-btn-icon:hover {
  background: #ddd6fe;
}

.button-icon {
  min-width: auto;
  padding: 0 0.5rem;
  line-height: 1;
  overflow: visible;
}

.button-danger {
  background: var(--danger);
}

.button-xs {
  padding: 0.35rem 0.55rem;
  font-size: 0.78rem;
}

.button-delete {
  width: 21px;
  min-width: 21px;
  max-width: 21px;
  height: 21px;
  min-height: 21px;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid #fca5a5;
  background: #fee2e2;
  color: #ef4444;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1;
  align-self: center;
  box-sizing: border-box;
}

.button.button-delete:hover {
  background: #fecaca;
}

.button.button-danger.button-delete {
  background: #fee2e2;
  color: #ef4444;
}

form:has(.button-delete) {
  display: inline-flex;
  align-items: center;
}

.pill {
  font-size: 0.82rem;
  padding: 0.2rem 0.6rem;
  background: var(--primary-light);
  border-radius: 999px;
  color: var(--primary);
  font-weight: 700;
}

.muted {
  color: var(--muted);
}

.card .muted {
  color: var(--muted);
}

.flash-wrap {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.flash {
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
  font-weight: 600;
}

.flash-success {
  background: #dcfce7;
  color: #14532d;
}

.flash-error {
  background: #fee2e2;
  color: #7f1d1d;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.stat {
  border-radius: 15px;
  padding: 18px;
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 2px;
}

.stat-emoji {
  font-size: 1.4rem;
  line-height: 1;
}

.stat strong {
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1.2;
}

.stat .stat-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-rooms {
  background: #fef3c7;
  border: 2px solid #fde68a;
}
.stat-rooms strong { color: #92400e; }
.stat-rooms .stat-label { color: #d97706; }

.stat-boxes {
  background: #dbeafe;
  border: 2px solid #bfdbfe;
}
.stat-boxes strong { color: #1e40af; }
.stat-boxes .stat-label { color: #3b82f6; }

.stat-items {
  background: #d1fae5;
  border: 2px solid #a7f3d0;
}
.stat-items strong { color: #065f46; }
.stat-items .stat-label { color: #10b981; }

.qr-wrap {
  justify-items: center;
}

.qr-image {
  width: 150px;
  height: 150px;
  border: 2px solid var(--border);
  border-radius: 12px;
}

.count-input {
  width: 80px;
}

.section-space {
  margin-bottom: 1rem;
}

.add-floor-toggle {
  display: grid;
  gap: 0.5rem;
}

.add-room-toggle {
  display: grid;
  gap: 0.5rem;
}

.add-box-toggle-wrap {
  display: grid;
  gap: 0.5rem;
}

.add-box-toggle-link {
  text-decoration: none;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--primary);
}

.add-box-toggle-link:hover {
  color: var(--primary-strong);
}

.add-room-link {
  text-decoration: none;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--primary);
}

.add-room-link:hover {
  color: var(--primary-strong);
}

.cancel-link {
  color: var(--danger) !important;
}

.add-floor-link {
  text-decoration: none;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--primary);
}

.add-floor-link:hover {
  color: var(--primary-strong);
}

.floors-board {
  gap: 12px;
}

.floor-card {
  cursor: grab;
  border-radius: 16px;
  border: 2px solid var(--border);
  overflow: hidden;
  padding: 0;
}

.floor-card > .row.between {
  background: linear-gradient(135deg, #ede9fe, #f5f3ff);
  border-bottom: 2px solid var(--border);
  padding: 14px 18px;
}

.floor-card > .row.between h3 {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--heading);
}

.floor-card > .row.between .pill {
  background: var(--primary);
  color: #fff;
  border-radius: 20px;
  padding: 3px 11px;
  font-size: 0.68rem;
  font-weight: 800;
}

.floor-meta {
  padding: 0;
  font-size: 0.71rem !important;
  color: var(--heading) !important;
  font-weight: 700;
  margin: 2px 0 0 0;
  opacity: 0.7;
}

/* ── Room emoji in home list ── */
.room-row-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.room-emoji-btn {
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
  background: none;
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 2px 4px;
  transition: border-color 0.15s, background 0.15s;
  flex-shrink: 0;
  position: relative;
}

.room-emoji-btn:hover {
  border-color: var(--primary-light);
  background: var(--primary-light);
}

.room-text-stack {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.room-text-stack .room-link {
  flex: unset;
}

.room-text-stack small {
  font-size: 0.73rem;
  color: #a78bfa;
  font-weight: 700;
}

/* ── Emoji picker popup ── */
.emoji-picker-popup {
  display: none;
  position: fixed;
  z-index: 900;
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.13);
  width: 220px;
  flex-wrap: wrap;
  gap: 6px;
}

.emoji-picker-popup.open {
  display: flex;
}

.emoji-picker-popup button {
  font-size: 1.4rem;
  background: none;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
  transition: background 0.12s, border-color 0.12s;
}

.emoji-picker-popup button:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}

.floor-card.dragging {
  opacity: 0.5;
}

/* ── Browse list (all-boxes / all-items pages) ── */
.browse-list {
  padding: 0 !important;
  gap: 0 !important;
}

.browse-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  text-decoration: none;
  color: inherit;
  border-bottom: 1.5px dashed var(--border);
  transition: background 0.12s;
}

.browse-row:last-child {
  border-bottom: none;
}

.browse-row:hover {
  background: var(--primary-light);
}

.browse-row-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.browse-emoji {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.browse-text-stack {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.browse-text-stack strong {
  color: var(--heading);
  font-weight: 700;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.browse-text-stack small {
  font-size: 0.73rem;
  color: #a78bfa;
  font-weight: 600;
}

.browse-row-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.pill-outline {
  background: transparent !important;
  color: var(--primary) !important;
  border: 1.5px solid var(--primary) !important;
}

a.stat {
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}

a.stat:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.15);
}

/* ── Demo page ── */
.demo-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  background: linear-gradient(135deg, #ede9fe, #f5f3ff);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 12px 20px;
  margin-bottom: 1rem;
  font-weight: 700;
  color: var(--heading);
  font-size: 0.88rem;
}

.demo-banner .button-sm {
  padding: 5px 14px;
  font-size: 0.78rem;
  border-radius: 10px;
}

.demo-emoji {
  cursor: default !important;
}

.demo-link {
  cursor: default;
}

.demo-box-peek {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  max-width: 260px;
}

.demo-box-label {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--heading);
  white-space: nowrap;
}

.demo-box-items {
  font-size: 0.66rem;
  color: #a78bfa;
  font-weight: 600;
  text-align: right;
  line-height: 1.3;
}

.room-list {
  padding: 0;
}

.room-row {
  padding: 11px 18px;
  cursor: grab;
  flex-wrap: nowrap;
  min-width: 0;
  border-bottom: 1.5px dashed var(--border);
}

.room-row:last-of-type {
  border-bottom: none;
}

.room-row.dragging-room {
  opacity: 0.55;
}

.room-link {
  color: var(--heading);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.87rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-link:hover {
  text-decoration: underline;
  color: var(--primary);
}

.room-actions small {
  font-size: 0.73rem;
  color: #a78bfa;
  font-weight: 700;
}

.room-edit-wrap {
  flex: 1;
  min-width: 230px;
}

.room-edit-form input,
.room-edit-form select {
  min-width: 140px;
}

.room-actions {
  justify-content: flex-end;
  flex-shrink: 0;
  white-space: nowrap;
}

.room-menu-actions {
  align-items: center;
  margin-top: 0.35rem;
}

.room-header-card {
  padding: 1.6rem;
}

.room-box-card {
  padding: 1.25rem;
}

.box-name-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 700;
}

.box-name-link:hover {
  text-decoration: underline;
  color: var(--primary-strong);
}

.room-box-card .stack-sm {
  gap: 0.6rem;
}

.room-section-card {
  padding: 1.5rem;
}

.room-boxes-grid {
  gap: 1rem;
}

.room-page-stack {
  gap: 1rem;
}

.box-page-stack {
  gap: 1rem;
}

.item-edit-wrap {
  flex: 1;
  min-width: 280px;
}

.hidden {
  display: none !important;
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1200;
}

.confirm-overlay.hidden {
  display: none;
}

.confirm-modal {
  width: min(420px, 100%);
  display: grid;
  gap: 0.85rem;
  border-radius: 18px;
}

@media (min-width: 760px) {
  .main-content {
    padding-top: 1.25rem;
  }

  .cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cols-3 {
    grid-template-columns: 2fr 0.7fr 1.5fr;
  }
}

@media (max-width: 759px) {
  .header {
    padding: 0.5rem 0;
  }

  .header .row.between {
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .header nav {
    gap: 0.3rem;
  }

  .header nav .button {
    min-width: 0;
    padding: 0 0.55rem;
    height: 1.85rem;
    font-size: 0.82rem;
    border-radius: 9px;
  }

  .header nav .nav-btn-icon {
    width: 28px;
    height: 28px;
    min-width: 28px;
    padding: 0;
  }

  .brand {
    font-size: 0.95rem;
  }

  .brand-logo {
    height: 1.6rem;
  }
}

/* ── Profile button ─────────────────────────────────── */
.profile-btn {
  gap: 0.35rem;
}

.profile-btn svg {
  flex-shrink: 0;
}

/* ── Profile page ──────────────────────────────────── */
.profile-section {
  max-width: 480px;
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.profile-avatar {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  flex-shrink: 0;
}

.profile-info {
  min-width: 0;
}

.profile-info .muted {
  font-size: 0.9rem;
}

.profile-form .stack {
  gap: 0.6rem;
}

.profile-form label {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: -0.25rem;
}

.profile-form input {
  width: 100%;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.5rem 0;
}

/* ── Floor card overflow fix on mobile ─────────────── */
.floor-card {
  overflow: hidden;
  min-width: 0;
}

.floor-card input[type="text"] {
  min-width: 0;
}

.floor-card .add-room-inline-form {
  padding: 0 18px 10px;
}

/* ── Photo styles ──────────────────────────────────── */
.box-photo {
  width: 100%;
  max-width: 320px;
  border-radius: 12px;
  border: 2px solid var(--border);
  object-fit: cover;
}

.item-thumb {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  border: 2px solid var(--border);
  object-fit: cover;
  flex-shrink: 0;
}

.item-card {
  padding: 0.85rem 1rem;
}

.photo-label {
  cursor: pointer;
  min-width: auto;
  font-size: 0.88rem;
}

.photo-filename {
  font-size: 0.82rem;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo-preview-wrap {
  display: grid;
  gap: 0.5rem;
}

.photo-preview {
  max-width: 240px;
  max-height: 200px;
  border-radius: 12px;
  object-fit: cover;
}

/* ── Household / member styles ─────────────────────── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.badge-owner {
  background: var(--primary-light);
  color: var(--primary);
}
.badge-member {
  background: #f5f3ff;
  color: #8b5cf6;
}

.member-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.member-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
}
.member-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.member-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.member-name {
  font-weight: 600;
  font-size: 0.95rem;
}
.member-email {
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.button-small {
  padding: 0.25rem 0.7rem;
  font-size: 0.8rem;
}
.button-outline {
  background: transparent;
  border: 1.5px solid var(--primary);
  color: var(--primary);
}
.button-outline:hover {
  background: var(--primary);
  color: #fff;
}
.inline-form {
  display: inline;
}

/* ── Admin panel styles ────────────────────────────── */
.admin-btn {
  padding: 0.4rem 0.55rem !important;
  min-width: auto !important;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.admin-table th,
.admin-table td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table th {
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.admin-table tr:last-child td {
  border-bottom: none;
}
.admin-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.admin-stat {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  margin-right: 0.25rem;
}
.admin-map {
  width: 100%;
  height: 200px;
  border: none;
  border-radius: 12px;
  margin-top: 0.5rem;
}
.ip-cell {
  font-family: monospace;
  font-size: 0.82rem;
}

/* ── About / What is organizr accordion ────────────── */
.about-accordion {
  border: none;
}
.about-toggle {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1rem;
  border-radius: 12px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.95rem;
  font-weight: 700;
  transition: background 0.2s;
}
.about-toggle:hover {
  background: #ddd6fe;
}
.about-toggle::-webkit-details-marker {
  display: none;
}
.about-toggle::after {
  content: "▸";
  font-size: 0.8rem;
  transition: transform 0.2s;
  margin-left: 0.3rem;
}
details[open] > .about-toggle::after {
  transform: rotate(90deg);
}
.about-body {
  margin-top: 0.75rem;
  animation: aboutFade 0.3s ease;
}
.about-body p {
  line-height: 1.7;
  margin: 0 0 0.8rem;
}
.about-body p:last-child {
  margin-bottom: 0;
}
.text-primary {
  color: var(--primary);
}
.text-accent {
  color: var(--accent);
  font-weight: 600;
}
@keyframes aboutFade {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Section subtitle ─────────────────────────────── */
.section-subtitle {
  font-size: 0.73rem;
  font-weight: 600;
  color: #a78bfa;
}

/* ── Floor card inner padding ─────────────────────── */
.floor-card .room-list {
  border-top: none;
}

.floor-card .add-room-toggle {
  padding: 10px 18px;
}

.floor-card .empty-floor-message {
  padding: 0 18px;
}

.floor-card .stack {
  gap: 0.5rem;
}
