/* ── Theme tokens ────────────────────────────────────────────────
   Default is the dark palette used in the reference HTML mockup.
   Light palette overrides via prefers-color-scheme: light so the
   whole web app tracks the system preference, matching the existing
   /tree/{token} share-link page. */
:root {
  --app-bg: #0f172a;
  --panel-bg: rgba(15, 23, 42, 0.95);
  --panel-border: rgba(56, 189, 248, 0.3);
  --sidebar-bg: rgba(15, 23, 42, 0.95);
  --sidebar-border: rgba(56, 189, 248, 0.2);
  --card-bg: #1e293b;
  --card-bg-subtle: rgba(15, 23, 42, 0.4);
  --dialog-bg: linear-gradient(135deg, #1e293b, #0f172a);
  --input-bg: #0f172a;
  --input-border: #334155;
  --input-border-focus: #38bdf8;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --accent-tint: rgba(56, 189, 248, 0.15);
  --accent-tint-strong: rgba(56, 189, 248, 0.3);
  --divider: rgba(148, 163, 184, 0.1);
  --hover-bg: rgba(56, 189, 248, 0.08);
  --danger: #f87171;
  --danger-bg: rgba(239, 68, 68, 0.15);
  --danger-border: rgba(239, 68, 68, 0.3);
  --success: #4ade80;
  --success-bg: rgba(74, 222, 128, 0.15);
  --panel-shadow: -5px 0 25px rgba(0, 0, 0, 0.5);
}
@media (prefers-color-scheme: light) {
  :root {
    --app-bg: #f1f5f9;
    --panel-bg: rgba(255, 255, 255, 0.97);
    --panel-border: rgba(14, 165, 233, 0.25);
    --sidebar-bg: rgba(255, 255, 255, 0.97);
    --sidebar-border: rgba(14, 165, 233, 0.2);
    --card-bg: #ffffff;
    --card-bg-subtle: rgba(241, 245, 249, 0.7);
    --dialog-bg: linear-gradient(135deg, #ffffff, #f8fafc);
    --input-bg: #ffffff;
    --input-border: #cbd5e1;
    --input-border-focus: #0284c7;
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --text-faint: #94a3b8;
    --accent: #0284c7;
    --accent-hover: #0369a1;
    --accent-tint: rgba(2, 132, 199, 0.1);
    --accent-tint-strong: rgba(2, 132, 199, 0.3);
    --divider: rgba(148, 163, 184, 0.3);
    --hover-bg: rgba(2, 132, 199, 0.08);
    --danger: #dc2626;
    --danger-bg: rgba(239, 68, 68, 0.08);
    --danger-border: rgba(239, 68, 68, 0.3);
    --success: #16a34a;
    --success-bg: rgba(22, 163, 74, 0.1);
    --panel-shadow: -5px 0 25px rgba(15, 23, 42, 0.1);
  }
}

/* Right-side slide-in panels (Profile / Chat) */
.side-panel {
  position: fixed;
  top: 0;
  right: -400px;
  width: 350px;
  height: 100%;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-left: 1px solid var(--panel-border);
  transition: right 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  box-shadow: var(--panel-shadow);
  z-index: 25;
  overflow-y: auto;
}
.side-panel.active { right: 0; }

.close-btn {
  position: absolute;
  top: 1rem;
  right: 1.5rem;
  cursor: pointer;
  font-size: 1.5rem;
  color: var(--text-muted);
  z-index: 10;
}
.close-btn:hover { color: var(--text-primary); }

.avatar-large {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--accent);
  margin: 0 auto 1rem auto;
  display: block;
  box-shadow: 0 0 20px var(--accent-tint-strong);
}

.status-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: var(--accent-tint);
  color: var(--accent);
  border-radius: 999px;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

.hide-scrollbar::-webkit-scrollbar { display: none; }
.hide-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

/* Profile panel — semantic classes so inline JS doesn't need to know colors */
.pp-root { padding: 0 1.25rem 2rem; }
.pp-header { text-align: center; margin-top: 2rem; }
.pp-name { font-size: 1.5rem; font-weight: bold; color: var(--text-primary); margin: 0 0 0.3rem; }
.pp-meta { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.5rem; }
.pp-badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.7rem; margin-left: 0.3rem; }
.pp-badge.claimed { background: var(--success-bg); color: var(--success); }
.pp-badge.unclaimed { background: rgba(148,163,184,0.15); color: var(--text-muted); }
.pp-bio { background: var(--card-bg); padding: 0.75rem; border-radius: 8px; border: 1px solid var(--input-border); color: var(--text-secondary); font-size: 0.85rem; line-height: 1.5; margin-bottom: 0.75rem; }
.pp-fields { background: var(--card-bg-subtle); padding: 0.6rem 0.9rem; border-radius: 8px; border: 1px solid var(--divider); margin-bottom: 0.75rem; }
.pp-field { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.35rem 0; border-bottom: 1px solid var(--divider); font-size: 0.85rem; }
.pp-field:last-child { border-bottom: none; }
.pp-field-label { color: var(--text-muted); }
.pp-field-value { color: var(--text-primary); text-align: right; word-break: break-all; }
.pp-nocontact { color: var(--text-faint); font-size: 0.85rem; text-align: center; padding: 0.75rem; }
.pp-rel-section { margin-top: 0.75rem; }
.pp-rel-title { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; margin-bottom: 0.3rem; }
.pp-rel-row { display: flex; justify-content: space-between; align-items: center; padding: 0.35rem 0.6rem; background: var(--card-bg-subtle); border-radius: 6px; margin-bottom: 0.3rem; font-size: 0.85rem; color: var(--text-primary); }
.pp-rel-unlink { background: transparent; border: none; color: var(--danger); cursor: pointer; font-size: 0.9rem; padding: 0 0.3rem; }
.pp-stats { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.pp-stat { flex: 1; text-align: center; background: var(--card-bg-subtle); padding: 0.5rem; border-radius: 6px; }
.pp-stat-value { font-size: 1.1rem; font-weight: bold; color: var(--accent); }
.pp-stat-label { font-size: 0.7rem; color: var(--text-muted); }
.pp-actions { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.4rem; }
.pp-btn-primary { width: 100%; padding: 0.5rem; background: var(--accent); color: #0f172a; font-weight: bold; border: none; border-radius: 8px; cursor: pointer; }
.pp-btn-primary:hover { background: var(--accent-hover); }
.pp-btn-secondary { width: 100%; padding: 0.5rem; background: var(--accent-tint); color: var(--accent); border: 1px solid var(--accent-tint-strong); border-radius: 8px; cursor: pointer; }
.pp-btn-secondary:hover { background: var(--accent-tint-strong); }
.pp-btn-danger { width: 100%; padding: 0.5rem; background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-border); border-radius: 8px; cursor: pointer; margin-top: 0.2rem; }
.pp-btn-danger:hover { background: var(--danger-border); }
.pp-loading, .pp-error { color: var(--text-muted); font-size: 0.9rem; padding: 2rem; text-align: center; }
.pp-error { color: var(--danger); }

/* Chat bubbles */
.msg-bubble { max-width: 80%; padding: 10px 14px; border-radius: 12px; font-size: 14px; line-height: 1.4; word-break: break-all; }
.msg-me { background: var(--accent); color: #0f172a; align-self: flex-end; border-bottom-right-radius: 2px; }
.msg-them { background: var(--card-bg); color: var(--text-primary); align-self: flex-start; border-bottom-left-radius: 2px; }

/* Full-bleed canvas stage (overview / friends fallback) */
.canvas-stage { position: fixed; inset: 48px 0 0 0; overflow: hidden; }
.canvas-stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* Top-left floating toolbar on canvas pages — inherits dark in share-link
   style.css; override for light theme so text stays readable */
#toolbar {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 10;
}
.tool-btn {
  background: var(--panel-bg);
  border: 1px solid var(--input-border);
  color: var(--text-primary);
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  font-weight: 600;
  font-size: 14px;
}
.tool-btn:hover { background: var(--accent-tint-strong); border-color: var(--accent); }

/* Left sidebar */
body.with-sidebar {
  margin: 0;
  display: flex;
  min-height: 100vh;
  background: var(--app-bg);
  color: var(--text-primary);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body.with-sidebar #app-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 20;
}
body.with-sidebar .canvas-wrap {
  margin-left: 240px;
  flex: 1;
  position: relative;
  min-height: 100vh;
}
body.with-sidebar canvas#graph { display: block; width: 100%; height: 100vh; touch-action: none; }
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-hamburger {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}

@media (max-width: 768px) {
  body.with-sidebar { flex-direction: column; }
  body.with-sidebar #app-sidebar {
    position: sticky;
    top: 0;
    width: 100%;
    max-height: 56px;
    overflow: hidden;
    border-right: none;
    border-bottom: 1px solid var(--sidebar-border);
    transition: max-height 0.25s ease;
  }
  body.with-sidebar #app-sidebar.expanded {
    max-height: 70vh;
    overflow-y: auto;
  }
  body.with-sidebar .sidebar-hamburger { display: inline-block; }
  body.with-sidebar .canvas-wrap { margin-left: 0; }
  body.with-sidebar canvas#graph { height: calc(100vh - 56px); }
}

.sidebar-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--divider); }
.sidebar-logo { color: var(--accent); font-weight: bold; font-size: 1.1rem; text-decoration: none; }
.sidebar-nav { flex: 1; padding: 0.5rem 0; overflow-y: auto; }
.sidebar-section-title { font-size: 0.7rem; text-transform: uppercase; color: var(--text-faint); padding: 1rem 1.25rem 0.5rem; letter-spacing: 0.05em; }
.sidebar-list, .sidebar-item { display: block; }
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1.25rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  transition: background 0.15s;
}
.sidebar-item:hover { background: var(--hover-bg); color: var(--text-primary); }
.sidebar-item.active {
  background: var(--accent-tint);
  color: var(--accent);
  border-left: 3px solid var(--accent);
  padding-left: calc(1.25rem - 3px);
}
.sidebar-icon { font-size: 1rem; flex-shrink: 0; }
.sidebar-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-item-count { color: var(--text-faint); font-size: 0.75rem; }
.sidebar-loading, .sidebar-empty { padding: 0.6rem 1.25rem; color: var(--text-faint); font-size: 0.85rem; }
.sidebar-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--divider); }
.sidebar-logout-btn {
  background: transparent;
  border: 1px solid var(--input-border);
  color: var(--text-secondary);
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  width: 100%;
}
.sidebar-logout-btn:hover { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }

/* Reposition share-link fixed-position header/controls/search so they don't
   sit under the 240px sidebar on desktop */
body.with-sidebar .header,
body.with-sidebar .footer,
body.with-sidebar .search-panel,
body.with-sidebar .loading { left: 240px !important; }
body.with-sidebar .controls { left: calc(240px + 12px) !important; }
body.with-sidebar .loading { right: 0 !important; width: auto; }
@media (max-width: 768px) {
  body.with-sidebar .header,
  body.with-sidebar .controls,
  body.with-sidebar .footer,
  body.with-sidebar .search-panel,
  body.with-sidebar .loading { left: 0 !important; }
  body.with-sidebar .header { top: 56px !important; }
}

/* Pick-target banner */
.pick-hint {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  z-index: 40;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: #0f172a;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  box-shadow: 0 6px 20px var(--accent-tint-strong);
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
}
.pick-hint.active { transform: translateX(-50%) translateY(0); }
.pick-hint-cancel {
  background: rgba(15, 23, 42, 0.2);
  color: #0f172a;
  border: none;
  border-radius: 999px;
  width: 24px; height: 24px;
  cursor: pointer;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pick-hint-cancel:hover { background: rgba(15, 23, 42, 0.35); }
body.picking-rel #graph { cursor: crosshair; }

/* Profile panel quick-add */
.pp-quickadd {
  padding: 0.45rem 0.5rem;
  background: var(--hover-bg);
  color: var(--text-primary);
  border: 1px solid var(--accent-tint-strong);
  border-radius: 8px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
}
.pp-quickadd:hover { background: var(--accent-tint); border-color: var(--accent); }
.pp-quickadd-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.3rem; margin-top: 0.4rem; }

/* Right-click context menu */
.context-menu {
  position: fixed;
  background: var(--card-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  z-index: 45;
  min-width: 180px;
  overflow: hidden;
  font-size: 0.85rem;
}
.context-menu-item {
  padding: 0.5rem 0.9rem;
  color: var(--text-primary);
  cursor: pointer;
  border: none;
  background: transparent;
  text-align: left;
  width: 100%;
  display: block;
}
.context-menu-item:hover { background: var(--accent-tint); color: var(--accent); }
.context-menu-divider { height: 1px; background: var(--divider); margin: 0; }

/* Dialog (native <dialog>) */
dialog.km-dialog {
  background: var(--dialog-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  color: var(--text-primary);
  padding: 1.5rem;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.25);
  max-width: 460px;
  width: 90%;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  margin: auto;
  inset: 0;
}
dialog.km-dialog::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px); }
dialog.km-dialog h3 { margin: 0 0 1rem 0; font-size: 1.1rem; font-weight: bold; color: var(--accent); }
dialog.km-dialog label { display: block; color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.25rem; margin-top: 0.5rem; }
dialog.km-dialog input[type="text"],
dialog.km-dialog input[type="email"],
dialog.km-dialog input[type="number"],
dialog.km-dialog textarea,
dialog.km-dialog select {
  width: 100%;
  box-sizing: border-box;
  padding: 0.5rem 0.75rem;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
dialog.km-dialog input:focus,
dialog.km-dialog textarea:focus,
dialog.km-dialog select:focus { border-color: var(--input-border-focus); }
dialog.km-dialog textarea { resize: vertical; min-height: 3em; }
dialog.km-dialog button { padding: 0.4rem 1rem; border: none; border-radius: 6px; cursor: pointer; font-size: 0.9rem; font-weight: 600; font-family: inherit; transition: opacity 0.15s, transform 0.05s; }
dialog.km-dialog button:active { transform: translateY(1px); }
dialog.km-dialog button[onclick^="submit"],
dialog.km-dialog button.primary { background: var(--accent); color: #0f172a; }
dialog.km-dialog button[onclick^="submit"]:hover,
dialog.km-dialog button.primary:hover { background: var(--accent-hover); }
dialog.km-dialog button[onclick*="close()"],
dialog.km-dialog button.ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--input-border); }
dialog.km-dialog button[onclick*="close()"]:hover,
dialog.km-dialog button.ghost:hover { color: var(--text-primary); border-color: var(--text-muted); }

/* Add-member dialog tabs + kinship grid */
.add-member-tabs {
  display: flex;
  gap: 0.3rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--divider);
}
.amt-tab {
  padding: 0.5rem 1rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
}
.amt-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.amt-hint { font-size: 0.8rem; color: var(--text-muted); margin: 0 0 0.75rem; }
.amt-kinship-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-top: 0.75rem;
}
.amt-kinship-btn {
  padding: 0.65rem 0.5rem;
  background: var(--hover-bg);
  color: var(--text-primary);
  border: 1px solid var(--accent-tint-strong);
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s;
}
.amt-kinship-btn:hover { background: var(--accent-tint); border-color: var(--accent); }

.amt-preview {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  min-height: 1.5rem;
  margin: 0.5rem 0;
  font-size: 0.85rem;
}
.amt-preview-chip {
  padding: 0.15rem 0.5rem;
  background: var(--accent-tint);
  color: var(--text-primary);
  border-radius: 999px;
  border: 1px solid var(--accent-tint-strong);
}
.amt-preview-sep { color: var(--text-muted); }
.amt-preview-err { color: #ef4444; font-size: 0.8rem; }

/* ── Light-mode overrides for auth/list pages using Tailwind utility classes ─────
   The CDN Tailwind doesn't respond to prefers-color-scheme by default, so we
   override the few utilities we actually use on Login / Register / ForgotPassword
   / Trees.Index / Friends.Index / _Layout.
*/
@media (prefers-color-scheme: light) {
  body.bg-slate-900, body { background-color: var(--app-bg) !important; color: var(--text-primary) !important; }
  .bg-slate-900\/80 { background-color: rgba(241, 245, 249, 0.85) !important; }
  .bg-slate-900 { background-color: var(--app-bg) !important; }
  .bg-slate-800 { background-color: var(--card-bg) !important; }
  .bg-slate-800\/80 { background-color: rgba(255, 255, 255, 0.85) !important; }
  .bg-slate-700 { background-color: #e2e8f0 !important; }
  .border-slate-700, .border-slate-800 { border-color: var(--input-border) !important; }
  .text-slate-100, .text-white { color: var(--text-primary) !important; }
  .text-slate-200 { color: var(--text-secondary) !important; }
  .text-slate-300 { color: var(--text-secondary) !important; }
  .text-slate-400 { color: var(--text-muted) !important; }
  .text-slate-500 { color: var(--text-faint) !important; }
  .text-slate-600 { color: var(--text-faint) !important; }
  .text-sky-400 { color: var(--accent) !important; }
  .hover\:text-sky-400:hover { color: var(--accent) !important; }
  .bg-sky-500 { background-color: var(--accent) !important; }
  .hover\:bg-sky-400:hover { background-color: var(--accent-hover) !important; }
  .backdrop-blur { backdrop-filter: blur(8px); }
}
