:root {
  --bg: #f8f5ef;
  --surface: #ffffff;
  --surface-warm: #fdfaf5;
  --border: #e7dfd3;
  --text: #1f2933;
  --muted: #5c6670;
  --pine: #166534;
  --pine-hover: #14532d;
  --pine-soft: #dcfce7;
  --cranberry: #b91c1c;
  --cranberry-hover: #991b1b;
  --cranberry-soft: #fee2e2;
  --gold: #b45309;
  --gold-soft: #fef3c7;
  --radius: 14px;
  --shadow: 0 4px 18px rgba(31, 41, 51, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.snow-accent {
  height: 5px;
  background: linear-gradient(90deg, var(--pine), var(--cranberry), #ca8a04, var(--pine));
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 0.85rem;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--pine-hover);
}

.btn-secondary {
  background: var(--surface-warm);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: #f1eadf;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: #f3ede4;
  color: var(--text);
}

.btn-claimed {
  background: var(--gold-soft);
  color: #92400e;
  border-color: #fcd34d;
}

.btn-claimed:hover:not(:disabled) {
  background: #fde68a;
}

.btn-danger-outline {
  background: #fff;
  color: var(--cranberry);
  border-color: #fecaca;
}

.btn-danger-outline:hover:not(:disabled) {
  background: var(--cranberry-soft);
}

/* Inputs */
input[type="text"],
input[type="password"],
input[type="datetime-local"],
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d5cab9;
  border-radius: 10px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}

input:focus,
textarea:focus {
  outline: 2px solid rgba(22, 101, 52, 0.25);
  border-color: var(--pine);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label,
.field-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

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

.muted {
  color: var(--muted);
  margin: 0;
  font-size: 0.92rem;
}

.error-text {
  color: var(--cranberry);
  font-size: 0.9rem;
  font-weight: 600;
  margin: 8px 0 0;
}

/* Login View */
.login-wrapper {
  min-height: calc(100vh - 5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.login-card {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

.brand-hero {
  text-align: center;
  margin-bottom: 24px;
}

.brand-icon {
  font-size: 2.8rem;
  line-height: 1;
  margin-bottom: 8px;
}

.brand-hero h1 {
  margin: 0 0 6px;
  font-size: 1.6rem;
  color: var(--pine);
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.user-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.user-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 10px;
  background: var(--surface-warm);
  border: 2px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.user-tile:hover {
  border-color: #b7a994;
}

.user-tile.selected {
  border-color: var(--pine);
  background: #f0fdf4;
  box-shadow: 0 0 0 3px rgba(22, 101, 52, 0.12);
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.avatar-sm {
  width: 30px;
  height: 30px;
  font-size: 0.85rem;
}

.user-tile-name {
  font-weight: 600;
  font-size: 0.95rem;
  text-align: center;
}

.pin-row {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.pin-row input {
  flex: 1;
}

/* App Shell */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-emoji {
  font-size: 1.7rem;
}

.topbar-title {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--pine);
}

.deadline-pill {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  margin-top: 2px;
  background: var(--pine-soft);
  color: var(--pine);
}

.deadline-pill.locked {
  background: var(--cranberry-soft);
  color: var(--cranberry);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.92rem;
}

.nav-tabs {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
}

.nav-tab {
  border: none;
  background: transparent;
  padding: 11px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}

.nav-tab:hover {
  color: var(--text);
}

.nav-tab.active {
  color: var(--pine);
  border-bottom-color: var(--pine);
}

/* Main Content */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 22px 16px 60px;
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 6px;
  font-size: 1.2rem;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 14px;
}

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

.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.form-actions.wrap {
  flex-wrap: wrap;
}

.form-actions.right {
  justify-content: flex-end;
}

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.section-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.spoiler-badge {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--pine);
  background: var(--pine-soft);
  padding: 4px 10px;
  border-radius: 999px;
}

.alert-banner {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 0.92rem;
  font-weight: 600;
}

.alert-success {
  background: var(--pine-soft);
  color: var(--pine);
  border: 1px solid #86efac;
}

.alert-locked {
  background: var(--cranberry-soft);
  color: var(--cranberry);
  border: 1px solid #fecaca;
  margin-top: 0;
}

.locked-card {
  text-align: center;
  padding: 36px 24px;
  background: linear-gradient(180deg, #fffdf9, #fdf4f4);
  border-color: #f3d5d5;
}

.locked-icon {
  font-size: 2.6rem;
  margin-bottom: 8px;
}

.locked-card h2 {
  color: var(--cranberry);
  margin-bottom: 8px;
}

.locked-card p + p {
  margin-top: 8px;
}

/* Items Grid */
.items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow);
}

.item-card.is-claimed-other {
  background: #faf9f7;
  border-style: dashed;
}

.item-card.is-claimed-me {
  border-color: #fcd34d;
  background: #fffdf5;
}

.item-title {
  margin: 0 0 6px;
  font-size: 1.05rem;
  font-weight: 700;
  word-break: break-word;
}

.item-notes {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.item-link {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--pine);
  text-decoration: none;
  word-break: break-all;
}

.item-link:hover {
  text-decoration: underline;
}

.item-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid #f0e9de;
  flex-wrap: wrap;
}

.owner-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  color: #fff;
  margin-bottom: 8px;
}

.status-badge {
  font-size: 0.82rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 8px;
  background: #ece7df;
  color: var(--muted);
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 36px 20px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
}

/* Family Selector Pills */
.family-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.family-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
}

.family-pill.active {
  border-color: var(--pine);
  background: #f0fdf4;
  color: var(--pine);
}

/* Admin */
.deadline-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 14px;
  max-width: 520px;
}

.admin-user-form {
  display: grid;
  grid-template-columns: 1.4fr 1fr auto auto;
  gap: 10px;
  align-items: end;
  margin: 14px 0 18px;
}

.checkbox-field {
  justify-content: center;
  padding-bottom: 8px;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.admin-users-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-warm);
  flex-wrap: wrap;
}

.admin-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-badge {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--gold-soft);
  color: var(--gold);
}

.admin-user-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.modal-card h3 {
  margin: 0 0 8px;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  max-width: 360px;
}

.toast {
  background: #1f2933;
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.toast.toast-success {
  background: var(--pine);
}

.toast.toast-error {
  background: var(--cranberry);
}

@media (max-width: 680px) {
  .form-grid,
  .admin-user-form {
    grid-template-columns: 1fr;
  }

  .pin-row {
    flex-direction: column;
  }

  .login-card {
    padding: 24px 18px;
  }
}
