/* ===========================================================
   Family Tree — stylesheet
   Palette: paper #FAF6EF · ink #2B2A26 · forest #3C5B45
            rootbrown #8B6A4F · gold #C68F3D · line #DDD5C3
   Type: Fraunces (display/names) + Inter (UI/body)
   Mobile-first: base rules target ~375px, enhanced upward.
   =========================================================== */

:root {
  --paper: #FAF6EF;
  --paper-raised: #FFFFFF;
  --ink: #2B2A26;
  --ink-soft: #5B5848;
  --forest: #3C5B45;
  --forest-dark: #2A4030;
  --rootbrown: #8B6A4F;
  --gold: #C68F3D;
  --line: #DDD5C3;
  --error: #B3432B;
  --radius: 10px;
  --tap: 44px;
  --shadow: 0 1px 2px rgba(43, 42, 38, 0.06), 0 4px 14px rgba(43, 42, 38, 0.06);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: calc(var(--tap) + 24px); /* room for bottom nav */
}

h1, h2, h3, .display {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 .4em;
  line-height: 1.15;
}

h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }

p { margin: 0 0 .8em; }

a { color: var(--forest-dark); text-decoration: underline; text-underline-offset: 2px; }
a:hover, a:focus { color: var(--gold); }

a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

/* --- Layout shells --- */
.app-header {
  background: var(--paper-raised);
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}
.app-header .site-name {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1.15rem;
  color: var(--forest-dark);
  text-decoration: none;
}
.app-header .session-tag {
  font-size: .8rem;
  color: var(--ink-soft);
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

/* --- Bottom tab bar (mobile) --- */
.tab-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--paper-raised);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab-bar a {
  flex: 1;
  text-align: center;
  padding: 10px 4px;
  min-height: var(--tap);
  font-size: .78rem;
  color: var(--ink-soft);
  text-decoration: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.tab-bar a.active { color: var(--forest-dark); font-weight: 600; }
.tab-bar svg { width: 22px; height: 22px; }

/* --- Buttons & forms --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--forest);
  color: #fff;
  font-weight: 600;
  font-size: .95rem;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover, .btn:focus { background: var(--forest-dark); color: #fff; }
.btn.secondary { background: transparent; color: var(--forest-dark); border-color: var(--line); }
.btn.secondary:hover { background: var(--paper); }
.btn.danger { background: var(--error); }
.btn.danger:hover { background: #8f3120; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.field small.hint { display: block; color: var(--ink-soft); font-size: .8rem; margin-top: 4px; }

input[type=text], input[type=email], input[type=tel], input[type=date],
input[type=password], input[type=search], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raised);
  color: var(--ink);
  font-size: 1rem;
  font-family: inherit;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--forest); }

fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 16px; }
legend { font-weight: 600; padding: 0 6px; }

/* --- Cards --- */
.card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

/* --- Flash messages --- */
.flash { padding: 12px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: .92rem; }
.flash.success { background: #E7EFE6; color: var(--forest-dark); border: 1px solid #C7D8C2; }
.flash.error { background: #F6E3DC; color: var(--error); border: 1px solid #ECC2B3; }

/* --- Search box --- */
.search-box { position: relative; margin-bottom: 16px; }
.search-box input { padding-left: 38px; }
.search-box svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--ink-soft); }
.search-results { margin-top: 8px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--paper-raised); }
.search-results a { display: block; padding: 12px 14px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); min-height: var(--tap); }
.search-results a:last-child { border-bottom: none; }
.search-results a:hover, .search-results a:focus { background: var(--paper); }

/* --- Person profile --- */
.profile-header { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.profile-photo {
  width: 96px; height: 96px; border-radius: 50%;
  object-fit: cover; border: 3px solid var(--paper-raised);
  box-shadow: var(--shadow); flex-shrink: 0;
}
.living-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--forest); margin-right: 6px; }
.living-dot.deceased { background: var(--rootbrown); }
.meta-row { color: var(--ink-soft); font-size: .92rem; margin-bottom: 2px; }
.rel-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.rel-list a {
  display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink);
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); min-height: var(--tap);
}
.rel-list a:hover { border-color: var(--forest); }
.rel-list img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }

/* --- Tree view --- */
.tree-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raised);
  height: 70vh;
  min-height: 420px;
  overflow: hidden;
  touch-action: none;
}
#treeSvg { display: block; width: 100%; height: 100%; cursor: grab; }
#treeSvg:active { cursor: grabbing; }

.tree-controls {
  position: absolute; right: 10px; bottom: 10px;
  display: flex; flex-direction: column; gap: 6px; z-index: 5;
}
.tree-controls button {
  width: var(--tap); height: var(--tap);
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--paper-raised);
  color: var(--forest-dark);
  font-size: 1.3rem;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.person-card-name { font-family: 'Fraunces', serif; font-weight: 600; }

/* --- Tables (settings/users) --- */
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); }
th { color: var(--ink-soft); font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
.table-scroll { overflow-x: auto; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 600; }
.badge.editor { background: #E7EFE6; color: var(--forest-dark); }
.badge.viewer { background: #F1EADD; color: var(--rootbrown); }

footer.app-footer { text-align: center; color: var(--ink-soft); font-size: .8rem; padding: 24px 16px 90px; }

/* ===========================================================
   Tablet and up
   =========================================================== */
@media (min-width: 768px) {
  body { padding-bottom: 0; }
  .tab-bar { display: none; }
  main { padding: 24px; }
  h1 { font-size: 2rem; }
  .top-nav {
    display: flex; gap: 6px; align-items: center;
  }
  .top-nav a {
    padding: 8px 14px; border-radius: 999px; text-decoration: none; color: var(--ink-soft); font-weight: 600; font-size: .92rem;
  }
  .top-nav a.active, .top-nav a:hover { background: var(--paper); color: var(--forest-dark); }
  .profile-photo { width: 128px; height: 128px; }
  .tree-wrap { height: 76vh; }
}

@media (min-width: 1024px) {
  main { padding: 32px 40px; }
  h1 { font-size: 2.3rem; }
}
