/* === Variables === */
:root {
  --bg: #0f0f1a;
  --bg-card: #1a1a2e;
  --bg-input: #16213e;
  --accent: #e94560;
  --accent-glow: rgba(233, 69, 96, 0.3);
  --text: #eee;
  --text-subtle: #8888a0;
  --border: #2a2a4a;
  --radius: 12px;
  --radius-sm: 8px;
  --nav-height: 64px;
  --header-height: 52px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

/* === Screens === */
.screen { display: none; height: 100%; }
.screen.active { display: flex; flex-direction: column; }

/* === Login === */
#login-screen, #person-picker {
  justify-content: center;
  align-items: center;
  padding: 24px;
}
.login-container {
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-logo { margin-bottom: 32px; }
.heart-icon {
  font-size: 56px;
  color: var(--accent);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}
.login-logo h1 { font-size: 28px; margin-top: 8px; }
.login-logo p { color: var(--text-subtle); margin-top: 4px; }

#login-form { display: flex; flex-direction: column; gap: 12px; }

input, textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 14px 16px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: none; font-family: inherit; }

.btn {
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #d63850; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: #c0392b; color: #fff; }
.btn-small { padding: 8px 16px; font-size: 13px; width: auto; }

.error-text { color: var(--accent); font-size: 14px; min-height: 20px; }
.subtle-text { color: var(--text-subtle); font-size: 13px; }

/* === Person Picker === */
.person-buttons { display: flex; gap: 12px; justify-content: center; margin-top: 16px; }
.person-btn {
  padding: 16px 32px;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s;
}
.person-btn:hover, .person-btn.active { border-color: var(--accent); background: var(--accent-glow); }
.person-buttons.small .person-btn { padding: 10px 20px; font-size: 14px; }

/* === App Layout === */
#app-screen {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}
.app-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.app-header h1 { font-size: 18px; font-weight: 700; }

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--bg-input); }

/* === Views === */
.view {
  display: none;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.view.active { display: flex; flex-direction: column; }

/* === Gallery === */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 3px;
  padding: 3px;
}
.photo-card {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 4px;
  cursor: pointer;
  background: var(--bg-card);
}
.photo-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
}
.photo-card:hover img { transform: scale(1.05); }
.photo-card .photo-badge {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  backdrop-filter: blur(4px);
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.empty-icon { font-size: 64px; margin-bottom: 16px; opacity: 0.6; }

.sentinel { height: 1px; }
.loading { display: flex; justify-content: center; padding: 20px; }
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner.small { width: 16px; height: 16px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* === Upload === */
.upload-area {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}
.dropzone:hover { border-color: var(--accent); }
.upload-icon { color: var(--text-subtle); margin-bottom: 12px; }
#upload-preview-container { position: relative; width: 100%; }
#upload-preview {
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  border-radius: var(--radius-sm);
}
#clear-preview {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn .btn-loading { display: inline-flex; align-items: center; gap: 8px; }

/* === Calendar === */
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
}
.calendar-header h2 { font-size: 18px; }
.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  padding: 0 8px 8px;
  color: var(--text-subtle);
  font-size: 12px;
  font-weight: 600;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  padding: 0 8px;
}
.cal-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: default;
  position: relative;
}
.cal-day.has-photos {
  background: var(--accent-glow);
  cursor: pointer;
  font-weight: 600;
}
.cal-day.has-photos:hover { background: rgba(233, 69, 96, 0.5); }
.cal-day.today { border: 1px solid var(--accent); }
.cal-day .cal-dot {
  width: 5px;
  height: 5px;
  background: var(--accent);
  border-radius: 50%;
  margin-top: 2px;
}
.cal-day.empty { color: var(--text-subtle); opacity: 0.3; }

.cal-photos {
  padding: 16px;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}
.cal-photos h3 { margin-bottom: 12px; font-size: 16px; }

/* === Lightbox === */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.92);
}
.lightbox-content {
  position: relative;
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.lightbox-close {
  position: absolute;
  top: -40px;
  right: 0;
  background: none;
  border: none;
  color: #fff;
  font-size: 32px;
  cursor: pointer;
  z-index: 1;
}
#lightbox-img {
  max-width: 95vw;
  max-height: 70vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
}
.lightbox-info { text-align: center; }
.lightbox-caption { font-size: 16px; margin-bottom: 4px; }
.lightbox-meta { color: var(--text-subtle); font-size: 13px; }

/* === Bottom Nav === */
.bottom-nav {
  height: var(--nav-height);
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-subtle);
  font-size: 11px;
  cursor: pointer;
  transition: color 0.2s;
  padding: 8px;
}
.nav-btn.active { color: var(--accent); }
.nav-btn svg { stroke: currentColor; }

/* === Modal === */
.modal {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
}
.modal-content {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-content h2 { font-size: 20px; }
.setting-item { display: flex; flex-direction: column; gap: 8px; }
.setting-item label { font-weight: 600; font-size: 14px; }
.modal-content hr { border: none; border-top: 1px solid var(--border); }

/* === Toast === */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  color: var(--text);
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  border: 1px solid var(--border);
  z-index: 2000;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* === Responsive === */
@media (min-width: 768px) {
  .photo-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 6px;
    padding: 6px;
  }
}
