:root {
    --ink: #1c1a17;
    --ink-soft: #4a453e;
    --parchment: #f5f1e8;
    --parchment-2: #ece5d6;
    --card: #fffdf8;
    --gold: #b08543;
    --gold-deep: #8a6630;
    --stone: #6b6459;
    --line: #d9d0bd;
    --danger: #a23b2d;
    --shadow: 0 10px 30px rgba(28, 26, 23, 0.14);
    --radius: 14px;
    --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--sans);
    color: var(--ink);
    background: var(--parchment);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Full-bleed map page: no scroll, header floats over map */
body.map-page {
    overflow: hidden;
}

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

h1, h2, h3 {
    font-family: var(--serif);
    font-weight: 600;
    line-height: 1.15;
    color: var(--ink);
    margin: 0 0 .5em;
}
h1 { font-size: clamp(2rem, 4vw, 3rem); }
h2 { font-size: clamp(1.5rem, 3vw, 2rem); }

/* ---------- Header ---------- */
.site-header {
    background: var(--ink);
    color: var(--parchment);
    border-bottom: 3px solid var(--gold);
}
.site-header__inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: .85rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .6rem; color: var(--parchment); }
.brand:hover { text-decoration: none; }
.brand__mark { color: var(--gold); font-size: 1.6rem; line-height: 1; }
.brand__name { font-family: var(--serif); font-size: 1.5rem; font-weight: 700; letter-spacing: .5px; }
.site-nav { display: flex; gap: 1.4rem; flex-wrap: wrap; }
.site-nav a { color: var(--parchment); font-weight: 500; font-size: .95rem; opacity: .9; }
.site-nav a:hover { color: #fff; opacity: 1; text-decoration: none; }

/* On the map page, the header floats translucently over the map */
body.map-page .site-header {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 1200;
    background: rgba(28, 26, 23, 0.55);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom-color: rgba(176, 133, 67, 0.6);
}

/* ---------- Main / Footer ---------- */
.site-main { flex: 1 0 auto; }
body:not(.map-page) .site-main {
    max-width: 1180px;
    margin: 0 auto;
    padding: 2.5rem 1.5rem;
    width: 100%;
}
.site-footer {
    background: var(--ink);
    color: rgba(245, 241, 232, 0.7);
    font-size: .82rem;
}
body.map-page .site-footer { display: none; }
.site-footer__inner {
    max-width: 1180px; margin: 0 auto; padding: 1rem 1.5rem;
    display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .6rem 1.15rem;
    border-radius: 999px;
    border: 1px solid transparent;
    font-family: var(--sans); font-weight: 600; font-size: .92rem;
    cursor: pointer; transition: all .15s ease; text-decoration: none;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn--primary { background: var(--gold); color: #fff; }
.btn--primary:hover { background: var(--gold-deep); color: #fff; }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn--ghost:hover { background: var(--parchment-2); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { background: #832f24; color: #fff; }
.btn--sm { padding: .35rem .8rem; font-size: .82rem; }

/* ---------- Cards / grid ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.75rem; }
.page-head p { color: var(--ink-soft); margin: .25rem 0 0; }

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}
.castle-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    display: flex; flex-direction: column;
    transition: transform .18s ease, box-shadow .18s ease;
}
.castle-card:hover { transform: translateY(-4px); box-shadow: 0 16px 40px rgba(28,26,23,.2); text-decoration: none; }
.castle-card__img { aspect-ratio: 3 / 2; background: var(--parchment-2) center/cover no-repeat; }
.castle-card__body { padding: 1rem 1.15rem 1.25rem; }
.castle-card__title { font-family: var(--serif); font-size: 1.45rem; font-weight: 600; color: var(--ink); margin: 0 0 .15rem; }
.castle-card__meta { color: var(--stone); font-size: .85rem; }
.castle-card__desc { color: var(--ink-soft); font-size: .9rem; margin-top: .6rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

.badge {
    display: inline-block; padding: .2rem .65rem; border-radius: 999px;
    font-size: .74rem; font-weight: 600; letter-spacing: .3px;
    background: var(--parchment-2); color: var(--gold-deep); border: 1px solid var(--line);
}

/* ---------- Filters ---------- */
.filter-bar { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1.75rem; align-items: end; }
.filter-bar .field { display: flex; flex-direction: column; gap: .25rem; }
.filter-bar label { font-size: .78rem; font-weight: 600; color: var(--stone); text-transform: uppercase; letter-spacing: .4px; }

/* ---------- Forms ---------- */
.form-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 2rem; box-shadow: var(--shadow); max-width: 760px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.1rem 1.25rem; }
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group.full { grid-column: 1 / -1; }
label.control-label, .form-group > label { font-weight: 600; font-size: .88rem; color: var(--ink); }
input[type=text], input[type=url], input[type=number], input[type=search], textarea, select {
    font-family: var(--sans); font-size: .95rem; color: var(--ink);
    padding: .6rem .75rem; border: 1px solid var(--line); border-radius: 10px;
    background: #fff; width: 100%; transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(176,133,67,.18); }
textarea { min-height: 130px; resize: vertical; }
.form-actions { display: flex; gap: .75rem; margin-top: 1.5rem; }
.text-danger, .field-validation-error { color: var(--danger); font-size: .82rem; }
.validation-summary-errors { color: var(--danger); background: #f7e7e3; border: 1px solid #e4b7ae; border-radius: 10px; padding: .75rem 1rem; margin-bottom: 1rem; }
.validation-summary-errors ul { margin: 0; padding-left: 1.1rem; }

/* ---------- Details page ---------- */
.detail-hero { position: relative; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); margin-bottom: 1.5rem; }
.detail-hero img { width: 100%; max-height: 460px; object-fit: cover; display: block; }
.detail-hero__overlay { position: absolute; inset: auto 0 0 0; padding: 2rem 1.75rem 1.25rem; background: linear-gradient(to top, rgba(28,26,23,.85), transparent); color: #fff; }
.detail-hero__overlay h1 { color: #fff; margin: 0; }
.detail-hero__overlay .meta { color: rgba(255,255,255,.85); }
.detail-layout { display: grid; grid-template-columns: 2fr 1fr; gap: 2rem; align-items: start; }
.fact-list { list-style: none; margin: 0; padding: 0; }
.fact-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.fact-list dt, .fact-list .k { color: var(--stone); font-size: .85rem; }
.fact-list .v { font-weight: 600; text-align: right; }

/* Google Maps quick-open icon in the facts list */
.maps-link {
    display: inline-flex; align-items: center; justify-content: center;
    margin-left: .4rem; width: 1.5rem; height: 1.5rem; border-radius: 6px;
    font-size: 1rem; line-height: 1; text-decoration: none;
    color: var(--gold-deep); background: var(--parchment-2, rgba(176,133,67,.12));
    border: 1px solid var(--line); vertical-align: middle;
    transition: background .15s ease, transform .15s ease;
}
.maps-link:hover { background: var(--gold); color: #fff; transform: translateY(-1px); }

/* Website reachability indicator */
.link-status { display: inline-block; margin-left: .5rem; font-size: .72rem; font-weight: 600; }
.link-status--ok { color: #2e7d32; }
.link-status--down { color: #c0392b; }

/* Small, unobtrusive version tag (see _Version partial) */
.app-version { font-size: .7rem; letter-spacing: .4px; color: var(--stone); opacity: .7; }

/* Admin / edit-mode toggle (owner only) */
.admin-toggle {
    display: inline-flex; align-items: center; gap: .4rem;
    font-size: .82rem; font-weight: 600; padding: .25rem .65rem;
    border-radius: 999px; border: 1px solid var(--line);
}
.admin-toggle:hover { text-decoration: none; background: rgba(0,0,0,.04); }
.admin-toggle__dot { width: .55rem; height: .55rem; border-radius: 50%; background: currentColor; }
.admin-toggle.is-on { color: #2e7d32; }
.admin-toggle.is-off { color: #b06a2c; }

/* Inline alerts (e.g. photo upload feedback) */
.alert { padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-size: .92rem; border: 1px solid transparent; }
.alert--error { background: #fdecea; color: #a32419; border-color: #f5c6c0; }
.sidebar-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.4rem; box-shadow: var(--shadow); }
.photo-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: .75rem; margin-top: 1rem; }
.photo-gallery figure { margin: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.photo-gallery img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
.photo-gallery figcaption { padding: .4rem .5rem; font-size: .75rem; color: var(--stone); display: flex; justify-content: space-between; align-items: center; gap: .3rem; }
.mini-map { height: 280px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }

/* Clickable gallery thumbnails */
.photo-thumb { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; }
.photo-thumb:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.photo-actions { display: flex; gap: .3rem; }

/* Inline photo-property edit form */
.photo-edit { display: grid; gap: .5rem; padding: .6rem .7rem .8rem; border-top: 1px solid var(--line); background: var(--parchment-2, rgba(176,133,67,.06)); }
.photo-edit label { display: flex; flex-direction: column; gap: .2rem; font-size: .72rem; font-weight: 600; color: var(--stone); text-transform: uppercase; letter-spacing: .3px; }
.photo-edit input { font-size: .9rem; padding: .35rem .5rem; }
.photo-edit__actions { display: flex; gap: .4rem; margin-top: .2rem; }

/* Back icon in the breadcrumb */
.back-link {
    display: inline-flex; align-items: center; justify-content: center;
    width: 1.6rem; height: 1.6rem; margin-right: .5rem; border-radius: 7px;
    font-size: 1.1rem; line-height: 1; text-decoration: none;
    color: var(--gold-deep); background: var(--parchment-2, rgba(176,133,67,.12));
    border: 1px solid var(--line); vertical-align: middle;
    transition: background .15s ease, transform .15s ease;
}
.back-link:hover { background: var(--gold); color: #fff; transform: translateX(-2px); }

/* Photo lightbox / slideshow */
.lightbox {
    position: fixed; inset: 0; z-index: 2000;
    display: flex; align-items: center; justify-content: center;
    background: rgba(17, 15, 12, .92);
    padding: clamp(1rem, 4vw, 3rem);
}
.lightbox[hidden] { display: none; }
.lightbox__stage { margin: 0; display: flex; flex-direction: column; align-items: center; gap: .8rem; max-width: 100%; max-height: 100%; }
.lightbox__img {
    max-width: min(1100px, 92vw); max-height: 80vh; width: auto; height: auto;
    object-fit: contain; border-radius: 8px; box-shadow: 0 20px 60px rgba(0,0,0,.5); background: #000;
}
.lightbox__caption { color: #f5f1e8; text-align: center; font-size: .9rem; max-width: min(1100px, 92vw); }
.lightbox__cap-text { display: block; font-weight: 600; }
.lightbox__meta { display: block; margin-top: .2rem; font-size: .8rem; color: rgba(245,241,232,.7); }
.lightbox__meta a { color: var(--gold); text-decoration: underline; }
.lightbox__counter { position: absolute; top: 1rem; left: 50%; transform: translateX(-50%); color: rgba(245,241,232,.7); font-size: .82rem; }
.lightbox__close, .lightbox__nav {
    position: absolute; display: grid; place-items: center;
    background: rgba(245,241,232,.1); color: #f5f1e8; border: 1px solid rgba(245,241,232,.25);
    cursor: pointer; border-radius: 50%; transition: background .15s ease;
}
.lightbox__close:hover, .lightbox__nav:hover { background: rgba(245,241,232,.25); }
.lightbox__close { top: 1rem; right: 1rem; width: 2.6rem; height: 2.6rem; font-size: 1.6rem; line-height: 1; }
.lightbox__nav { top: 50%; transform: translateY(-50%); width: 3rem; height: 3rem; font-size: 2rem; line-height: 1; }
.lightbox__nav--prev { left: clamp(.5rem, 2vw, 2rem); }
.lightbox__nav--next { right: clamp(.5rem, 2vw, 2rem); }

.prose p { margin: 0 0 1rem; font-size: 1.05rem; color: var(--ink-soft); }

.breadcrumb { font-size: .85rem; color: var(--stone); margin-bottom: 1rem; }

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