/* Torciano access portal. Self-contained: no external fonts or CDN (CSP default-src 'self'). */
:root {
    --wine: #5c1a2a;
    --wine-dark: #45121f;
    --wine-soft: #f5e9ec;
    --gold: #a97b4b;
    --gold-light: #d9b58a;
    --ground: #eef0eb;
    --surface: #ffffff;
    --ink: #1f2420;
    --muted: #5d665f;
    --line: #dde1da;
    --line-strong: #c3c9c0;

    --danger: #a3241f;
    --danger-dark: #861b17;
    --danger-soft: #fbeceb;
    --danger-soft-text: #7f1d18;
    --info-soft: #eef1f4;
    --info-soft-text: #33414e;
    --warn-soft: #fbf1dc;
    --warn-soft-text: #7a4a07;
    --ok-soft: #e6f1e6;
    --ok-soft-text: #255c2c;

    --font-sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --font-serif: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
    --radius: 10px;
    --radius-small: 6px;
    --ring: 0 0 0 3px rgba(92, 26, 42, 0.18);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.5;
    color: var(--ink);
    background: var(--ground);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    -webkit-font-smoothing: antialiased;
}

/* ---- wordmark ---- */
.mark {
    font-family: var(--font-serif);
    font-weight: 400;
    letter-spacing: 0.06em;
    color: var(--wine);
}

.sub { color: var(--muted); }

/* ---- card ---- */
.card {
    width: calc(100% - 2rem);
    max-width: 25rem;
    margin: 0 1rem 1.5rem;
    padding: 2rem 1.9rem 1.75rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 1px 2px rgba(31, 36, 32, 0.04), 0 12px 32px -16px rgba(31, 36, 32, 0.18);
}

h1 {
    font-family: var(--font-serif);
    font-weight: 400;
    font-size: 1.6rem;
    line-height: 1.2;
    margin: 0 0 0.9rem;
    color: var(--ink);
}

h2 {
    font-family: var(--font-serif);
    font-weight: 400;
    font-size: 1.25rem;
    line-height: 1.25;
    margin: 0 0 0.6rem;
}

p { margin: 0 0 0.9rem; }

a { color: var(--wine); text-underline-offset: 0.18em; }
a:hover { color: var(--wine-dark); }

:focus-visible { outline: none; box-shadow: var(--ring); }
a:focus-visible { border-radius: 3px; }

/* ---- forms ---- */
label { display: block; font-weight: 600; font-size: 0.9rem; margin: 1.1rem 0 0.4rem; }

input[type=email], input[type=text], input[type=password], input[type=date], textarea, select {
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-small);
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

input[type=email], input[type=text], input[type=password] { width: 100%; padding: 0.7rem 0.8rem; }
input[type=date], select { padding: 0.55rem 0.7rem; }
textarea { width: 100%; padding: 0.6rem 0.75rem; font-family: ui-monospace, Consolas, monospace; font-size: 0.9rem; }

input:hover, textarea:hover, select:hover { border-color: var(--muted); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--wine); box-shadow: var(--ring); }

input.code {
    font-size: 1.6rem;
    letter-spacing: 0.35em;
    text-align: center;
    font-variant-numeric: tabular-nums;
    padding: 0.6rem 0.5rem 0.6rem 0.85rem;
}

input[type=checkbox], input[type=radio] { width: 1.05rem; height: 1.05rem; accent-color: var(--wine); }

button {
    margin-top: 1.25rem;
    width: 100%;
    padding: 0.75rem 1rem;
    font: inherit;
    font-weight: 600;
    color: #fff;
    background: var(--wine);
    border: 1px solid var(--wine);
    border-radius: var(--radius-small);
    cursor: pointer;
    transition: background-color 120ms ease, border-color 120ms ease;
}

button:hover { background: var(--wine-dark); border-color: var(--wine-dark); }

button.secondary { background: transparent; color: var(--ink); border-color: var(--line-strong); }
button.secondary:hover { background: var(--ground); border-color: var(--muted); }

button.danger { background: var(--danger); border-color: var(--danger); }
button.danger:hover { background: var(--danger-dark); border-color: var(--danger-dark); }

button.link { margin: 0; width: auto; padding: 0.35rem 0; background: none; border: 0; color: var(--muted); font-weight: 600; }
button.link:hover { background: none; color: var(--wine); }

button.small { width: auto; margin-top: 0; padding: 0.45rem 0.9rem; font-size: 0.875rem; }

.btn {
    display: inline-block;
    padding: 0.55rem 1.05rem;
    border: 1px solid var(--wine);
    border-radius: var(--radius-small);
    background: var(--wine);
    color: #fff;
    font-weight: 600;
    text-decoration: none;
}
.btn:hover { background: var(--wine-dark); color: #fff; }
.btn.secondary { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn.secondary:hover { background: var(--ground); color: var(--ink); }

/* ---- messages ---- */
.notice, .error, .warnbox {
    padding: 0.7rem 0.85rem;
    border-radius: var(--radius-small);
    border-left: 3px solid;
    font-size: 0.95rem;
}
.notice { background: var(--info-soft); color: var(--info-soft-text); border-color: #8fa0b0; }
.error { margin: 0.6rem 0 0; background: var(--danger-soft); color: var(--danger-soft-text); border-color: var(--danger); }
.warnbox { background: var(--warn-soft); color: var(--warn-soft-text); border-color: #c98a1a; font-weight: 600; }
.warnline { margin: 0.3rem 0 0; font-size: 0.8rem; color: var(--warn-soft-text); font-weight: 600; }

.hint { font-size: 0.875rem; color: var(--muted); }
form + .hint { margin-top: 1.1rem; }
.card > .hint:last-child { margin-bottom: 0; }

/* ---- choose the application ---- */
.apps { list-style: none; padding: 0; margin: 0.25rem 0 0.25rem; }
.apps li { margin: 0 0 0.6rem; }

.app {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.1rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-small);
    color: var(--ink);
    font-family: var(--font-serif);
    font-size: 1.2rem;
    text-decoration: none;
    transition: border-color 120ms ease, background-color 120ms ease;
}
.app::after {
    content: "";
    width: 0.5rem;
    height: 0.5rem;
    border-top: 2px solid var(--wine);
    border-right: 2px solid var(--wine);
    transform: rotate(45deg);
}
.app:hover { border-color: var(--wine); background: var(--wine-soft); color: var(--ink); }

.foot { font-size: 0.78rem; color: var(--muted); padding: 0.5rem 1rem 2rem; text-align: center; }

/* ---- public pages: split card (estate photo + form) ---- */
body.public { justify-content: center; padding: 2rem 0; background: #e9e6e0; }

.shell {
    display: grid;
    grid-template-columns: 1.05fr 1fr;
    width: calc(100% - 2rem);
    max-width: 60rem;
    min-height: 36rem;
    background: var(--surface);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(28, 25, 21, 0.06), 0 30px 70px -30px rgba(28, 25, 21, 0.45);
}

.panel {
    display: flex;
    align-items: flex-start;
    padding: 2.5rem 2.5rem 2.25rem;
    color: #fff;
    background:
        linear-gradient(to bottom, rgba(14, 24, 38, 0.72) 0%, rgba(14, 24, 38, 0.38) 30%, rgba(14, 24, 38, 0) 55%),
        url("/vigneto.jpg") 30% 100% / cover no-repeat, #4c6b2e;
}
.panel p { margin: 0; }
.panel .group {
    font-family: var(--font-serif);
    font-size: 1.65rem;
    line-height: 1.15;
    letter-spacing: 0.02em;
    color: var(--gold-light);
}
.panel .group::after {
    content: "";
    display: block;
    width: 2.5rem;
    height: 1px;
    margin: 0.85rem 0 0.8rem;
    background: var(--gold-light);
    opacity: 0.7;
}
.panel .lead { font-size: 1rem; font-weight: 600; color: #fff; }
.panel .blurb { margin-top: 0.35rem; max-width: 22rem; font-size: 0.92rem; line-height: 1.55; color: rgba(255, 255, 255, 0.88); }
.panel .group, .panel .lead, .panel .blurb { text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35); }

body.public .card {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: auto;
    max-width: none;
    margin: 0;
    padding: 2.5rem 2.75rem 1.5rem;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}
.card .logo { display: block; width: 100%; max-width: 12.5rem; height: auto; margin: 0 auto 1.75rem; }
.cardbody { flex: 1; display: flex; flex-direction: column; justify-content: center; width: 100%; max-width: 22rem; }
body.public h1 { text-align: center; font-size: 1.6rem; }
.cardbody > p:not(.notice):not(.error) { text-align: center; }
.cardbody > .notice { text-align: center; border-left: 0; }
body.public button.secondary { color: var(--wine); border-color: var(--wine); }
body.public button.secondary:hover { background: var(--wine-soft); }
body.public .foot { padding: 1.5rem 0 0; }

@media (max-width: 48rem) {
    body.public { justify-content: flex-start; padding: 1rem 0; }
    .shell { grid-template-columns: 1fr; min-height: 0; }
    .panel { min-height: 8.5rem; padding: 1.25rem 1.5rem; background: linear-gradient(to right, rgba(14, 24, 38, 0.75), rgba(14, 24, 38, 0.2)), url("/vigneto.jpg") 35% 68% / cover no-repeat, #4c6b2e; }
    .panel .blurb { display: none; }
    .panel .group { font-size: 1.3rem; }
    .panel .group::after { margin: 0.5rem 0; }
    body.public .card { padding: 1.75rem 1.25rem 1.25rem; }
    .card .logo { max-width: 10rem; margin-bottom: 1.25rem; }
}

/* ---- administration ---- */
body.admin { align-items: stretch; }

.adminbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.adminbar-in {
    max-width: 76rem;
    margin: 0 auto;
    padding: 0 1.25rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0 2rem;
    min-height: 3.75rem;
}

.brand-inline { display: flex; align-items: center; gap: 0.9rem; text-decoration: none; padding: 0.45rem 0; }
.brand-inline img { display: block; height: 3rem; width: auto; }
.brand-inline .sub { font-size: 0.85rem; padding-left: 0.9rem; border-left: 1px solid var(--line-strong); }

.adminnav { display: flex; flex-wrap: wrap; gap: 0 1.5rem; align-self: stretch; }
.adminnav a {
    display: flex;
    align-items: center;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    padding: 0.6rem 0 calc(0.6rem - 2px);
}
.adminnav a:hover { color: var(--ink); }
.adminnav a.on { color: var(--wine); border-bottom-color: var(--wine); }
.navout { margin-left: auto; }

.card.wide {
    align-self: center;
    max-width: 76rem;
    width: calc(100% - 2.5rem);
    margin: 1.75rem 1.25rem 1.5rem;
    padding: 1.75rem 2rem 2rem;
}

.headrow { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.75rem; margin-bottom: 0.9rem; }
.headrow h1 { margin: 0; }

.tablewrap { width: 100%; overflow-x: auto; margin: 0.75rem 0; }
table.grid { width: 100%; border-collapse: collapse; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
table.grid th, table.grid td { text-align: left; vertical-align: top; padding: 0.6rem 0.7rem; border-bottom: 1px solid var(--line); }
table.grid th { font-size: 0.8rem; font-weight: 600; color: var(--muted); border-bottom-color: var(--line-strong); background: #f7f8f5; }
table.grid tbody tr:hover td { background: #fafbf8; }
table.grid tr.off td { color: var(--muted); }
table.grid td a { font-weight: 600; text-decoration: none; }
table.grid td a:hover { text-decoration: underline; }
table.grid input[type=text], table.grid select { width: 100%; min-width: 8rem; padding: 0.45rem 0.55rem; }
table.grid td.actions { white-space: nowrap; }
table.grid td.actions form { display: inline-block; margin-right: 0.25rem; }
table.log { font-size: 0.82rem; }
td.ua { max-width: 22rem; overflow-wrap: anywhere; color: var(--muted); }
td.nowrap { white-space: nowrap; }

.tag {
    display: inline-block;
    margin: 0 0.25rem 0.2rem 0;
    padding: 0.12rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--info-soft);
    color: var(--info-soft-text);
}
.tag.ok { background: var(--ok-soft); color: var(--ok-soft-text); }
.tag.muted { background: var(--ground); color: var(--muted); }
.tag.admin { background: var(--wine-soft); color: var(--wine); }
.tag.warn { background: var(--warn-soft); color: var(--warn-soft-text); }

.form { max-width: 34rem; }
fieldset { margin: 1.4rem 0 0; padding: 0.6rem 1.1rem 1.1rem; border: 1px solid var(--line); border-radius: var(--radius-small); }
legend { font-weight: 600; font-size: 0.9rem; padding: 0 0.4rem; }
label.check { display: flex; align-items: center; gap: 0.55rem; font-weight: 400; font-size: 0.95rem; margin: 0.55rem 0 0; }

.block { margin-top: 2.25rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.buttons { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin-top: 0.75rem; }
.buttons form button { margin-top: 0; width: auto; }

.confirm {
    margin: 1.25rem 0;
    padding: 1.1rem 1.25rem;
    border: 1px solid var(--danger);
    border-left-width: 4px;
    border-radius: var(--radius-small);
    background: var(--danger-soft);
    color: var(--danger-soft-text);
}

.switches { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem; margin: 1.25rem 0; }
.switch { padding: 1.1rem 1.25rem; border: 1px solid var(--line-strong); border-top-width: 4px; border-radius: var(--radius-small); }
.switch.on { border-color: var(--ok-soft-text); background: var(--ok-soft); }
.switch .state { font-weight: 700; margin: 0 0 0.25rem; }
.switch.on .state { color: var(--ok-soft-text); }
.switch button { width: auto; }
.allform button { width: auto; }

.tabs { display: flex; gap: 1.5rem; margin-bottom: 1rem; border-bottom: 1px solid var(--line); }
.tabs a { padding: 0.5rem 0 calc(0.5rem - 2px); text-decoration: none; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a:hover { color: var(--ink); }
.tabs a.on { color: var(--wine); border-bottom-color: var(--wine); }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.6rem 1rem; margin-bottom: 0.75rem; }
.filters label { margin: 0; font-size: 0.85rem; display: flex; flex-direction: column; gap: 0.3rem; }
.filters input[type=text] { width: 11rem; padding: 0.5rem 0.6rem; }
.filters input[type=date], .filters select { padding: 0.45rem 0.55rem; }

.pager { display: flex; gap: 1.25rem; align-items: center; }

/* ---- people list ---- */
.subhead { margin: 0.3rem 0 0; color: var(--muted); }
.stats { display: flex; flex-wrap: wrap; gap: 0.75rem; margin: 0.25rem 0 1.25rem; }
.stat { display: flex; align-items: baseline; gap: 0.5rem; padding: 0.6rem 1rem; border: 1px solid var(--line); border-radius: var(--radius-small); background: #fafbf8; }
.stat .num { font-family: var(--font-serif); font-size: 1.5rem; line-height: 1; color: var(--wine); font-variant-numeric: tabular-nums; }
.stat .lbl { font-size: 0.85rem; color: var(--muted); }
.filters label.grow { flex: 1 1 14rem; }
.filters label.grow input[type=text] { width: 100%; }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: var(--radius-small); }

table.grid th.center, table.grid td.center { text-align: center; width: 6.5rem; }
table.people td { vertical-align: middle; }
table.people .who { display: block; color: var(--ink); }
table.people .who:hover { color: var(--wine); }
table.people .mail { display: block; font-size: 0.82rem; color: var(--muted); }
table.people td form { display: inline-block; margin: 0; }
table.grid tr.changed td, table.grid tr:target td { background: var(--wine-soft); }

.sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* on/off switch: a submit button (no scripts) */
button.toggle {
    position: relative;
    width: 2.75rem;
    height: 1.55rem;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: var(--line-strong);
    cursor: pointer;
    transition: background-color 120ms ease;
}
button.toggle::after {
    content: "";
    position: absolute;
    top: 0.2rem;
    left: 0.2rem;
    width: 1.15rem;
    height: 1.15rem;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    transition: transform 120ms ease;
}
button.toggle:hover { background: var(--muted); }
button.toggle.on { background: var(--ok-soft-text); }
button.toggle.on:hover { background: #1c4721; }
button.toggle.on::after { transform: translateX(1.2rem); }
tr.off button.toggle { opacity: 0.55; }

/* two-choice switch (Da dove): one form, two submit buttons */
.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 999px; padding: 2px; background: #fff; }
.segmented button {
    width: auto;
    margin: 0;
    padding: 0.25rem 0.75rem;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
}
.segmented button:hover { background: var(--ground); color: var(--ink); }
.segmented button.on { background: var(--wine); color: #fff; }
.segmented button.on:hover { background: var(--wine-dark); }
tr.off .segmented { opacity: 0.6; }

/* ---- one person ---- */
.backlink { margin: 0 0 0.5rem; font-size: 0.9rem; }
.backlink a { text-decoration: none; }
.persona-grid { display: grid; grid-template-columns: minmax(0, 1fr) 20rem; gap: 2rem; align-items: start; }
.persona-grid .form { max-width: none; }
.side { display: flex; flex-direction: column; gap: 1rem; }
.sidebox { padding: 1.1rem 1.2rem; border: 1px solid var(--line); border-radius: var(--radius-small); background: #fafbf8; }
.sidebox h2 { font-size: 1.1rem; }
.sidebox .form { max-width: none; }
.sidebox button { width: 100%; }
.sidebox .buttons form { flex: 1; }
.sidebox .buttons button { width: 100%; }
.section { margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }
.section:first-of-type { margin-top: 0.5rem; padding-top: 0; border-top: 0; }
.section h2 { margin-bottom: 0.2rem; }
.section > .hint:first-of-type { margin-bottom: 0.5rem; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
label.choice { display: flex; gap: 0.6rem; align-items: flex-start; font-weight: 400; margin: 0.5rem 0 0; padding: 0.7rem 0.85rem; border: 1px solid var(--line); border-radius: var(--radius-small); cursor: pointer; }
label.choice:hover { border-color: var(--line-strong); }
label.choice input { margin-top: 0.2rem; }
label.choice strong { display: block; }
label.choice span { display: block; font-size: 0.85rem; color: var(--muted); }
.savebar { margin-top: 1.5rem; display: flex; align-items: center; gap: 1rem; }
.savebar button { width: auto; margin: 0; padding-left: 2rem; padding-right: 2rem; }

@media (max-width: 60rem) {
    .persona-grid { grid-template-columns: 1fr; }
    .two { grid-template-columns: 1fr; }
}

@media (max-width: 40rem) {
    .card.wide { width: calc(100% - 2rem); margin: 1rem; padding: 1.25rem 1rem; }
    .adminbar-in { gap: 0 1rem; }
    .brand-inline .sub { display: none; }
    .filters input[type=text], .filters label { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}
