/* Memory — Family History App
   Palette: white primary, #CDB190 (warm), #4C066C (deep purple) */

:root {
  --white: #ffffff;
  --warm: #CDB190;
  --warm-light: #E8DCC8;
  --warm-soft: #F6EFE3;
  --purple: #4C066C;
  --purple-light: #7A2DA1;
  --purple-soft: #F3EAF7;
  --ink: #2A2030;
  --ink-soft: #5A4F62;
  --muted: #8B8294;
  --line: #EBE5EE;
  --shadow: 0 2px 8px rgba(76, 6, 108, 0.06);
  --shadow-md: 0 6px 24px rgba(76, 6, 108, 0.10);
  --radius: 10px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--white);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 600;
  color: var(--purple);
  margin: 0 0 0.5em;
}

h1 { font-size: 2.2rem; letter-spacing: -0.01em; }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.2rem; }

a { color: var(--purple); text-decoration: none; }
a:hover { text-decoration: underline; }

button, .btn {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--ink);
  cursor: pointer;
  transition: all 0.15s ease;
}
button:hover, .btn:hover { border-color: var(--purple); color: var(--purple); }

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

.btn-warm {
  background: var(--warm);
  color: var(--white);
  border-color: var(--warm);
}
.btn-warm:hover { background: #B89878; border-color: #B89878; color: var(--white); }

.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--warm-soft); }

.btn-small { padding: 0.4rem 0.8rem; font-size: 0.85rem; }

input, textarea, select {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink);
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 3px var(--purple-soft);
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-soft);
  margin-bottom: 0.35rem;
}

/* ========== Login Page ========== */
.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.auth-hero {
  background: linear-gradient(135deg, var(--purple) 0%, #2C0440 100%);
  color: var(--white);
  padding: 4rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.auth-hero::before {
  content: '';
  position: absolute;
  top: -50%; right: -30%;
  width: 80%; height: 200%;
  background: radial-gradient(circle, rgba(205, 177, 144, 0.15) 0%, transparent 60%);
}
.auth-hero h1 {
  color: var(--white);
  font-size: 3rem;
  position: relative;
}
.auth-hero p { color: var(--warm-light); font-size: 1.05rem; max-width: 420px; position: relative; }
.auth-hero .brand {
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  margin-bottom: 3rem;
  letter-spacing: 0.02em;
  position: relative;
}
.auth-hero .brand-mark { color: var(--warm); }

.auth-form-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
}
.auth-form { width: 100%; max-width: 380px; }
.auth-form h2 { font-size: 1.8rem; }
.auth-form .field { margin-bottom: 1rem; }
.auth-form button[type="submit"] {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.8rem;
  font-size: 1rem;
}
.auth-toggle { text-align: center; margin-top: 1.5rem; font-size: 0.9rem; color: var(--ink-soft); }
.auth-toggle a { font-weight: 500; cursor: pointer; }
.auth-error {
  background: #FFF0F0;
  color: #B82A2A;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

@media (max-width: 800px) {
  .auth-page { grid-template-columns: 1fr; }
  .auth-hero { padding: 2.5rem; min-height: 240px; }
  .auth-hero h1 { font-size: 2rem; }
}

/* ========== App Shell ========== */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--warm-soft);
  border-right: 1px solid var(--line);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
}
.sidebar .brand {
  font-family: 'Playfair Display', serif;
  font-size: 1.4rem;
  color: var(--purple);
  margin-bottom: 0.25rem;
  padding: 0 0.75rem;
}
.sidebar .brand-mark { color: var(--warm); }
.sidebar .tagline {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0 0.75rem;
  margin-bottom: 2rem;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  color: var(--ink-soft);
  font-size: 0.95rem;
  cursor: pointer;
  margin-bottom: 0.15rem;
  transition: all 0.15s ease;
}
.nav-item:hover { background: var(--white); color: var(--purple); text-decoration: none; }
.nav-item.active { background: var(--purple); color: var(--white); }
.nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-section {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  padding: 0 0.75rem;
  margin: 1.25rem 0 0.5rem;
}
.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
}
.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--purple);
  color: var(--white);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.avatar.warm { background: var(--warm); }
.user-chip .meta { font-size: 0.85rem; line-height: 1.2; }
.user-chip .meta .name { font-weight: 600; color: var(--ink); }
.user-chip .meta .rel { color: var(--muted); font-size: 0.75rem; }

.main {
  padding: 2rem 2.5rem;
  max-width: 1200px;
  width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}
.topbar .search-wrap {
  flex: 1;
  position: relative;
  max-width: 480px;
}
.topbar .search-wrap input {
  padding-left: 2.5rem;
  background: var(--warm-soft);
  border-color: transparent;
}
.topbar .search-wrap input:focus { background: var(--white); }
.topbar .search-wrap .search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.topbar .person-select {
  max-width: 240px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  gap: 1rem;
}
.page-header .subtitle { color: var(--ink-soft); font-size: 0.95rem; }

/* ========== Dashboard ========== */
.dash-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}
.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.card-accent {
  background: linear-gradient(135deg, var(--warm-soft) 0%, var(--white) 100%);
  border-color: var(--warm-light);
}
.card-purple {
  background: linear-gradient(135deg, var(--purple) 0%, #2C0440 100%);
  color: var(--white);
  border-color: var(--purple);
}
.card-purple h2, .card-purple h3 { color: var(--white); }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.card-header .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--warm);
  font-weight: 600;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
}
.stat .num {
  font-family: 'Playfair Display', serif;
  font-size: 1.8rem;
  color: var(--purple);
  font-weight: 600;
}
.stat .lbl {
  font-size: 0.8rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ========== Memory Cards ========== */
.memory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}
.memory-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
}
.memory-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--warm);
}
.memory-card .media {
  height: 180px;
  background: var(--warm-soft);
  position: relative;
  overflow: hidden;
}
.memory-card .media img,
.memory-card .media video {
  width: 100%; height: 100%; object-fit: cover;
}
.memory-card .media-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--warm);
  font-size: 2rem;
  background: linear-gradient(135deg, var(--warm-soft), var(--warm-light));
}
.memory-card .media-type-badge {
  position: absolute;
  top: 0.6rem; left: 0.6rem;
  background: rgba(255,255,255,0.95);
  color: var(--purple);
  padding: 0.2rem 0.55rem;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.memory-card .star-btn {
  position: absolute;
  top: 0.6rem; right: 0.6rem;
  background: rgba(255,255,255,0.95);
  border: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--muted);
  font-size: 1.1rem;
  padding: 0;
}
.memory-card .star-btn.starred { color: var(--warm); }
.memory-card .star-btn:hover { color: var(--warm); }

.memory-card .body { padding: 1rem 1.1rem; flex: 1; display: flex; flex-direction: column; }
.memory-card h3 {
  font-size: 1.05rem;
  margin: 0 0 0.3rem;
  color: var(--ink);
  font-family: 'Playfair Display', serif;
}
.memory-card .date { font-size: 0.8rem; color: var(--purple); font-weight: 500; }
.memory-card .desc {
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin-top: 0.5rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.memory-card .footer {
  margin-top: auto;
  padding-top: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--muted);
}
.tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.6rem; }
.tag {
  background: var(--warm-soft);
  color: var(--purple);
  padding: 0.15rem 0.55rem;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 500;
}

/* ========== Timeline ========== */
.timeline {
  position: relative;
  padding-left: 40px;
  margin-top: 1rem;
}
.timeline::before {
  content: '';
  position: absolute;
  left: 14px; top: 0; bottom: 0;
  width: 2px;
  background: linear-gradient(to bottom, var(--warm) 0%, var(--purple) 100%);
}
.timeline-year {
  position: relative;
  margin-bottom: 2.5rem;
}
.timeline-year .year-marker {
  position: absolute;
  left: -40px;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--white);
  border: 3px solid var(--purple);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--purple);
}
.timeline-year .year-label {
  font-family: 'Playfair Display', serif;
  font-size: 1.4rem;
  color: var(--purple);
  margin-bottom: 0.25rem;
}
.timeline-year .age-label {
  font-size: 0.85rem;
  color: var(--warm);
  font-weight: 600;
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.timeline-year .historical-context {
  background: var(--purple-soft);
  border-left: 3px solid var(--purple);
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
}
.timeline-year .historical-context strong { color: var(--purple); }

/* Historical context facts (timeline + memory detail + admin manager) */
.hc-fact {
  position: relative;
  padding-right: 28px;
  margin-bottom: 0.6rem;
}
.hc-fact:last-child { margin-bottom: 0; }
.hc-fact .hc-body { line-height: 1.55; }
.hc-fact .hc-delete {
  position: absolute;
  top: -2px;
  right: 0;
  width: 22px; height: 22px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 50%;
  color: var(--muted);
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
.hc-fact .hc-delete:hover {
  color: #B82A2A;
  border-color: #FFD0D0;
  background: #FFF0F0;
}
.hc-year-block { margin-bottom: 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
.hc-year-block:last-child { border-bottom: none; }
.hc-year-heading {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.3rem;
  color: var(--purple);
  margin-bottom: 0.75rem;
}
.hc-admin-row {
  background: var(--warm-soft);
  padding: 0.75rem 2.5rem 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--ink);
  margin-bottom: 0.5rem;
}
.hc-admin-row .hc-delete {
  top: 0.6rem;
  right: 0.6rem;
}
.timeline-memories { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }

/* ========== Memory Detail ========== */
.detail {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 2rem;
}
.detail-main {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.detail-media {
  background: var(--warm-soft);
  min-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.detail-media img, .detail-media video {
  max-width: 100%; max-height: 500px; object-fit: contain;
}
.detail-media audio { width: 90%; }
.detail-media .doc-icon {
  font-size: 4rem; color: var(--warm);
}
.detail-body { padding: 2rem; }
.detail-body h1 { margin-bottom: 0.25rem; }
.detail-body .meta-row {
  display: flex; flex-wrap: wrap; gap: 1rem;
  font-size: 0.9rem; color: var(--ink-soft);
  margin-bottom: 1.5rem;
}
.detail-body .meta-row .meta-item { display: flex; align-items: center; gap: 0.4rem; }
.detail-body p.description { font-size: 1rem; color: var(--ink); white-space: pre-wrap; }

.detail-side { display: flex; flex-direction: column; gap: 1.25rem; }

.comments-section h3 { margin-bottom: 1rem; }
.comment {
  background: var(--warm-soft);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-bottom: 0.75rem;
}
.comment .head {
  display: flex; align-items: center; gap: 0.5rem;
  margin-bottom: 0.4rem;
}
.comment .head .name { font-weight: 600; font-size: 0.85rem; color: var(--ink); }
.comment .head .when { font-size: 0.75rem; color: var(--muted); }
.comment .body { font-size: 0.9rem; color: var(--ink); }
.comment-form { margin-top: 1rem; }
.comment-form textarea { min-height: 70px; resize: vertical; }
.comment-form button { margin-top: 0.5rem; }

/* ========== Add Memory Form ========== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.form-grid .full { grid-column: 1 / -1; }
.field { margin-bottom: 1rem; }
.field-help { font-size: 0.78rem; color: var(--muted); margin-top: 0.3rem; }
textarea { min-height: 100px; resize: vertical; }

.date-picker { display: grid; grid-template-columns: auto 1fr; gap: 0.5rem; align-items: start; }
.date-picker .precision { display: flex; flex-direction: column; gap: 0.3rem; }
.date-picker .precision label {
  display: flex; align-items: center; gap: 0.4rem;
  font-weight: normal;
  font-size: 0.85rem;
  margin-bottom: 0;
  cursor: pointer;
}
.date-inputs { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.date-inputs input { width: auto; flex: 1; min-width: 80px; }

.media-drop {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--warm-soft);
}
.media-drop:hover { border-color: var(--purple); background: var(--purple-soft); }
.media-drop input { display: none; }
.media-drop .icon { font-size: 2rem; color: var(--warm); margin-bottom: 0.5rem; }
.media-drop p { margin: 0; color: var(--ink-soft); font-size: 0.9rem; }
.media-preview {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: space-between;
}

/* ========== Modal ========== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(42, 32, 48, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 2rem;
}
.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-header {
  padding: 1.5rem 1.5rem 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.modal-header h2 { margin: 0; }
.modal-body { padding: 1rem 1.5rem 1.5rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }
.close-btn { background: transparent; border: none; font-size: 1.4rem; cursor: pointer; color: var(--muted); padding: 0; line-height: 1; }
.close-btn:hover { color: var(--purple); border: none; }

/* ========== Empty States ========== */
.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}
.empty .icon { font-size: 3rem; color: var(--warm); margin-bottom: 0.75rem; }
.empty h3 { color: var(--ink); }

/* ========== Misc ========== */
.divider { height: 1px; background: var(--line); margin: 1.5rem 0; }
.flex-row { display: flex; align-items: center; gap: 0.75rem; }
.flex-row.between { justify-content: space-between; }
.text-muted { color: var(--muted); }
.text-warm { color: var(--warm); }
.text-purple { color: var(--purple); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.hidden { display: none !important; }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--warm-soft); }
::-webkit-scrollbar-thumb { background: var(--warm); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--purple); }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 1.25rem; }
  .dash-grid { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .detail { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
