/* Family Roots — Living Family Tree — senior-friendly, offline-first */

:root {
  --accent: #2D6A4F;
  --accent-hover: #1B4332;
  --accent-soft: #D8F3DC;
  --accent-ink: #081C15;
  --bg: #F7F5F0;
  --surface: #FFFFFF;
  --surface-2: #EEEBE4;
  --text: #1C1917;
  --text-muted: #57534E;
  --border: #D6D3D1;
  --danger: #B91C1C;
  --danger-soft: #FEE2E2;
  --success: #166534;
  --success-soft: #DCFCE7;
  --warn: #92400E;
  --warn-soft: #FEF3C7;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(28, 25, 23, 0.08), 0 4px 16px rgba(28, 25, 23, 0.06);
  --shadow-lg: 0 8px 30px rgba(28, 25, 23, 0.12);
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --touch: 48px;
  --max: 920px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

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

button {
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -100px;
  z-index: 1000;
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  top: 0.75rem;
}

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 0 rgba(28, 25, 23, 0.04);
}

.header-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.85rem 1rem 0;
}

.brand {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.brand-mark {
  font-size: 1.75rem;
  line-height: 1;
  margin-top: 0.15rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent-ink);
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0.15rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.main-nav {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  padding-bottom: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.main-nav::-webkit-scrollbar {
  display: none;
}

.nav-btn {
  flex: 0 0 auto;
  min-height: var(--touch);
  padding: 0.65rem 1rem;
  border: none;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.nav-btn:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.nav-btn.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: transparent;
}

/* Main */
.main {
  flex: 1;
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.25rem 1rem 2.5rem;
}

.view[hidden] {
  display: none !important;
}

.view-header {
  margin-bottom: 1.25rem;
}

.view-header.row-between {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem 1rem;
}

.view-header h2 {
  margin: 0 0 0.35rem;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent-ink);
  letter-spacing: -0.02em;
}

.view-lead {
  margin: 0;
  color: var(--text-muted);
  max-width: 40rem;
}

/* Stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

@media (min-width: 640px) {
  .stat-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.stat-card.stat-ok {
  border-color: #95D5B2;
  background: linear-gradient(180deg, #F0FFF4 0%, var(--surface) 100%);
}

.stat-card.stat-warn {
  border-color: #FCD34D;
  background: linear-gradient(180deg, #FFFBEB 0%, var(--surface) 100%);
}

.stat-label {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.stat-value {
  margin: 0.25rem 0 0.5rem;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.stat-link {
  display: inline-block;
  min-height: 44px;
  padding: 0.35rem 0;
  border: none;
  background: none;
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.stat-link:hover {
  color: var(--accent-hover);
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.15rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 0.75rem;
}

.card-head h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-ink);
}

.card-body-text {
  margin: 0 0 1rem;
  color: var(--text-muted);
}

.card-note {
  margin: -0.25rem 0 0.75rem;
}

.muted-sm {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: var(--touch);
  padding: 0.65rem 1.15rem;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  font-weight: 600;
  text-align: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--accent-ink);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--surface-2);
  border-color: var(--text-muted);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-danger:hover {
  background: #991B1B;
  border-color: #991B1B;
}

.btn-text {
  min-height: 44px;
  padding: 0.35rem 0.5rem;
  border: none;
  background: none;
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-text:hover {
  color: var(--accent-hover);
}

.btn-icon {
  min-width: var(--touch);
  min-height: var(--touch);
  padding: 0;
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
}

.btn-icon:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-sm {
  min-height: 44px;
  padding: 0.45rem 0.85rem;
  font-size: 0.95rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.file-label {
  cursor: pointer;
}

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}

.field.grow {
  flex: 1;
  min-width: 12rem;
}

.field label {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

.req {
  color: var(--danger);
}

.field input,
.field select,
.field textarea {
  min-height: var(--touch);
  padding: 0.6rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  width: 100%;
}

.field textarea {
  min-height: 6rem;
  resize: vertical;
  line-height: 1.45;
}

.field select[multiple] {
  min-height: 8rem;
  padding: 0.5rem;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 0.75rem;
}

@media (min-width: 560px) {
  .field-row {
    grid-template-columns: 1fr 1fr;
  }
}

.filter-bar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem 0.75rem;
  margin-bottom: 1rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

@media (min-width: 560px) {
  .filter-bar {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 800px) {
  .filter-bar {
    grid-template-columns: repeat(4, 1fr);
  }
}

.filter-bar .field {
  margin-bottom: 0;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: flex-end;
  margin-bottom: 0.85rem;
}

.inline-form .field {
  margin-bottom: 0;
}

.result-summary {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Lists */
.item-list,
.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.item-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.85rem 0.9rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}

.item-row:hover {
  border-color: var(--border);
}

.item-main {
  flex: 1;
  min-width: 12rem;
}

.item-title {
  margin: 0;
  font-weight: 700;
  color: var(--text);
  font-size: 1rem;
}

.item-meta {
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.empty-state {
  padding: 1.25rem 1rem;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
}

.empty-state p {
  margin: 0 0 0.75rem;
}

.empty-state p:last-child {
  margin-bottom: 0;
}

/* Person / memory cards */
.entity-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}

.entity-card-top {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
}

.avatar {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  background: var(--accent);
}

.avatar.remembered {
  background: #78716C;
}

.entity-body {
  flex: 1;
  min-width: 0;
}

.entity-name {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-ink);
}

.entity-sub {
  margin: 0.15rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.badge.muted {
  background: var(--surface-2);
  color: var(--text-muted);
}

.badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.entity-notes {
  margin: 0.65rem 0 0;
  font-size: 0.95rem;
  color: var(--text);
}

.entity-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

/* Who grid */
.who-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
}

@media (min-width: 560px) {
  .who-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.who-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.85rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: none;
  text-align: left;
  width: 100%;
  min-height: var(--touch);
  cursor: pointer;
}

.who-card:hover {
  background: var(--accent-soft);
}

.who-card .avatar {
  width: 44px;
  height: 44px;
  font-size: 0.9rem;
}

.who-card-text {
  flex: 1;
  min-width: 0;
}

.who-card-name {
  margin: 0;
  font-weight: 700;
  font-size: 0.95rem;
}

.who-card-meta {
  margin: 0.1rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Reminder done */
.item-row.is-done .item-title {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

@media (min-width: 600px) {
  .modal {
    align-items: center;
    padding: 1.5rem;
  }
}

.modal[hidden] {
  display: none !important;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 25, 23, 0.45);
}

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 540px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow-lg);
  padding: 1rem 1.15rem 1.25rem;
  z-index: 1;
}

@media (min-width: 600px) {
  .modal-panel {
    border-radius: var(--radius);
  }
}

.modal-panel-sm {
  max-width: 420px;
}

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

.modal-head h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent-ink);
}

.modal-form {
  margin: 0;
}

.modal-body {
  margin-bottom: 0.5rem;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.55rem;
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.confirm-message {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  color: var(--text);
  line-height: 1.5;
}

.detail-block {
  margin-bottom: 0.85rem;
}

.detail-block h3 {
  margin: 0 0 0.35rem;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-block p {
  margin: 0;
  font-size: 1rem;
}

.detail-list {
  margin: 0;
  padding-left: 1.2rem;
}

.detail-list li {
  margin-bottom: 0.25rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  max-width: min(92vw, 28rem);
  padding: 0.85rem 1.25rem;
  background: var(--accent-ink);
  color: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-weight: 600;
  text-align: center;
}

.toast[hidden] {
  display: none !important;
}

/* Footer */
.app-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 1rem;
  text-align: center;
}

.app-footer p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Progress bars for insights */
.bar-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.75rem 0.9rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}

.bar-label-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.95rem;
}

.bar-track {
  height: 10px;
  background: #E7E5E4;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  min-width: 0;
}

body.modal-open {
  overflow: hidden;
}
