:root {
    --color-bg: #f5f5f7;
    --color-text: #111827;
    --color-text-muted: #6b7280;
    --color-text-faint: #9ca3af;
    --color-border: #e5e7eb;
    --color-accent: #2563eb;
    --color-accent-dark: #1d4ed8;
    --color-accent-soft: #eff6ff;
    --color-danger: #991b1b;
    --color-danger-bg: #fee2e2;
    --color-success: #166534;
    --color-success-bg: #dcfce7;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-full: 999px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
}

a { color: inherit; }

/* Top app header: two rows, like the reference design
   row 1 = brand + user actions, row 2 = section tabs */
.app-header {
    background: #fff;
}

.app-header__top {
    border-bottom: 1px solid #f1f1f3;
}

.app-header__top-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0.85rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
}

.app-header__brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.02em;
    white-space: nowrap;
    text-decoration: none;
}

.app-header__logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: var(--color-accent);
    color: #fff;
    font-size: 0.9rem;
}

.app-header__user {
    display: flex;
    align-items: center;
    gap: 0.9rem;
}

.app-header__avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--color-accent-soft);
    color: var(--color-accent-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
}

.app-header__logout {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--color-bg);
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 0.95rem;
}

.app-header__logout:hover {
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.app-header__tabs {
    border-bottom: 1px solid var(--color-border);
}

.app-header__tabs-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    gap: 2rem;
    -webkit-overflow-scrolling: touch;
}

.app-header__tabs a {
    flex-shrink: 0;
}

.app-header__tabs a {
    text-decoration: none;
    color: var(--color-text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.9rem 0;
    margin-bottom: -1px;
    border-bottom: 2px solid transparent;
}

.app-header__tabs a.active {
    color: var(--color-text);
    border-bottom-color: var(--color-accent);
    font-weight: 700;
}

/* Page layout */
.page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2.5rem 2rem;
}

.page-header {
    margin-bottom: 2rem;
}

.page-header .back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--color-accent);
    text-decoration: none;
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

.page-header h1 {
    font-size: 2rem;
    font-weight: 800;
    margin: 0 0 0.4rem;
}

.page-header .subtitle {
    color: var(--color-text-muted);
    font-size: 0.95rem;
    margin: 0;
}

/* Cards */
.card {
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    overflow-x: auto;
}

.card + .card { margin-top: 1.5rem; }

/* Form sections, à la "Meeting Title / Location" layout */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem 2rem;
}

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

.form-section h2 {
    font-size: 0.95rem;
    font-weight: 700;
    margin: 0 0 0.2rem;
}

.form-section .desc {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin: 0 0 0.75rem;
}

.field-box {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.65rem 0.9rem;
    background: #fff;
}

.field-box label {
    display: block;
    font-size: 0.72rem;
    color: var(--color-text-faint);
    margin-bottom: 0.2rem;
}

.field-box input,
.field-box select,
.field-box textarea {
    border: none;
    outline: none;
    width: 100%;
    padding: 0;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--color-text);
    background: transparent;
    resize: vertical;
}

.field-stack {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

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

.field-hint {
    font-size: 0.75rem;
    color: var(--color-text-faint);
    margin: 0.35rem 0 0;
}

/* Buttons */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--color-accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-full);
    padding: 0.65rem 1.6rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}

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

/* Tables */
table.data-table {
    width: 100%;
    border-collapse: collapse;
}

table.data-table th,
table.data-table td {
    text-align: left;
    padding: 0.65rem 0.5rem;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.88rem;
}

table.data-table th {
    color: var(--color-text-faint);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

table.data-table tr:last-child td { border-bottom: none; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.6rem;
    border-radius: var(--radius-full);
    background: var(--color-accent-soft);
    color: var(--color-accent-dark);
    font-size: 0.72rem;
    font-weight: 600;
}

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

.link-danger {
    color: var(--color-danger);
    text-decoration: none;
    font-size: 0.82rem;
}

.section-title {
    font-size: 1rem;
    font-weight: 700;
    margin: 0 0 0.75rem;
}

.section-title:not(:first-child) {
    margin-top: 1.5rem;
}

.empty-hint {
    color: var(--color-text-faint);
    font-size: 0.85rem;
}

/* Row actions */
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.card-header h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
}

.row-actions {
    display: flex;
    gap: 0.4rem;
    justify-content: flex-end;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    background: #fff;
    color: var(--color-text-muted);
    cursor: pointer;
    text-decoration: none;
    padding: 0;
}

.icon-btn:hover { background: var(--color-bg); }

.icon-btn.danger:hover {
    background: var(--color-danger-bg);
    color: var(--color-danger);
    border-color: var(--color-danger-bg);
}

/* Modal dialogs */
dialog.modal {
    border: none;
    border-radius: var(--radius-lg);
    padding: 0;
    width: 92%;
    max-width: 560px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

dialog.modal::backdrop {
    background: rgba(15, 23, 42, 0.45);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-muted);
    font-size: 1.3rem;
    line-height: 1;
    padding: 0.2rem;
}

.modal-body {
    padding: 1.5rem;
    max-height: 65vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 1rem 1.5rem 1.5rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.btn-secondary {
    background: #fff;
    border: 1px solid var(--color-border);
    color: var(--color-text);
    border-radius: var(--radius-full);
    padding: 0.6rem 1.4rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}

/* View toggle (list / board) */
.view-toggle {
    display: inline-flex;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    padding: 0.2rem;
    background: #fff;
}

.view-toggle button,
.view-toggle a {
    border: none;
    background: none;
    padding: 0.4rem 1rem;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-muted);
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

.view-toggle button.active,
.view-toggle a.active {
    background: var(--color-accent);
    color: #fff;
}

/* Board (canvas) view: intentionally breaks out of .page's max-width to use the full window */
.board-full {
    width: 100%;
    padding: 0 2rem 2rem;
}

.board-viewport {
    position: relative;
    height: calc(100vh - 220px);
    min-height: 420px;
    overflow: hidden;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background-color: #fafafa;
    background-image: radial-gradient(circle, #dcdce0 1px, transparent 1px);
    background-size: 22px 22px;
    cursor: grab;
    touch-action: none;
}

.board-viewport.is-panning { cursor: grabbing; }

.board-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 2600px;
    height: 1500px;
    transform-origin: 0 0;
}

.board-edges {
    position: absolute;
    top: 0;
    left: 0;
    overflow: visible;
    pointer-events: none;
}

.board-node {
    position: absolute;
    cursor: grab;
    user-select: none;
    border-radius: var(--radius-md);
    padding: 0.55rem 0.85rem;
    font-size: 0.82rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--color-border);
    background: #fff;
    min-width: 150px;
    white-space: nowrap;
}

.board-node:active { cursor: grabbing; }

.board-node.family-node {
    background: var(--color-accent);
    color: #fff;
    font-weight: 700;
    border-color: var(--color-accent-dark);
}

.board-node.person-node .role-tag {
    display: block;
    font-size: 0.68rem;
    color: var(--color-text-faint);
    font-weight: 600;
    margin-top: 0.1rem;
}

.board-controls {
    position: absolute;
    right: 0.85rem;
    bottom: 0.85rem;
    display: flex;
    gap: 0.4rem;
}

/* Birthday timeline */
.timeline-month {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-faint);
    margin: 1.75rem 0 0.5rem;
}

.timeline-month:first-child { margin-top: 0; }

.timeline {
    position: relative;
    padding-left: 1.5rem;
    border-left: 2px solid var(--color-border);
}

.timeline-item {
    position: relative;
    padding: 0.6rem 0;
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: calc(-1.5rem - 5px);
    top: 1.1rem;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-text-faint);
}

.timeline-item.is-today::before {
    background: var(--color-accent);
    box-shadow: 0 0 0 4px var(--color-accent-soft);
}

.timeline-item.is-past {
    opacity: 0.5;
}

.timeline-date {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-muted);
    width: 3.2rem;
    flex-shrink: 0;
}

.timeline-name {
    font-size: 0.92rem;
}

.timeline-age {
    font-size: 0.8rem;
    color: var(--color-text-faint);
}

/* Alerts */
.alert {
    padding: 0.6rem 0.9rem;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.alert-error { background: var(--color-danger-bg); color: var(--color-danger); }
.alert-success { background: var(--color-success-bg); color: var(--color-success); }

/* Auth (login) card, centered */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.auth-card {
    width: 100%;
    max-width: 320px;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 2rem;
}

.auth-card .app-header__brand {
    justify-content: center;
    margin-bottom: 1.5rem;
    font-size: 1.15rem;
}

.auth-card h1 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0 0 1rem;
    text-align: center;
}

.auth-card label {
    display: block;
    margin-top: 1rem;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.auth-card input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    margin-top: 0.3rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
}

.auth-card .btn-primary {
    width: 100%;
    margin-top: 1.5rem;
}

/* Small screens: tighter spacing so content isn't cramped against the edges */
@media (max-width: 640px) {
    .app-header__top-inner,
    .app-header__tabs-inner {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .page {
        padding: 1.5rem 1rem;
    }

    .board-full {
        padding: 0 1rem 1.5rem;
    }

    .page-header h1 {
        font-size: 1.5rem;
    }

    dialog.modal {
        width: 96%;
        max-height: 90vh;
    }

    .modal-body {
        padding: 1.25rem;
    }
}
