:root {
  color-scheme: light;
  --bg: #edf2ef;
  --panel: #ffffff;
  --line: #d6e2db;
  --accent: #0f8b6f;
  --accent-2: #0b6e58;
  --text: #172322;
  --muted: #5e7570;
  --danger: #ca3a3a;
  --soft: #f3f8f5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Trebuchet MS", "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #f9fcfa 0%, var(--bg) 45%, #e7efe9 100%);
  color: var(--text);
}

header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: #ffffffd9;
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  position: relative;
}

.workspace-tools {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}

.workspace-auth {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--line);
  background: #f7fbf9;
  border-radius: 12px;
  padding: 0.35rem 0.45rem 0.35rem 0.6rem;
  min-height: 44px;
}

.workspace-auth-user {
  margin: 0;
  font-size: 0.86rem;
  color: #1c4f42;
  max-width: 320px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand h1 {
  margin: 0 0 0.25rem;
}

.brand p {
  margin: 0;
  color: var(--muted);
}

.settings-menu {
  position: relative;
}

.settings-trigger {
  list-style: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #f7fbf9;
  color: #1e4e42;
  cursor: pointer;
  user-select: none;
  font-size: 1.2rem;
  line-height: 1;
}

.settings-trigger::-webkit-details-marker {
  display: none;
}

.settings-menu[open] .settings-trigger {
  background: #e9f5ef;
  border-color: #b6ddcf;
}

.settings-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.55rem);
  width: min(680px, 92vw);
  z-index: 60;
  display: grid;
  gap: 1rem;
}

main {
  padding: 1rem;
  max-width: 1320px;
  margin: 0 auto;
}

.hidden {
  display: none !important;
}

.guest-landing {
  display: grid;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.guest-landing h2,
.guest-landing h3 {
  margin: 0;
}

.guest-landing p {
  margin: 0;
}

.guest-grid {
  display: grid;
  gap: 0.7rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.guest-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem;
  background: linear-gradient(180deg, #ffffff 0%, #f9fcfb 100%);
}

.guest-card ul {
  margin: 0.45rem 0 0;
  padding-left: 1rem;
}

.tabs {
  display: inline-flex;
  gap: 0.4rem;
  background: #f2f7f4;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem;
  margin-bottom: 1rem;
}

.tab-btn {
  border-radius: 999px;
  background: transparent;
  color: #2a4e45;
  padding: 0.45rem 0.95rem;
}

.tab-btn:hover {
  background: #deeee7;
}

.tab-btn.active {
  background: var(--accent);
  color: #fff;
}

.tab-btn.active:hover {
  background: var(--accent-2);
}

.tab-panel {
  display: none;
  margin-bottom: 1rem;
}

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

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  box-shadow: 0 6px 18px rgba(22, 37, 34, 0.07);
}

.panel h2 {
  margin: 0;
  font-size: 1.1rem;
}

.section-head {
  margin-bottom: 0.85rem;
}

.section-head .muted {
  margin: 0.35rem 0 0;
}

.auth-panel h2,
.controls-panel h2 {
  margin-bottom: 0.5rem;
}

.auth-panel p {
  margin-top: 0;
}

.google-auth-wrap {
  min-width: 260px;
  min-height: 42px;
}

.auth-actions {
  align-items: center;
}

.list-panel,
.tree-panel {
  min-height: 420px;
}

.tree-panel {
  min-height: 620px;
}

.list-toolbar {
  margin-bottom: 0.85rem;
}

#peopleSearch {
  flex: 1;
  min-width: 220px;
}

.badge {
  background: #e2f4ed;
  border: 1px solid #b7dfd1;
  color: #1a5848;
  border-radius: 999px;
  padding: 0.28rem 0.62rem;
  font-size: 0.82rem;
  font-weight: 600;
}

.stats-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.stat-pill {
  border-radius: 999px;
  background: var(--soft);
  border: 1px solid var(--line);
  padding: 0.3rem 0.65rem;
  color: #24423a;
  font-size: 0.85rem;
}

.row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

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

.muted {
  color: var(--muted);
  font-size: 0.92rem;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.58rem 0.68rem;
  width: 100%;
  background: white;
  color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-color: var(--accent);
}

button {
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  padding: 0.55rem 0.85rem;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  background: var(--accent-2);
}

button.secondary {
  background: #e6f0ec;
  color: #23433b;
}

button.secondary:hover {
  background: #d7e7e1;
}

button.danger {
  background: var(--danger);
}

button.danger:hover {
  background: #b82f2f;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.file-label {
  position: relative;
  background: #e6f0ec;
  color: #23433b;
  border-radius: 10px;
  padding: 0.55rem 0.85rem;
  cursor: pointer;
}

.file-label input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.people-list {
  display: grid;
  gap: 0.8rem;
}

.person-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem;
  background: linear-gradient(180deg, #ffffff 0%, #f9fcfb 100%);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.person-card.focused {
  border-color: #66b29c;
  box-shadow: 0 0 0 2px #b9e2d5;
}

.person-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
}

.person-name {
  margin: 0;
}

.person-chip {
  font-size: 0.75rem;
  background: #eef6f2;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  color: #2f5047;
}

.person-card p {
  margin: 0.25rem 0;
}

.person-highlights {
  color: #35574d;
  font-size: 0.88rem;
}

.person-actions {
  margin-top: 0.55rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 0.9rem;
  background: #fbfefd;
}

.tree-view {
  overflow: auto;
  max-height: 76vh;
  padding-right: 0.3rem;
  padding-bottom: 0.35rem;
}

.tree-root-list,
.tree-root-list ul {
  list-style: none;
  margin: 0;
  padding-left: 1rem;
}

.tree-root-list > li {
  padding-left: 0;
}

.tree-root-list ul {
  margin-left: 0.45rem;
  border-left: 2px dashed #b8d7cb;
}

.tree-branch.relation-root > ul {
  border-left-color: #6dbd9f;
}

.tree-branch.relation-father > ul {
  border-left-color: #76a7f0;
}

.tree-branch.relation-mother > ul {
  border-left-color: #ef9dc4;
}

.tree-branch.relation-other > ul {
  border-left-color: #c7cfd6;
}

.tree-person {
  margin: 0.35rem 0;
  padding: 0.45rem 0.55rem;
  border-radius: 10px;
  border: 1px solid #d8e7e1;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: #f8fcfa;
}

.tree-person-icon {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
}

.tree-person-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tree-person-icon.male {
  color: #1e5bb7;
  background: #e8f0fe;
  border-color: #b8cef6;
}

.tree-person-icon.female {
  color: #b43076;
  background: #fee8f4;
  border-color: #f2b8d7;
}

.tree-person-icon.unknown {
  color: #56706a;
  background: #eef3f1;
  border-color: #ccd8d4;
}

.tree-person.matched {
  background: #ecf8f2;
}

.tree-person.focused {
  box-shadow: 0 0 0 2px #b9e2d5;
  border-color: #88c9b4;
  background: #f1fbf6;
}

.tree-person-btn {
  border: none;
  background: transparent;
  color: #19463c;
  padding: 0;
  text-align: left;
  font-weight: 600;
}

.tree-person-btn:hover {
  text-decoration: underline;
  transform: none;
  background: transparent;
}

.tree-meta {
  color: var(--muted);
  font-size: 0.82rem;
  margin-right: 0.15rem;
}

.relation-badge {
  border-radius: 999px;
  padding: 0.16rem 0.5rem;
  font-size: 0.74rem;
  line-height: 1.2;
  border: 1px solid transparent;
}

.relation-badge.relation-root {
  color: #19664f;
  background: #e3f4ec;
  border-color: #b8e0d0;
}

.relation-badge.relation-father {
  color: #1f549f;
  background: #e7f0ff;
  border-color: #bfd4fb;
}

.relation-badge.relation-mother {
  color: #9e2f68;
  background: #fde9f4;
  border-color: #f4bfdc;
}

.relation-badge.relation-other {
  color: #4f6460;
  background: #edf2f1;
  border-color: #d0dcd9;
}

.relation-badge.relation-spouse {
  color: #7a5612;
  background: #fff7df;
  border-color: #f0dfab;
}

.person-modal {
  border: none;
  border-radius: 16px;
  padding: 0;
  width: min(760px, 94vw);
  background: transparent;
}

.person-modal::backdrop {
  background: rgba(10, 18, 15, 0.48);
  backdrop-filter: blur(2px);
}

.person-modal-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
  margin: 0;
  box-shadow: 0 18px 48px rgba(17, 31, 28, 0.26);
  max-height: min(88vh, 860px);
  overflow: auto;
}

.person-modal-card label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: #36564e;
}

.relation-type-dialog {
  border: none;
  border-radius: 14px;
  padding: 0;
  width: min(420px, 92vw);
}

.relation-type-dialog::backdrop {
  background: rgba(10, 18, 15, 0.48);
}

.relation-type-dialog-card {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 1rem;
}

.relation-type-dialog-card h3 {
  margin: 0;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  z-index: 3;
  background: #fff;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid #e6efec;
}

.modal-head h3 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-head h3:empty {
  display: none;
}

.modal-head-title {
  min-width: 0;
}

.modal-person-badge {
  margin: 0.2rem 0 0;
  font-size: 1.22rem;
  color: #25473f;
  font-weight: 700;
}

.modal-actions {
  margin-top: 0.2rem;
}

.modal-tablist {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.modal-tab-btn.active {
  background: var(--accent);
  color: #fff;
}

.modal-tab-panel {
  display: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfefd;
  padding: 0.7rem;
}

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

.modal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.modal-grid .full {
  grid-column: 1 / -1;
}

.stack-list {
  display: grid;
  gap: 0.55rem;
}

.entry-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem;
  background: #fff;
}

.entry-compact-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.entry-summary {
  min-width: 0;
  font-size: 0.86rem;
  color: #36564e;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry-card.collapsed .entry-editable-body {
  display: none;
}

.tag-entry-card.collapsed .tag-editor-grid {
  display: none;
}

.relation-entry-card.collapsed .relation-editor-grid {
  display: none;
}

.tree-empty-actions {
  display: grid;
  justify-items: start;
  gap: 0.6rem;
}

.tree-relation-actions {
  margin-left: auto;
}

.tree-relation-select {
  min-width: 126px;
  padding: 0.24rem 0.35rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 0.78rem;
}

.tree-edit-btn {
  margin-left: auto;
  padding: 0.2rem 0.55rem;
  border-radius: 8px;
  font-size: 0.78rem;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1100px) {
  .tree-view {
    max-height: none;
  }
}

@media (max-width: 760px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

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

  .topbar {
    align-items: center;
  }

  .workspace-tools {
    width: 100%;
    justify-content: flex-end;
  }

  .workspace-auth {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
    max-width: 100%;
  }

  .workspace-auth-user {
    max-width: 100%;
    white-space: normal;
  }

  .google-auth-wrap {
    min-width: 100%;
  }

  .settings-panel {
    right: -0.4rem;
    width: min(680px, calc(100vw - 1rem));
  }

  header {
    position: static;
  }
}

.analysis-panel {
  min-height: 620px;
}

.analysis-toolbar {
  display: grid;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.analysis-view-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.analysis-view-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.analysis-controls label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.analysis-view {
  overflow: auto;
  min-height: 360px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 0.75rem;
  background: #fbfdfc;
}

.analysis-levels,
.analysis-fan {
  display: grid;
  gap: 0.8rem;
}

.analysis-fan .analysis-level {
  border-radius: 999px;
  border: 1px solid #dbe9e2;
  padding: 0.8rem;
}

.analysis-grid {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.analysis-node {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.6rem;
  background: #fff;
}

.analysis-node-title {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: #16473d;
  font-weight: 600;
  padding: 0;
  margin: 0 0 0.35rem;
  cursor: pointer;
}

.analysis-node-controls {
  margin-top: 0.5rem;
}

.analysis-timeline {
  display: grid;
  gap: 0.75rem;
}

.analysis-timeline-item {
  border-left: 3px solid #9dceb9;
  padding-left: 0.8rem;
}
