:root {
    --black: #1a1a1a;
    --dark-grey: #333333;
    --mid-grey: #666666;
    --light-grey: #cccccc;
    --pale-grey: #f0f0f0;
    --ice-blue: #e8f4f8;
    --ice-blue-mid: #b8dce8;
    --ice-blue-dark: #5a9db5;
    --white: #ffffff;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 14px;
    color: var(--black);
    background: var(--pale-grey);
    min-height: 100vh;
}

/* ── Layout ─────────────────────────────────────────── */

header {
    background: var(--dark-grey);
    color: var(--white);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

header h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

#app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* ── Toolbar ─────────────────────────────────────────── */

#toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

#search-scope {
    padding: 8px 12px;
    border: 1px solid var(--light-grey);
    border-radius: 4px;
    font-size: 14px;
    background: var(--white);
    cursor: pointer;
    min-width: 140px;
}

#search-scope:focus {
    outline: none;
    border-color: var(--ice-blue-dark);
    box-shadow: 0 0 0 2px var(--ice-blue);
}

#search-input {
    flex: 1;
    min-width: 200px;
    padding: 8px 12px;
    padding-right: 185px;
    border: 1px solid var(--light-grey);
    border-radius: 4px;
    font-size: 14px;
    background: var(--white);
}

#search-input::placeholder {
    color: var(--medium-grey);
    font-style: italic;
}

#search-input:focus {
    outline: none;
    border-color: var(--ice-blue-dark);
    box-shadow: 0 0 0 2px var(--ice-blue);
}

/* ── Buttons ─────────────────────────────────────────── */
div.buttonbar {
    gap: 10px;
    width: 100%;
    margin-bottom: 10px;
}

button {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition:
        background 0.15s,
        opacity 0.15s;
}

button:hover {
    opacity: 0.88;
}

button:active {
    opacity: 0.75;
}

.btn-primary {
    background: var(--ice-blue-dark);
    color: var(--white);
}
.btn-secondary {
    background: var(--mid-grey);
    color: var(--white);
}
.btn-danger {
    background: #8b3a3a;
    color: var(--white);
}
.btn-ghost {
    background: transparent;
    color: var(--ice-blue-dark);
    border: 1px solid var(--ice-blue-dark);
}
.btn-small {
    padding: 4px 10px;
    font-size: 12px;
}

/* Search input inline buttons */
.search-input-btn {
    padding: 4px 6px;
    font-size: 11px;
    border-radius: 3px;
    background: var(--ice-blue);
    border: 1px solid var(--light-grey);
    color: var(--dark-grey);
    cursor: pointer;
    transition: all 0.15s ease;
}

.search-input-btn:hover {
    background: var(--ice-blue-dark);
    color: var(--white);
    border-color: var(--ice-blue-dark);
}

.search-input-btn.active {
    background: var(--ice-blue-dark);
    color: var(--white);
    border-color: var(--ice-blue-dark);
}

.btn-in-statcard {
    padding: 2px 2px;
    font-size: 9px;
    margin-bottom: 2px;
}

/* ── Records table ───────────────────────────────────── */

#records-container {
    background: var(--white);
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

#records-count {
    padding: 10px 16px;
    background: var(--ice-blue);
    color: var(--mid-grey);
    font-size: 12px;
    border-bottom: 1px solid var(--ice-blue-mid);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    background: var(--dark-grey);
    color: var(--white);
    padding: 6px 9px;
    text-align: left;
    font-weight: 500;
    font-size: 11px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

thead th:hover {
    background: var(--mid-grey);
}

tbody tr {
    border-bottom: 1px solid var(--pale-grey);
    transition: background 0.1s;
}

tbody tr:hover {
    background: var(--ice-blue);
    cursor: pointer;
}

tbody td {
    padding: 6px 9px;
    color: var(--dark-grey);
    font-size: 13px;
}

.tag {
    display: inline-block;
    background: var(--ice-blue);
    border: 1px solid var(--ice-blue-mid);
    border-radius: 3px;
    padding: 1px 6px;
    font-size: 11px;
    color: var(--ice-blue-dark);
    margin: 1px 2px;
}

.deleted-row td {
    color: var(--light-grey);
    text-decoration: line-through;
}

/* ── Modal ───────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal {
    background: var(--white);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.22);
    width: 100%;
    max-width: 760px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modalfullwidth {
    max-width: 94vw;
}

.modal-header {
    background: var(--dark-grey);
    color: var(--white);
    padding: 14px 20px;
    border-radius: 8px 8px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--white);
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--pale-grey);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ── Form ────────────────────────────────────────────── */

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

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

label {
    font-size: 12px;
    font-weight: 600;
    color: var(--mid-grey);
    /*text-transform: uppercase;*/
    letter-spacing: 0.4px;
}

input[type="text"],
input[type="number"],
textarea,
select {
    padding: 7px 10px;
    border: 1px solid var(--light-grey);
    border-radius: 4px;
    font-size: 13px;
    background: var(--white);
    color: var(--black);
    width: 100%;
    box-sizing: border-box;
}

/* Ensure consistent height for text and number inputs */
input[type="text"],
input[type="number"] {
    height: 35px;
    line-height: 1.4;
}

/* Ensure select elements match input height */
select {
    height: 35px;
    line-height: 1.4;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url('data:image/svg+xml;utf8,<svg fill="%23666666" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 5px center;
    background-size: 20px;
    padding-right: 30px;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--ice-blue-dark);
    box-shadow: 0 0 0 2px var(--ice-blue);
}

/* Disabled/readonly inputs maintain same height */
input:disabled,
input[readonly],
select:disabled,
textarea:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: var(--pale-grey);
}

textarea {
    resize: vertical;
    min-height: 70px;
}

/* ── Variations / Array fields ───────────────────────── */

.array-field {
    border: 1px solid var(--light-grey);
    border-radius: 4px;
    padding: 8px;
    background: var(--pale-grey);
}

.array-item {
    display: flex;
    gap: 6px;
    align-items: flex-start;
    margin-bottom: 6px;
    background: var(--white);
    border: 1px solid var(--ice-blue-mid);
    border-radius: 4px;
    padding: 8px;
}

.array-item input,
.array-item textarea {
    flex: 1;
    margin: 0;
}

.array-item-fields {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.array-item-fields input {
    width: 100%;
}

.add-item-btn {
    margin-top: 4px;
    font-size: 12px;
    padding: 4px 10px;
}

/* ── Lookup dropdown ─────────────────────────────────── */

.lookup-wrapper {
    position: relative;
}

.lookup-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--white);
    border: 1px solid var(--ice-blue-mid);
    border-top: none;
    border-radius: 0 0 4px 4px;
    z-index: 500;
    max-height: 220px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.lookup-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid var(--pale-grey);
}

.lookup-item:hover {
    background: var(--ice-blue);
}

.lookup-item .match-type {
    font-size: 11px;
    color: var(--mid-grey);
    margin-left: 8px;
}

.lookup-item .person-details {
    font-size: 11px;
    color: var(--mid-grey);
    margin-top: 2px;
}

/* ── Settings panel ──────────────────────────────────── */

#settings-panel {
    background: var(--white);
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    padding: 20px;
    margin-bottom: 20px;
    display: none;
}

#settings-panel h3 {
    font-size: 14px;
    color: var(--dark-grey);
    margin-bottom: 14px;
    border-bottom: 1px solid var(--pale-grey);
    padding-bottom: 8px;
}

/* ── Dialogs ─────────────────────────────────────────── */

.dialog-box {
    background: var(--white);
    border-radius: 8px;
    padding: 28px;
    max-width: 440px;
    width: 100%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.22);
    text-align: center;
}

.dialog-box h3 {
    margin-bottom: 12px;
    color: var(--dark-grey);
}
.dialog-box p {
    color: var(--mid-grey);
    margin-bottom: 20px;
    font-size: 13px;
}
.dialog-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* ── Notifications ───────────────────────────────────── */

#notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
    display: none;
    max-width: 340px;
}

.notif-success {
    background: var(--ice-blue-dark);
    color: var(--white);
}
.notif-error {
    background: #8b3a3a;
    color: var(--white);
}
.notif-info {
    background: var(--dark-grey);
    color: var(--white);
}

/* ── Relationship Network Legend ─────────────────────── */

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    transition: opacity 0.2s ease;
}

.legend-item:hover {
    transform: scale(1.05);
    transition: transform 0.1s ease;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

/* ── Help & Documentation ───────────────────────────── */

#help-modal .modal {
    margin-right: 20px;
    margin-left: auto;
}

#help-modal .modal-body {
    scroll-behavior: smooth;
}

#help-content a[href^="#"] {
    cursor: pointer;
    text-decoration: underline;
    color: var(--ice-blue-dark);
}

#help-content a[href^="#"]:hover {
    color: var(--dark-grey);
}

/* Responsive positioning for smaller screens */
@media (max-width: 900px) {
    #help-modal .modal {
        margin-left: auto;
        margin-right: auto;
        max-width: 90vw;
    }
}

/* ── Misc ────────────────────────────────────────────── */

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--ice-blue-mid);
    border-top-color: var(--ice-blue-dark);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

hr {
    border: none;
    border-top: 1px solid var(--pale-grey);
    margin: 16px 0;
}

.hidden {
    display: none !important;
}

/* ── Statistics pane ─────────────────────────────────── */

#stats-pane {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
    align-items: center;
}

.stat-card {
    background: var(--white);
    border: 1px solid var(--light-grey);
    border-radius: 6px;
    padding: 10px 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 90px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
}

.stat-card--clickable {
    cursor: pointer;
    transition:
        transform 0.15s,
        box-shadow 0.15s;
}

.stat-card--clickable:hover {
    transform: translateY(-2px);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
    border-color: var(--ice-blue-dark);
}

.stat-card--clickable:active {
    transform: translateY(0);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
}

.stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--dark-grey);
    line-height: 1.1;
}

.stat-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--mid-grey);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-top: 3px;
}

.stat-divider {
    width: 1px;
    height: 44px;
    background: var(--light-grey);
    margin: 0 4px;
    align-self: center;
}

.stat-divider-nl {
    margin: 4px 4px;
}

#origin-stats-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

#religion-stats-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

/* ── Person Picker ───────────────────────────────────── */

.person-picker-item {
    padding: 12px;
    border: 1px solid var(--light-grey);
    border-radius: 4px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.15s;
}

.person-picker-item:hover {
    background: var(--ice-blue);
    border-color: var(--ice-blue-dark);
}

/* ── Relationship Chips ──────────────────────────────── */

.relationship-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--white);
    border: 1px solid var(--ice-blue-mid);
    border-radius: 16px;
    font-size: 12px;
    transition: all 0.15s;
}

.relationship-chip:hover {
    background: var(--ice-blue);
    border-color: var(--ice-blue-dark);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.rel-type-badge {
    display: inline-block;
    padding: 2px 6px;
    background: var(--ice-blue-dark);
    color: var(--white);
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.rel-person-name {
    color: var(--dark-grey);
    font-weight: 500;
}

/* ── Relationship Network Modal ──────────────────────── */

.network-person-card {
    padding: 16px;
    margin-bottom: 12px;
    background: var(--white);
    border: 1px solid var(--light-grey);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.network-person-card:hover {
    background: var(--ice-blue);
    border-color: var(--ice-blue-dark);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.network-person-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--dark-grey);
    margin-bottom: 8px;
}

.network-person-details {
    font-size: 11px;
    color: var(--mid-grey);
    margin-bottom: 10px;
}

.network-relationships {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.network-rel-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    color: var(--white);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-color {
    width: 20px;
    height: 12px;
    border-radius: 2px;
}
