/* ============================================================
   Design system (§15): warm, calm, photography-forward.
   Light theme; one warm accent; Thai + Latin rendered together.
   ============================================================ */

@font-face {
    font-family: 'Noto Sans';
    src: url('fonts/noto-sans-latin.woff2') format('woff2');
    font-weight: 400 700;
    font-display: swap;
}

@font-face {
    font-family: 'Noto Sans Thai';
    src: url('fonts/noto-sans-thai.woff2') format('woff2');
    font-weight: 400 700;
    font-display: swap;
}

:root {
    --bg: #faf6f0;
    --surface: #ffffff;
    --surface-soft: #f4ede3;
    --ink: #3d3229;
    --ink-muted: #6f6355;
    --border: #e5ddd2;
    --border-strong: #d3c7b8;
    --accent: #b4552d;
    --accent-hover: #9a4826;
    --accent-soft: #f6e7de;
    --danger: #a13333;
    --danger-soft: #f7e5e5;
    --ok: #4a7047;
    --shadow: 0 1px 3px rgba(61, 50, 41, 0.08), 0 4px 16px rgba(61, 50, 41, 0.06);
    --radius: 12px;
    --radius-sm: 8px;
    /* Thai ascenders/descenders need room (§15.2). */
    --lh: 1.7;
    font-size: 17px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: 'Noto Sans Thai', 'Noto Sans', 'Leelawadee UI', 'Thonburi', sans-serif;
    line-height: var(--lh);
}

h1, h2, h3, h4 {
    line-height: 1.5;
    margin: 0 0 0.5rem 0;
    font-weight: 700;
}
h1 { font-size: 1.7rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.15rem; }
h1:focus { outline: none; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

p { margin: 0 0 1rem 0; }

img { max-width: 100%; }

/* ---------- Layout shell ---------- */

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    min-height: 3.6rem;
    flex-wrap: wrap;
}

.topbar-brand {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.topbar-brand:hover { text-decoration: none; }

.topbar-nav {
    display: flex;
    gap: 0.25rem;
    align-items: center;
    flex-wrap: wrap;
}

.topbar-nav a {
    color: var(--ink-muted);
    padding: 0.4rem 0.85rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
}
.topbar-nav a:hover { background: var(--surface-soft); text-decoration: none; color: var(--ink); }
.topbar-nav a.active { background: var(--accent-soft); color: var(--accent); }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; }

.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 4rem;
}
.page-narrow { max-width: 720px; }

/* ---------- Banner (§6) ---------- */

.info-banner {
    background: var(--accent-soft);
    border: 1px solid #eacfbe;
    border-radius: var(--radius);
    padding: 0.75rem 1.15rem;
    margin: 1rem auto 0;
    max-width: 1200px;
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.55rem 1.2rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { background: var(--surface-soft); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: default; }

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

.btn-danger { color: var(--danger); border-color: #dcc0c0; }
.btn-danger:hover { background: var(--danger-soft); }

.btn-sm { padding: 0.25rem 0.7rem; font-size: 0.9rem; }

.btn-link {
    border: none;
    background: none;
    color: var(--accent);
    padding: 0.2rem 0.4rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }

/* ---------- Forms ---------- */

.field { margin-bottom: 1.1rem; }

.field label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.3rem;
}

.field .hint {
    font-size: 0.88rem;
    color: var(--ink-muted);
    margin-top: 0.25rem;
}

input[type="text"], input[type="email"], input[type="tel"], input[type="number"],
textarea, select {
    width: 100%;
    padding: 0.55rem 0.8rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font: inherit;
    line-height: 1.5;
    background: var(--surface);
    color: var(--ink);
}
input:focus, textarea:focus, select:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.field-inline { display: flex; gap: 0.6rem; }
.field-inline > * { flex: 1; }
/* Bilingual resilience (§15.5): if one label wraps and its neighbor doesn't,
   let the shorter label absorb the extra height so the inputs stay aligned. */
.field-inline > .field { display: flex; flex-direction: column; }
.field-inline > .field > label { flex: 1; }

.checkbox-row { display: flex; align-items: center; gap: 0.5rem; }
.checkbox-row input { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); }
.checkbox-row label { margin: 0; font-weight: 600; }

.validation-message { color: var(--danger); font-size: 0.9rem; }

/* ---------- Cards, alerts, badges ---------- */

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

.alert {
    padding: 0.7rem 1.1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
}
.alert-error { background: var(--danger-soft); color: var(--danger); border: 1px solid #e3c6c6; }
.alert-ok { background: #e9f0e8; color: var(--ok); border: 1px solid #cfdccd; }
.alert-info { background: var(--accent-soft); border: 1px solid #eacfbe; }

.badge {
    display: inline-block;
    font-size: 0.8rem;
    font-weight: 700;
    padding: 0.05rem 0.6rem;
    border-radius: 999px;
    background: var(--surface-soft);
    color: var(--ink-muted);
    white-space: nowrap;
}
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-ok { background: #e9f0e8; color: var(--ok); }

.muted { color: var(--ink-muted); }
.small { font-size: 0.88rem; }

/* ---------- Avatars (§15.3): consistent circles, dignified fallback ---------- */

.avatar {
    border-radius: 50%;
    object-fit: cover;
    background: var(--surface-soft);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--ink-muted);
    font-weight: 700;
    flex-shrink: 0;
    overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 2.2rem; height: 2.2rem; font-size: 0.8rem; }
.avatar-md { width: 3.2rem; height: 3.2rem; font-size: 1rem; }
.avatar-lg { width: 6.5rem; height: 6.5rem; font-size: 2rem; }

/* ---------- Tables (admin) ---------- */

.table-wrap { overflow-x: auto; }

table.data {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
}
table.data th, table.data td {
    text-align: left;
    padding: 0.55rem 0.85rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
table.data th { color: var(--ink-muted); font-size: 0.88rem; white-space: nowrap; }

/* ---------- Modal ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(61, 50, 41, 0.45);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 3rem 1rem;
    z-index: 100;
    overflow-y: auto;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 8px 40px rgba(61, 50, 41, 0.25);
    padding: 1.6rem;
    max-width: 560px;
    width: 100%;
}

/* ---------- Tree (§15.4) ---------- */

.tree-viewport {
    overflow: auto;
    padding: 2rem 1rem 3rem;
    background:
        radial-gradient(circle at 1px 1px, rgba(61,50,41,0.05) 1px, transparent 0) 0 0 / 26px 26px,
        var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 60vh;
    cursor: grab;
}
.tree-viewport:active { cursor: grabbing; }

.tree-inner { display: inline-block; min-width: 100%; text-align: center; }

/* A generation block: couple row on top, children below. */
.fam { display: inline-flex; flex-direction: column; align-items: center; vertical-align: top; }

.fam-couple { display: flex; align-items: flex-start; gap: 0.6rem; justify-content: center; }

.fam-children {
    display: flex;
    align-items: flex-start;
    gap: 1.4rem;
    padding-top: 1.6rem;
    position: relative;
}
/* Trunk from the couple down to the children rail. */
.fam-children::before {
    content: "";
    position: absolute;
    top: 0;
    left: 50%;
    width: 2px;
    height: 0.8rem;
    background: var(--border-strong);
}

.fam-child { position: relative; padding-top: 0.8rem; }
/* Riser from the rail down to each child. */
.fam-child::before {
    content: "";
    position: absolute;
    top: 0;
    left: 50%;
    width: 2px;
    height: 0.8rem;
    background: var(--border-strong);
}
/* The horizontal rail connecting siblings. */
.fam-child::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--border-strong);
}
.fam-child:first-child::after { left: 50%; }
.fam-child:last-child::after { right: 50%; }
.fam-child:only-child::after { display: none; }

/* Partner connector. */
.couple-link {
    align-self: center;
    color: var(--border-strong);
    font-size: 1.1rem;
    padding: 0 0.1rem;
    user-select: none;
}

/* Person node card. */
.node {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0.7rem 0.9rem 0.6rem;
    width: 11.5rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    position: relative;
}
.node:hover { border-color: var(--border-strong); }

.node.selected {
    border-color: var(--accent);
    outline: 3px solid var(--accent-soft);
}

.node .node-name {
    font-weight: 700;
    font-size: 1.02rem;
    line-height: 1.5;
    text-align: center;
    overflow-wrap: anywhere;
}

.node .node-sub { font-size: 0.85rem; color: var(--ink-muted); text-align: center; line-height: 1.45; }

.node.deceased { background: #f7f3ec; }
.node.deceased .node-name { color: var(--ink-muted); }

/* Placeholder/unknown persons: unmistakably provisional (§15.3). */
.node.placeholder {
    border-style: dashed;
    border-color: var(--border-strong);
    background: var(--bg);
    box-shadow: none;
}
.node.placeholder .node-name { font-style: italic; font-weight: 600; color: var(--ink-muted); }

.node-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    justify-content: center;
    padding: 0.65rem 0.5rem 0.2rem;
}

.expand-toggle {
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--ink-muted);
    border-radius: 999px;
    min-width: 1.7rem;
    height: 1.7rem;
    padding: 0 0.5rem;
    cursor: pointer;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1;
    margin-top: 0.5rem;
}
.expand-toggle:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* Child groups: one per partner, labeled with the other parent's name. */
.fam-groups { display: flex; align-items: flex-start; gap: 2.2rem; }

.fam-group { display: flex; flex-direction: column; align-items: center; }

.fam-group-label {
    font-size: 0.82rem;
    color: var(--ink-muted);
    background: var(--surface-soft);
    border-radius: 999px;
    padding: 0 0.7rem;
    margin-top: 0.6rem;
}

/* Name search with dropdown results (§9.6). */
.search-box { position: relative; min-width: 260px; }

.search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    z-index: 50;
    max-height: 22rem;
    overflow-y: auto;
}

.search-result {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.5rem 0.8rem;
    border: none;
    background: none;
    font: inherit;
    text-align: left;
    cursor: pointer;
    color: var(--ink);
}
.search-result:hover { background: var(--surface-soft); }

/* Ancestor strip above the focus person. */
.ancestor-strip {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

/* ---------- Gallery ---------- */

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

.gallery-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.gallery-item img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.gallery-item .gallery-caption { padding: 0.5rem 0.7rem; font-size: 0.85rem; color: var(--ink-muted); line-height: 1.5; }

/* ---------- Comments ---------- */

.comment {
    display: flex;
    gap: 0.85rem;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border);
}
.comment:last-child { border-bottom: none; }
.comment-body { flex: 1; min-width: 0; }
.comment-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-photos { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }
.comment-photos img { width: 7rem; height: 7rem; object-fit: cover; border-radius: var(--radius-sm); }

/* ---------- Details grid (profile) ---------- */

.detail-grid {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.4rem 1.4rem;
    align-items: baseline;
}
.detail-grid dt { color: var(--ink-muted); font-size: 0.92rem; margin: 0; }
.detail-grid dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- Public homepage: intentionally plain (§15.1) ---------- */

.plain-page {
    max-width: 560px;
    margin: 3rem auto;
    padding: 0 1.25rem;
    font-size: 1rem;
}

/* ---------- Misc ---------- */

.row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack-sm > * + * { margin-top: 0.5rem; }

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--danger-soft);
    color: var(--danger);
    padding: 0.8rem 1.25rem;
    z-index: 200;
    text-align: center;
}

.blazor-error-boundary {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid #e3c6c6;
    border-radius: var(--radius-sm);
    padding: 1rem;
}
.blazor-error-boundary::after { content: "An error has occurred. · เกิดข้อผิดพลาด"; }
