:root {
  --gold: #C9A962;
  --gold-light: #E8D5A3;
  --gold-dim: rgba(201, 169, 98, 0.15);
  --bg: #0F0E0C;
  --bg-surface: #1A1814;
  --bg-elevated: #242019;
  --bg-muted: #2A2620;
  --text: #F5F0E8;
  --text-secondary: #A89F8F;
  --text-tertiary: #6B6358;
  --border: rgba(201, 169, 98, 0.2);
  --border-strong: rgba(201, 169, 98, 0.35);
  --success: #7CB87C;
  --danger: #E57373;
  --radius: 14px;
  --radius-lg: 20px;
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-ui: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --sidebar-width: 240px;
  --mobile-nav-height: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
}

body.modal-open {
  overflow: hidden;
  touch-action: none;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(201, 169, 98, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(201, 169, 98, 0.05), transparent);
  pointer-events: none;
  z-index: 0;
}

.hidden { display: none !important; }

/* Lock screen */
.lock-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  z-index: 1;
}

.lock-card {
  max-width: 400px;
  width: 100%;
  background: rgba(26, 24, 20, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 44px 36px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.lock-icon {
  width: 60px;
  height: 60px;
  margin: 0 auto 24px;
  background: var(--gold-dim);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold);
}

.lock-card h1 {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 500;
  letter-spacing: 0.02em;
  margin-bottom: 10px;
  color: var(--text);
}

.lock-card p {
  color: var(--text-secondary);
  margin-bottom: 28px;
  font-size: 14px;
  line-height: 1.6;
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-dim);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-tertiary);
}

.form-textarea {
  resize: vertical;
  min-height: 100px;
}

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23A89F8F' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

/* Date/time inputs — iOS Safari needs 16px+ font and dark color-scheme */
.form-input[type="date"],
.form-input[type="time"],
.form-input[type="datetime-local"] {
  color-scheme: dark;
  min-height: 48px;
  line-height: 1.2;
  -webkit-appearance: none;
  appearance: none;
  display: block;
  min-width: 0;
  max-width: 100%;
}

.form-input[type="date"]::-webkit-date-and-time-value,
.form-input[type="time"]::-webkit-date-and-time-value {
  text-align: left;
  color: var(--text);
}

.form-input[type="date"]::-webkit-calendar-picker-indicator,
.form-input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(0.85) sepia(0.2) saturate(2) hue-rotate(5deg);
  cursor: pointer;
  opacity: 0.85;
  padding: 4px;
}

.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: transform 0.15s, opacity 0.2s, background 0.2s, border-color 0.2s;
}

.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--gold) 0%, #A8863E 100%);
  color: #0F0E0C;
  width: 100%;
  padding: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.btn-primary:hover:not(:disabled) {
  opacity: 0.92;
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--bg-muted);
}

.btn-danger {
  background: rgba(229, 115, 115, 0.15);
  color: var(--danger);
  border: 1px solid rgba(229, 115, 115, 0.3);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(229, 115, 115, 0.25);
}

.btn-success {
  background: rgba(124, 184, 124, 0.15);
  color: var(--success);
  border: 1px solid rgba(124, 184, 124, 0.3);
}

.btn-sm { padding: 8px 14px; font-size: 12px; }

.error-text { color: var(--danger); font-size: 13px; margin-top: 8px; }
.success-text { color: var(--success); font-size: 13px; margin-top: 8px; }

/* Dashboard layout */
.dashboard {
  display: flex;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.sidebar {
  width: var(--sidebar-width);
  background: rgba(26, 24, 20, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-right: 1px solid var(--border);
  padding: 24px 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  padding: 0 24px 28px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.sidebar-brand h2 {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--gold-light);
}

.sidebar-brand span {
  font-size: 12px;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sidebar-nav { flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 13px 24px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  border-left: 3px solid transparent;
}

@media (hover: hover) and (pointer: fine) {
  .nav-item:hover {
    background: var(--gold-dim);
    color: var(--text);
  }
}

.nav-item.active {
  background: var(--gold-dim);
  color: var(--gold-light);
  font-weight: 600;
  border-left-color: var(--gold);
}

.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 28px 32px;
  max-width: 920px;
}

.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 12px;
  flex-wrap: wrap;
}

.main-header h1 {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.save-status {
  font-size: 13px;
  color: var(--text-secondary);
}

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

.card {
  background: rgba(26, 24, 20, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
  transition: border-color 0.2s;
}

.card:hover {
  border-color: rgba(201, 169, 98, 0.3);
}

.card-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 500;
  margin-bottom: 18px;
  color: var(--gold-light);
}

.guest-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  transition: border-color 0.2s;
}

.guest-card:hover {
  border-color: var(--border-strong);
}

.guest-card-info { flex: 1; min-width: 0; }
.guest-card-name { font-weight: 600; margin-bottom: 4px; color: var(--text); }
.guest-card-dates { font-size: 13px; color: var(--text-secondary); }
.guest-card-actions { display: flex; gap: 8px; flex-shrink: 0; }

.guests-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.guests-sort {
  display: flex;
  align-items: center;
  gap: 8px;
}

.guests-sort .form-label {
  margin-bottom: 0;
  white-space: nowrap;
}

.guests-sort .form-select {
  min-width: 220px;
}

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

.upload-row .form-input { flex: 1; }

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

.quick-add {
  background: linear-gradient(135deg, rgba(201, 169, 98, 0.25) 0%, rgba(168, 134, 62, 0.15) 100%);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
}

.quick-add .card-title {
  color: var(--gold-light);
  margin-bottom: 16px;
}

.quick-add .form-label { color: var(--text-secondary); }

.quick-add .form-input {
  background: rgba(15, 14, 12, 0.5);
  border-color: var(--border);
  color: var(--text);
}

.quick-add .form-input::placeholder { color: var(--text-tertiary); }

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

.quick-add-grid .form-group {
  min-width: 0;
}

.quick-add .btn-secondary {
  background: rgba(201, 169, 98, 0.2);
  color: var(--gold-light);
  border-color: var(--border-strong);
}

.quick-add .btn-secondary:hover:not(:disabled) {
  background: rgba(201, 169, 98, 0.3);
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 14, 12, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.modal h3 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 500;
  margin-bottom: 20px;
  color: var(--gold-light);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.modal-actions .btn { flex: 1; }
.modal-actions .btn-primary { width: auto; }

code {
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--gold-light);
}

.mobile-nav {
  display: none;
}

@media (max-width: 768px) {
  /* Lock viewport height; scroll inside .main so bottom nav stays flush (iOS Safari) */
  body:has(#dashboard:not(.hidden)) {
    overflow: hidden;
    height: 100dvh;
    width: 100%;
  }

  .sidebar { display: none; }

  .dashboard {
    flex-direction: column;
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .main {
    margin-left: 0;
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: none;
    padding: 20px 16px;
    padding-bottom: 16px;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .main-header h1 { font-size: 26px; }

  .form-input,
  .form-textarea,
  .form-select {
    font-size: 16px;
  }

  .mobile-nav {
    display: flex;
    flex-shrink: 0;
    position: relative;
    width: 100%;
    background: rgba(26, 24, 20, 0.98);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    z-index: 50;
    min-height: var(--mobile-nav-height);
    padding:
      6px max(8px, env(safe-area-inset-right))
      calc(6px + var(--safe-bottom))
      max(8px, env(safe-area-inset-left));
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
    transition: opacity 0.2s ease, visibility 0.2s ease;
  }

  body.modal-open .mobile-nav {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
  }

  .mobile-nav .nav-item {
    flex: 1;
    flex-direction: column;
    min-height: 52px;
    padding: 6px 4px;
    font-size: 11px;
    gap: 2px;
    justify-content: center;
    align-items: center;
    border-left: none;
    border-top: 3px solid transparent;
    border-radius: 8px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
  }

  .mobile-nav .nav-item:active:not(.active) {
    background: rgba(201, 169, 98, 0.1);
  }

  .mobile-nav .nav-item.active {
    background: var(--gold-dim);
    color: var(--gold-light);
    font-weight: 600;
    border-left: none;
    border-top-color: var(--gold);
  }

  .photo-grid { grid-template-columns: 1fr; }

  .quick-add-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .quick-add {
    padding: 20px 16px;
    overflow: hidden;
  }

  .quick-add .form-input[type="date"] {
    width: 100%;
  }

  .guests-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .guests-sort {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .guests-sort .form-select {
    min-width: 0;
    width: 100%;
  }

  .guest-card {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }

  .guest-card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .guest-card-actions .btn {
    min-height: 44px;
    font-size: 14px;
    padding: 10px 16px;
  }

  .upload-row {
    flex-wrap: wrap;
  }

  .upload-row .btn {
    min-height: 44px;
  }

  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: min(90dvh, 100%);
    padding: 24px 20px calc(24px + var(--safe-bottom));
    -webkit-overflow-scrolling: touch;
  }

  .modal-actions {
    flex-direction: column-reverse;
    gap: 10px;
  }

  .modal-actions .btn {
    min-height: 48px;
    width: 100%;
  }

  .modal-actions .btn-primary {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn:active:not(:disabled) { transform: none; }
}
