@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@600;700;900&family=DM+Sans:wght@300;400;500;600;700&display=swap');

/* ─── CSS Variables ─── */
:root {
  --parchment: #f5ede0;
  --parchment-light: #faf5ee;
  --parchment-dark: #ecdec9;
  --ink: #1a1a2e;
  --ink-soft: #2d2d44;
  --ink-muted: #5a5a72;
  --gold: #c9a84c;
  --gold-light: #e8d5a3;
  --gold-dark: #a07830;
  --green-alive: #16a34a;
  --red-soft: #b91c1c;
  --red-bg: #fff1f2;
  --white-card: #fffcf7;
  --border: #e2d5c3;
  --border-dark: #c9b99a;
  --shadow-sm: 0 2px 8px rgba(26,26,46,0.07);
  --shadow-md: 0 4px 20px rgba(26,26,46,0.12);
  --shadow-lg: 0 12px 40px rgba(26,26,46,0.18);
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 24px;
  --radius-pill: 999px;
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'DM Sans', -apple-system, system-ui, sans-serif;
  --nav-h: 64px;
  --top-h: 56px;
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  background: var(--parchment);
  color: var(--ink);
  min-height: 100vh;
  overscroll-behavior-y: none;
}

/* ─── Top Bar ─── */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--ink);
  height: var(--top-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 10px;
  box-shadow: var(--shadow-md);
}

.brand-pill {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--gold-light);
  line-height: 1;
}

.top-links { display: none; }

/* Updates btn injected by JS */
#updatesBtn {
  font-family: var(--font-body) !important;
  font-size: 12px !important;
  font-weight: 700 !important;
  letter-spacing: 0.04em;
  transition: background 0.2s, color 0.2s;
}

/* ─── Bottom Navigation ─── */
.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--ink);
  height: var(--nav-h);
  display: flex;
  align-items: stretch;
  padding: 0;
  gap: 0;
  border-top: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 -4px 24px rgba(26,26,46,0.25);
}

.tab-button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.4);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
  padding: 8px 4px 10px;
  position: relative;
}

.tab-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 2px;
  background: var(--gold);
  border-radius: 0 0 3px 3px;
  transition: width 0.3s ease;
}

.tab-button.active {
  color: var(--gold-light);
}

.tab-button.active::before {
  width: 32px;
}

/* Tab icons */
.tab-button[data-tab="ceremonies"]::after { content: '⛪'; font-size: 18px; }
.tab-button[data-tab="warehouse"]::after  { content: '📦'; font-size: 18px; }
.tab-button[data-tab="stats"]::after      { content: '📊'; font-size: 18px; }
.tab-button[data-tab="history"]::after    { content: '📋'; font-size: 18px; }

.tab-button[data-tab="ceremonies"]::after,
.tab-button[data-tab="warehouse"]::after,
.tab-button[data-tab="stats"]::after,
.tab-button[data-tab="history"]::after {
  display: block;
  order: -1;
  margin-bottom: 1px;
}

/* New Ceremony FAB */
.new-ceremony {
  position: fixed;
  bottom: calc(var(--nav-h) + 14px);
  right: 16px;
  z-index: 45;
  background: var(--gold);
  color: var(--ink);
  border: none;
  border-radius: var(--radius-pill);
  padding: 13px 20px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(201,168,76,0.45);
  transition: transform 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}

.new-ceremony:active {
  transform: scale(0.96);
  box-shadow: 0 2px 10px rgba(201,168,76,0.3);
}

/* ─── Main Content ─── */
main {
  padding: 12px 12px calc(var(--nav-h) + 80px);
  max-width: 640px;
  margin: 0 auto;
}

.tab { display: none; animation: fadeUp 0.22s ease; }
.tab.active { display: block; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Section headings */
h2 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  margin: 12px 0 10px;
  letter-spacing: 0.01em;
}

h3 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 14px 0 8px;
}

/* ─── Week Divider ─── */
.week-divider {
  margin: 14px 0 8px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--ink) 0%, var(--ink-soft) 100%);
  color: var(--gold-light);
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ─── Ceremony Cards ─── */
.ceremony-card {
  background: var(--white-card);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  border: 1.5px solid var(--border);
  transition: box-shadow 0.2s;
}

.ceremony-card:active { box-shadow: var(--shadow-md); }

.ceremony-card.green-frame {
  border-color: var(--green-alive);
  box-shadow: 0 0 0 3px rgba(22,163,74,0.12), var(--shadow-sm);
}

.ceremony-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 4px;
  gap: 8px;
}

.ceremony-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  line-height: 1.2;
  color: var(--ink);
}

.ceremony-date {
  font-size: 12px;
  color: var(--ink-muted);
  white-space: nowrap;
  background: var(--parchment-dark);
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  font-weight: 500;
  flex-shrink: 0;
}

.ceremony-place {
  font-size: 13px;
  color: var(--ink-muted);
  margin-bottom: 8px;
  font-weight: 500;
}

.ceremony-row {
  font-size: 13px;
  margin-bottom: 3px;
  display: flex;
  gap: 4px;
  line-height: 1.4;
}

.ceremony-label {
  font-weight: 700;
  color: var(--ink-soft);
  flex-shrink: 0;
}

.card-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.card-buttons button {
  border-radius: var(--radius-pill);
  padding: 7px 15px;
  border: none;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.card-buttons button:active { transform: scale(0.95); }

.card-buttons .edit {
  background: var(--ink);
  color: #f9fafb;
}

.card-buttons .delete {
  background: var(--red-bg);
  color: var(--red-soft);
}

/* ─── History Search ─── */
.history-search { margin: 8px 0 12px; }

.history-search input {
  width: 100%;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--border-dark);
  padding: 11px 16px;
  font-size: 14px;
  font-family: var(--font-body);
  background: var(--white-card);
  color: var(--ink);
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
}

.history-search input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201,168,76,0.15);
}

/* ─── Warehouse ─── */
.warehouse-section {
  margin-top: 16px;
  background: var(--white-card);
  border-radius: var(--radius-md);
  padding: 14px;
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.warehouse-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.warehouse-controls button,
.add-option-btn {
  border-radius: var(--radius-pill);
  border: none;
  padding: 8px 16px;
  background: var(--ink);
  color: #f9fafb;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.warehouse-controls button:active,
.add-option-btn:active { transform: scale(0.95); }

.warehouse-hint {
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--parchment-dark);
  border-radius: var(--radius-sm);
}

.warehouse-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.warehouse-table th,
.warehouse-table td {
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.warehouse-table tr:last-child td { border-bottom: none; }

.warehouse-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  text-transform: uppercase;
}

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

.warehouse-actions button {
  border-radius: var(--radius-pill);
  border: none;
  padding: 4px 10px;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.warehouse-actions button:not(.edit):not(.delete) {
  background: var(--parchment-dark);
  color: var(--ink-soft);
}

.warehouse-actions .edit {
  background: var(--ink);
  color: #f9fafb;
}

.warehouse-actions .delete {
  background: var(--red-bg);
  color: var(--red-soft);
}

/* Options Warehouse */
.options-warehouse {
  background: var(--white-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  margin-top: 16px;
}

.options-warehouse > h3 { margin-top: 0; }

.option-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.option-box {
  background: var(--parchment-light);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
}

.option-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.option-head h4 {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
}

.add-option-btn {
  font-size: 11px;
  padding: 5px 10px;
  background: var(--gold);
  color: var(--ink);
}

.compact-table td { font-size: 13px; }

/* Onboarding hint for empty dropdowns */
.onboarding-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  border: 1px solid #fcd34d;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  color: #92400e;
  margin-bottom: 8px;
}

.onboarding-hint span { font-size: 16px; }

/* ─── Stats ─── */
#statsContent { padding: 4px 0; }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  background: var(--white-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.stat-card .stat-value {
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--ink-muted);
  font-weight: 500;
  margin-top: 4px;
}

/* ─── MODAL — Full Screen on Mobile ─── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--parchment-light);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 16px 0;
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -8px 40px rgba(26,26,46,0.3);
  animation: slideUp 0.28s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes slideUp {
  from { transform: translateY(60px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* Drag handle */
.modal-content::before {
  content: '';
  display: block;
  width: 40px;
  height: 4px;
  background: var(--border-dark);
  border-radius: var(--radius-pill);
  margin: 0 auto 16px;
  flex-shrink: 0;
}

.modal-content h2 {
  margin: 0 0 14px;
  font-size: 20px;
  flex-shrink: 0;
}

/* Scrollable form body */
.modal-body {
  overflow-y: auto;
  flex: 1;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}

/* Sticky footer in modal */
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 0 max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--parchment-light);
  position: sticky;
  bottom: 0;
}

.modal-actions button {
  border-radius: var(--radius-pill);
  border: none;
  padding: 12px 24px;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
  flex: 1;
  max-width: 180px;
}

.modal-actions button:active { transform: scale(0.96); }

#cancelModalBtn,
#cancelWarehouseBtn,
#cancelSetBtn {
  background: var(--parchment-dark);
  color: var(--ink-muted);
}

#saveCeremonyBtn,
#saveWarehouseBtn,
#saveSetBtn {
  background: var(--ink);
  color: #f9fafb;
}

/* ─── Wizard Steps ─── */
.wizard-steps {
  display: flex;
  gap: 0;
  margin-bottom: 18px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--parchment-dark);
  padding: 3px;
  gap: 3px;
  flex-shrink: 0;
}

.wizard-step-btn {
  flex: 1;
  padding: 8px 4px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-muted);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  line-height: 1.2;
  text-align: center;
}

.wizard-step-btn.active {
  background: var(--ink);
  color: var(--gold-light);
}

.wizard-step-btn.done {
  background: var(--green-alive);
  color: #fff;
}

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

/* ─── Form Fields ─── */
.form-label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 10px;
}

.form-label input,
.form-label select,
.form-label textarea {
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-dark);
  padding: 10px 12px;
  font-size: 15px;
  font-family: var(--font-body);
  background: var(--white-card);
  color: var(--ink);
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  width: 100%;
}

.form-label input:focus,
.form-label select:focus,
.form-label textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201,168,76,0.18);
}

/* Legacy form selectors from existing code */
#ceremonyForm label,
#warehouseForm label,
#setForm label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 10px;
}

#ceremonyForm input,
#ceremonyForm select,
#ceremonyForm textarea,
#warehouseForm input,
#setForm input,
#setForm select {
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-dark);
  padding: 10px 12px;
  font-size: 15px;
  font-family: var(--font-body);
  background: var(--white-card);
  color: var(--ink);
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  width: 100%;
}

#ceremonyForm input:focus,
#ceremonyForm select:focus,
#ceremonyForm textarea:focus,
#warehouseForm input:focus,
#setForm input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201,168,76,0.18);
}

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

/* ─── Hint / Cremation box ─── */
.hint-box {
  border: 1.5px solid #bbf7d0;
  background: #f0fdf4;
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 10px;
}

.mini-muted {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--ink-muted);
}

/* ─── Grave fields ─── */
.grave-row {
  display: flex;
  gap: 14px;
  align-items: center;
  margin: 6px 0 8px;
}

.grave-option {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.grave-option input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--gold-dark);
}

.grave-fields {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.grave-fields input,
.grave-fields select { flex: 1; }

/* ─── Updates modal ─── */
#updatesModal .modal-content {
  max-height: 80vh;
}

/* ─── Low stock badge ─── */
.low-stock-badge {
  display: inline-block;
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
  border-radius: var(--radius-pill);
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  margin-left: 6px;
}

.out-of-stock-badge {
  display: inline-block;
  background: var(--red-bg);
  color: var(--red-soft);
  border: 1px solid #fecaca;
  border-radius: var(--radius-pill);
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  margin-left: 6px;
}

/* ─── Responsive ─── */
@media (min-width: 640px) {
  .modal {
    align-items: center;
  }

  .modal-content {
    border-radius: var(--radius-lg);
    max-height: 88vh;
    max-width: 540px;
  }

  .modal-content::before { display: none; }
}

@media (max-width: 460px) {
  .option-grid { grid-template-columns: 1fr; }
  .form-grid-2 { grid-template-columns: 1fr; }
  .ceremony-header { flex-direction: column; align-items: flex-start; }
  .ceremony-date { white-space: normal; }
}

/* ─── Scrollbar styling ─── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 3px; }
