/* ============================================================
   Family Tree – Global Styles
   ============================================================ */

/* ── Fonts ── */

@font-face {
  font-display: swap;
  font-family: 'Noto Serif TC';
  font-style: normal;
  font-weight: 400;
  src: url('fonts/noto-serif-tc-v36-chinese-traditional_latin-regular.woff2') format('woff2');
}
@font-face {
  font-display: swap;
  font-family: 'Noto Serif TC';
  font-style: normal;
  font-weight: 500;
  src: url('fonts/noto-serif-tc-v36-chinese-traditional_latin-500.woff2') format('woff2');
}
@font-face {
  font-display: swap;
  font-family: 'Noto Serif TC';
  font-style: normal;
  font-weight: 600;
  src: url('fonts/noto-serif-tc-v36-chinese-traditional_latin-600.woff2') format('woff2');
}
@font-face {
  font-display: swap;
  font-family: 'Noto Serif TC';
  font-style: normal;
  font-weight: 700;
  src: url('fonts/noto-serif-tc-v36-chinese-traditional_latin-700.woff2') format('woff2');
}
@font-face {
  font-family: 'TwemojiCountryFlags';
  unicode-range: U+1F1E6-1F1FF;
  src: url('/fonts/TwemojiCountryFlags.woff2') format('woff2');
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'TwemojiCountryFlags', 'Noto Serif TC CJK', system-ui, -apple-system, sans-serif;
    font-size: 15px;
    background: #f4f2ee;
    color: #2e2e2e;
    line-height: 1.55;
}

a { color: #3d6fa8; }
a:hover { color: #264d7a; }

/* ── Shared values ── */

:root {
    --avatar-size: 80px;
    --avatar-radius: 8px;
    --avatar-border: 2px solid #d8d0c8;
}

/* ── Nav ── */
nav {
    background: #2c3e50;
    color: #fff;
    padding: 10px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 0.93rem;
}
nav .nav-left,
nav .nav-right {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
}
nav .nav-left  { gap: 8px; }
nav .nav-right { gap: 6px; margin-left: auto; }
nav .site-title { font-size: 1.05rem; font-weight: 700; color: #fff; text-decoration: none; }
nav .breadcrumb-sep { color: #88a; }
nav .breadcrumb-link { color: #a8c0d8; text-decoration: none; }
nav .breadcrumb-link:hover { color: #fff; }
nav .breadcrumb-current { color: #ddd; }
.btn-nav {
    background: rgba(255,255,255,.12);
    color: #dce6f0;
    border: 1px solid rgba(255,255,255,.2);
    padding: 4px 12px;
    border-radius: 4px;
    font-size: .8rem;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.4;
    font-family: inherit;
}
.btn-nav:hover {
    background: rgba(255,255,255,.22);
    color: #fff;
}

/* ── Page layout ── */
.container { 
    display: grid;
    justify-content: center;
    justify-items: stretch;
    margin: 0 auto; 
    padding: 28px 20px; 
}

/* ── Card ── */
.card {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 5px rgba(0,0,0,.10);
    padding: 24px;
    margin-bottom: 20px;
}

/* ── Page header ── */
.page-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.page-header h1 { font-size: 1.6rem; font-weight: 700; }
.page-header .actions { display: flex; gap: 8px; align-items: center; margin-left: auto; flex-wrap: wrap; }

/* ── Buttons ── */
.btn {
    display: inline-block;
    padding: 7px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font: inherit;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
}
.btn-primary   { background: #2c3e50; color: #fff; }
.btn-primary:hover   { background: #3a5068; color: #fff; }
.btn-secondary { background: #e8e4de; color: #333; }
.btn-secondary:hover { background: #d8d4ce; color: #333; }
.btn-danger    { background: #b03030; color: #fff; }
.btn-danger:hover    { background: #8e2626; color: #fff; }
.btn-sm { padding: 4px 10px; font-size: .8rem; }

/* ── Forms ── */
.form-card { max-width: 700px; }

.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    font-weight: 600;
    font-size: .875rem;
    margin-bottom: 5px;
    color: #444;
}
.form-group-inline {
    flex: 1;
    min-width: 160px;
    margin-bottom: 0;
}
.admin-tree-table input[type="password"],
.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="file"],
.form-group input[type="password"],
.form-group select {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font: inherit;
    font-size: .9rem;
    background: #fafafa;
    transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #4a90d9;
    box-shadow: 0 0 0 3px rgba(74,144,217,.18);
    background: #fff;
}
.form-hint { font-size: .8rem; color: #777; margin-top: 3px; }
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }
.form-row-inline {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-wrap: wrap;
}
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 24px; }

/* Inline checkbox labels (e.g. "Approximate" under year fields) */
.checkbox-label {
    font-size: .85rem;
    cursor: pointer;
    margin-top: 4px;
}
/* Required-field asterisk */
.required { color: #b03030; }
/* Hide elements (toggled by JS) */
.hidden { display: none; }
/* Remove margin from inline forms */
.m-0 { margin: 0; }
/* Muted text for hints & secondary info */
.text-muted    { color: #888; font-size: .9rem; }
.text-muted-sm { color: #888; font-size: .85rem; }
.form-caption { color: #555; font-size: .85rem; margin-bottom: 6px; }
/* Warning badge (e.g. "no password set") */
.text-warning { color: #b03030; font-size: .8rem; }
/* Subheading in cards */
.card-subheading { font-size: 1.15rem; }
/* Card spacing when stacking */
.card-stacked { margin-top: 10px; }

/* ── Login page ── */
.login-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.login-header h1 { margin: 0; }
.active-session-banner {
    background: #eaf4ea;
    border: 1px solid #b5d5b5;
    border-radius: 6px;
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: .9rem;
}
.active-session-banner a { display: block; margin-top: 6px; }

/* ── Admin table ── */
.admin-tree-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.admin-tree-table th { text-align: left; padding: 8px 8px 8px 0; }
.admin-tree-table td { padding: 6px 8px 6px 0; }
.admin-tree-table .inline-form {
    display: flex;
    gap: 6px;
    margin: 0;
    align-items: center;
}
/* Small input modifier – compact contexts (admin table, inline year editing) */
.input-sm {
    padding: 4px 8px;
    font-size: .8rem;
}
.admin-tree-table .inline-form .input-sm {
    width: 160px;
}

.alert-msg {
    border-radius: 6px;
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: .9rem;
}
.alert-msg--error {
    background: #fde8e8;
    border: 1px solid #e8a0a0;
    color: #8a1c1c;
}
.alert-msg--success {
    background: #e6f4ea;
    border: 1px solid #8dc99a;
    color: #1a5c2a;
}

/* ── Tree list (index) ── */
.tree-list { list-style: none; margin-top: 14px; }
.tree-list li {
    padding: 10px 0;
    border-bottom: 1px solid #eee;
    font-size: 1rem;
}
.tree-list li:first-child { border-top: 1px solid #eee; }
.tree-list a { font-weight: 600; font-size: 1.05rem; }
.no-trees { color: #888; margin-top: 12px; }

/* ── Tree visualization ── */
.tree-outer {
    overflow-x: auto;
    overflow-y: visible;
    padding: 10px 0 30px;
}
.tree-wrap {
    display: inline-block;
    min-width: 100%;
    position: relative;
    padding: 16px 48px 48px;
}
.tree-root {
    display: flex;
    flex-direction: row;
    gap: 40px;
    align-items: flex-start;
    flex-wrap: nowrap;
}

/* Family unit: one couple + their descendants */
.tree-family {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

/* Couple row */
.tree-couple {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0;
}

/* Horizontal line + optional year label between spouses */
.spouse-connector {
    width: 36px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.spouse-connector::before {
    content: '';
    position: absolute;
    left: 0; right: 0; top: 50%;
    height: 2px;
    background: #7a8fa6;
    margin-top: -1px;
}
.marriage-years {
    position: relative;
    z-index: 1;
    font-size: 0.67rem;
    color: #7a8fa6;
    background: #fff;
    padding: 0 3px;
    white-space: nowrap;
    line-height: 1.2;
    text-align: center;
}
.spouse-connector:has(.marriage-years br) {
    width: 56px;
}

/* Children row */
.tree-children {
    display: flex;
    flex-direction: row;
    gap: 20px;
    margin-top: 56px;    /* space for connector lines drawn by JS */
    align-items: flex-start;
}
.tree-children.collapsed {
    display: none;
}

/* Branch collapse / expand toggle */
.branch-toggle {
    position: absolute;
    z-index: 5;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid #8899aa;
    background: #fff;
    color: #556;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    font-family: Arial, sans-serif;
    pointer-events: auto;
}
.branch-toggle:hover {
    background: #edf2f7;
    border-color: #5a7a94;
}

/* ── Person card ── */
.person-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 110px;
    position: relative;
    min-height: calc(80px + 5.25em);
}
.edit-link {
    font-size: 0.73rem;
    color: #4a90d9;
    text-decoration: none;
    margin-bottom: 4px;
    height: 16px;
    line-height: 16px;
}
.edit-link:hover { text-decoration: underline; }

.person-photo {
    width: var(--avatar-size);
    height: var(--avatar-size);
    object-fit: cover;
    border-radius: var(--avatar-radius);
    border: var(--avatar-border);
    display: block;
}
.person-emoji {
    font-size: 44px;
    line-height: 76px;
    text-align: center;
    background: #f0ece6;
    user-select: none;
}
.person-name {
    font-family: 'Noto Serif TC CJK', 'Noto Serif TC', Georgia, serif;
    font-size: 0.8rem;
    font-weight: 700;
    text-align: center;
    margin-top: 6px;
    max-width: 110px;
    word-break: break-word;
    line-height: 1.3;
    [lang="zh-Hant"]{
        font-size: 1.5em;
    }
}
.person-years {
    font-size: 0.73rem;
    color: #888;
    text-align: center;
    margin-top: 2px;
}

/* ── Relationship list (edit page) ── */
.rel-list {
    list-style: none;
    margin-bottom:20px;
}
.rel-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    font-size: .9rem;
}
.rel-list li:last-child { border-bottom: none; }
.rel-spouse-form:not(.hidden) {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: .9rem;
}
.rel-year-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.rel-years-read:not(.hidden) {
    display: inline;
}
.marriage-years-inline {
    color: #666;
    font-size: .85rem;
}
.rel-spouse-name { font-weight: 500; margin-right: 4px; }
.rel-inline-field { display: flex; align-items: center; gap: 4px; font-size: .8rem; white-space: nowrap; }
.input-year { width: 5.5em; }
.rel-type-badge {
    display: inline-block;
    background: #e8f0fa;
    color: #2c5282;
    font-size: .75rem;
    font-weight: 600;
    border-radius: 4px;
    padding: 2px 7px;
    white-space: nowrap;
}

/* ── Current photo preview ── */
.photo-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}
.photo-preview img {
    width: var(--avatar-size);
    height: var(--avatar-size);
    object-fit: cover;
    border-radius: var(--avatar-radius);
    border: var(--avatar-border);
}
.photo-preview .photo-emoji {
    font-size: 44px;
    line-height: 1;
}

/* ── Fieldset-style section ── */
.form-section {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}
.form-section legend, .form-section-title {
    font-weight: 700;
    font-size: .9rem;
    color: #444;
    margin-bottom: 12px;
}

/* ── Utility classes ── */
.flex-fill { flex: 1; }
.mt-sm { margin-top: 8px; }
.mb-md { margin-bottom: 16px; }
.btn-full { width: 100%; }
.card-flush { padding: 0; overflow: hidden; }
.noscript-msg { padding: 20px; color: #888; }

/* ── Login page ── */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1,
.login-header h1 { font-size: 1.4rem; }
.hp-field {
    position: absolute;
    left: -9999px;
    top: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}

/* ── Edit tree title inline ── */
.tree-title-wrap { display: flex; align-items: baseline; gap: 10px; }
.tree-title-edit { font-size: 0.87rem; }

/* ── Delete confirm ── */
.delete-confirm {
    border: 1px solid #e8a0a0;
    background: #fff6f6;
    border-radius: 8px;
    padding: 14px 18px;
    margin-top: 24px;
}
.delete-confirm p { font-size: .9rem; color: #6b2020; margin-bottom: 10px; }

/* ============================================================
   Print styles
   ============================================================ */
body.clean-view .tree-wrap .no-print { visibility: hidden !important; }

@media print {
    .no-print { display: none !important; }

    nav, .page-header .actions { display: none; }
}
