/* HelloFamily — family test build.
 * Visual language aligned with the approved onboarding mock:
 * DM Sans + Newsreader, green/rust token palette, warm paper background.
 */

:root {
  --page: #f4f6f1;
  --paper: #ffffff;
  --ink: #18221d;
  --ink-soft: #5b675f;
  --line: #d8ded8;
  --soft: #e9eee8;
  --field: #fbfcfa;
  --green: #225e43;
  --green-2: #174631;
  --green-soft: #dcebe2;
  --rust: #a44f35;
  --rust-soft: #f2dfd8;
  --gold: #d9a441;
  --accent: #174631;
  --accent-dark: #225e43;
  --leaf: #225e43;
  --danger: #a44f35;
  --radius: 14px;
  --shadow: 0 18px 54px rgba(25, 43, 33, 0.10);
  --font-head: "Newsreader", Georgia, "Times New Roman", serif;
  --font-body: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--page);
  background-image: radial-gradient(1200px 600px at 85% -10%, var(--green-soft) 0%, transparent 60%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Auth page ---------- */
.auth-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 22px 12px 22px 12px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  text-align: center;
}
.brand { margin-bottom: 18px; }
.brand-mark {
  width: 64px; height: 64px; margin: 0 auto 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--green) 0%, #75a447 52%, #e1bd35 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; color: #fff;
  box-shadow: var(--shadow);
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.brand h1 {
  font-family: var(--font-head);
  font-size: 32px; margin: 0 0 4px;
  letter-spacing: 0.5px; font-weight: 600;
}
.brand p { margin: 0; color: var(--ink-soft); font-size: 14px; }
.auth-card h2 { font-family: var(--font-head); font-size: 21px; margin: 6px 0 16px; font-weight: 600; }

.field { text-align: left; margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--ink-soft); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 12px;
  font-size: 16px; /* prevents iOS zoom */
  font-family: var(--font-body);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(34, 94, 67, 0.15);
}
.field textarea { resize: vertical; min-height: 70px; }
.field .hint { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }

.btn {
  display: inline-block;
  border: none; cursor: pointer;
  font-family: var(--font-body); font-size: 15px; font-weight: 700;
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--green-2); color: #fff;
  transition: transform 0.08s ease, background 0.15s ease;
  text-decoration: none;
}
.btn:hover { background: var(--green); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: wait; }
.btn.block { width: 100%; }
.btn.secondary { background: var(--soft); color: var(--ink); }
.btn.secondary:hover { background: #dde6dd; }
.btn.ghost { background: transparent; color: var(--green-2); padding: 8px 12px; }
.btn.danger { background: var(--rust); }
.btn.small { padding: 8px 14px; font-size: 13px; }

.auth-switch { margin-top: 16px; font-size: 14px; color: var(--ink-soft); }
.auth-switch button {
  background: none; border: none; cursor: pointer;
  color: var(--green-2); font-weight: 700; font-size: 14px; padding: 0;
}
.form-error {
  display: none;
  background: var(--rust-soft); color: var(--rust);
  border: 1px solid #e3b7a4;
  border-radius: 10px;
  padding: 10px 12px; font-size: 14px;
  margin-bottom: 12px; text-align: left;
}
.form-error.show { display: block; }
.test-note {
  margin-top: 18px; font-size: 12.5px; color: var(--ink-soft);
  background: var(--soft); border-radius: 10px; padding: 10px 12px; text-align: left;
}

/* ---------- App shell ---------- */
.app-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
.app-header .brand-mini {
  display: flex; align-items: center; gap: 9px;
  font-family: var(--font-head); font-size: 20px; font-weight: 600;
  white-space: nowrap;
}
.brand-mini .dot {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--green), #75a447);
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 17px; font-family: var(--font-body);
  flex: none;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.app-header .spacer { flex: 1; }
.user-chip {
  font-size: 13px; color: var(--ink-soft);
  max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sync-note {
  font-size: 12px; color: var(--ink-soft);
  background: var(--soft); border-radius: 999px; padding: 6px 12px;
  white-space: nowrap;
}
main { padding: 20px 16px 60px; max-width: 1100px; margin: 0 auto; }

/* Tree list */
.tree-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  margin-top: 16px;
}
.tree-card {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 18px 18px 48px 18px; box-shadow: var(--shadow);
  padding: 18px; cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.15s ease;
  text-align: left; font-family: var(--font-body); color: var(--ink);
  width: 100%;
}
.tree-card:hover { transform: translateY(-2px); }
.tree-card h3 { font-family: var(--font-head); margin: 0 0 8px; font-size: 22px; font-weight: 600; }
.role-badge {
  display: inline-block; font-size: 11.5px; font-weight: 700;
  padding: 3px 10px; border-radius: 999px;
  background: var(--green-soft); color: var(--green-2);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.role-badge.viewer { background: #eef0f4; color: #5a6472; }
.role-badge.editor { background: #fdf1dd; color: #9a6b1d; }
.tree-card .meta { font-size: 12.5px; color: var(--ink-soft); margin-top: 8px; }
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 4px 0 0; gap: 10px; flex-wrap: wrap;
}
.section-head h2 { font-family: var(--font-head); font-size: 26px; margin: 0; font-weight: 600; }

/* ---------- Tree canvas ---------- */
.tree-toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin: 12px 0;
}
.tree-toolbar .sep { width: 1px; height: 24px; background: var(--line); }
.toggle-chip {
  border: 1.5px solid var(--line); background: var(--paper);
  border-radius: 999px; padding: 7px 13px;
  font-size: 13px; font-weight: 600; color: var(--ink-soft);
  cursor: pointer; font-family: var(--font-body);
}
.toggle-chip[aria-pressed="true"] { border-color: var(--green); color: var(--green-2); background: var(--green-soft); }

.canvas-frame {
  position: relative;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px 8px 20px 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
  height: calc(100dvh - 250px);
  min-height: 420px;
}
.canvas-bg {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none; opacity: 0.11;
  overflow: hidden;
}
.canvas-bg img { width: 70vmin; height: 70vmin; object-fit: cover; border-radius: 50%; }
#treeCanvas { position: absolute; inset: 0; }
#treeCanvas .tree-viewport { cursor: grab; }
#treeCanvas .tree-viewport:active { cursor: grabbing; }
.canvas-hint {
  position: absolute; left: 12px; bottom: 10px;
  font-size: 12px; color: var(--ink-soft);
  background: rgba(244, 246, 241, 0.88);
  padding: 5px 10px; border-radius: 999px; pointer-events: none;
}
.canvas-empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; gap: 10px;
  align-items: center; justify-content: center; text-align: center;
  padding: 24px; color: var(--ink-soft);
}

/* Side panels (member / connection lists) */
.side-panel {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin-top: 14px; overflow: hidden;
}
.side-panel > button.panel-head {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  background: none; border: none; cursor: pointer;
  padding: 13px 16px; font-size: 15px; font-weight: 700; color: var(--ink);
  font-family: var(--font-body);
}
.side-panel .panel-body { padding: 0 16px 14px; }
.side-panel .panel-body[hidden] { display: none; }
.member-row {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  background: none; border: none; cursor: pointer;
  padding: 7px 4px; border-radius: 8px;
  font-family: var(--font-body); font-size: 14px; color: var(--ink);
}
.member-row:hover { background: var(--soft); }
.mini-circle {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 13px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.25);
  overflow: hidden;
}
.mini-circle img { width: 100%; height: 100%; object-fit: cover; }
.member-row .dates { margin-left: auto; font-size: 12px; color: var(--ink-soft); white-space: nowrap; }
.conn-row {
  font-size: 13.5px; color: var(--ink-soft); padding: 6px 4px;
  border-bottom: 1px dashed var(--line);
}
.conn-row:last-child { border-bottom: none; }
.conn-row .heart { font-style: normal; }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(8, 18, 12, 0.58);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; padding: 24px; }
}
.modal {
  background: var(--paper);
  width: 100%; max-width: 520px;
  max-height: 92dvh; overflow-y: auto;
  border-radius: 22px 12px 22px 12px;
  padding: 22px 20px calc(20px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
}
.modal h3 { font-family: var(--font-head); margin: 0 0 4px; font-size: 22px; font-weight: 600; }
.modal .sub { font-size: 13.5px; color: var(--ink-soft); margin: 0 0 14px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.modal-actions .btn { flex: 1; min-width: 120px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.checkline { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 8px 0; }
.checkline input { width: 18px; height: 18px; accent-color: var(--green-2); }

/* Profile */
.profile-top { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
.profile-circle {
  width: 76px; height: 76px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 26px; font-weight: 700;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
  overflow: hidden; box-shadow: var(--shadow);
}
.profile-circle img { width: 100%; height: 100%; object-fit: cover; }
.profile-top h3 { margin: 0; font-size: 24px; }
.profile-top .dates { color: var(--ink-soft); font-size: 13.5px; margin-top: 3px; }
.profile-bio { font-size: 14.5px; line-height: 1.55; margin: 10px 0; white-space: pre-wrap; }
.profile-meta { font-size: 13px; color: var(--ink-soft); margin: 6px 0; }
.link-btn {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 10px;
}

/* Toasts */
#toasts {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px;
  width: min(92vw, 420px);
}
.toast {
  background: #18221d; color: #fff;
  border-radius: 12px; padding: 12px 16px; font-size: 14px;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease;
}
.toast.error { background: var(--rust); }
.toast.ok { background: var(--green); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

/* Loading */
.loading-veil {
  display: flex; flex-direction: column; gap: 12px;
  align-items: center; justify-content: center;
  padding: 60px 20px; color: var(--ink-soft);
}
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--green-2);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }
.mt8 { margin-top: 8px; }
.center { text-align: center; }

/* ---------- birthdays ---------- */
.bday-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--rust); color: #fff;
  font-size: 0.72rem; font-weight: 800; line-height: 1;
  margin-left: 4px; vertical-align: 1px;
}
.bday-controls { margin-bottom: 10px; font-size: 0.85rem; color: var(--ink-soft); }
.bday-controls select, .bday-lead select {
  font: inherit; padding: 4px 8px; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
}
.bday-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 8px; border: 0; border-bottom: 1px solid var(--line);
  background: none; font: inherit; color: inherit; text-align: left;
  cursor: pointer; border-radius: 8px;
}
.bday-row:hover { background: var(--green-soft); }
.bday-cake { font-size: 1.4rem; }
.bday-who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.bday-who small, .bday-when small { color: var(--ink-soft); font-size: 0.75rem; }
.bday-when { text-align: right; display: flex; flex-direction: column; }
.bday-empty { color: var(--ink-soft); font-size: 0.9rem; padding: 8px 0; }
.bday-prefs {
  margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line);
  display: flex; flex-direction: column; gap: 8px; font-size: 0.85rem;
}
.bday-toggle { display: flex; align-items: center; gap: 8px; font-weight: 700; cursor: pointer; }
.bday-toggle input { width: 16px; height: 16px; accent-color: var(--green-2); }
.bday-lead { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); }
.bday-note { margin: 0; font-size: 0.75rem; color: var(--ink-soft); }

/* ---------- cross-tree links ---------- */
.link-create { margin-top: 10px; font-size: 0.85rem; color: var(--ink-soft); }
.link-create select {
  font: inherit; padding: 4px 8px; border-radius: 8px; margin: 0 6px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  max-width: 200px;
}
.link-btn { margin-top: 6px; }
