/*
 * Pitwall. Hand-written CSS, no build (docs/progetto.md § Interfaccia).
 * Dark top bar like a pit wall stand, light working area, one orange accent for actions.
 */

:root {
    --ink: #16181d;
    --ink-2: #3b3f48;
    --muted: #6b7180;
    --line: #dfe1e6;
    --line-strong: #c4c8d0;
    --paper: #f5f5f2;
    --surface: #ffffff;
    --stand: #16181d;
    --stand-2: #24272e;
    --accent: #e8590c;
    --accent-ink: #b8460a;
    --accent-soft: #fdf0e8;
    --ok: #1f7a4d;
    --ok-soft: #e7f4ed;
    --warn: #8a5a00;
    --warn-soft: #fdf4e0;
    --danger: #b42318;
    --danger-soft: #fdecea;
    --info-soft: #eaf0fb;
    --radius: 6px;
    --shadow: 0 1px 2px rgb(22 24 29 / 0.06), 0 4px 16px rgb(22 24 29 / 0.06);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font: 15px/1.5 var(--font);
    color: var(--ink);
    background: var(--paper);
    font-variant-numeric: tabular-nums;
}

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

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; font-weight: 650; }
h2 { font-size: 1.05rem; font-weight: 650; }
h3 { font-size: 0.95rem; font-weight: 600; }

p { margin: 0 0 0.75rem; }

[x-cloak] { display: none !important; }

.visually-hidden {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Top bar ---------------------------------------------------------- */

.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 1.25rem;
    padding: 0 1.25rem; height: 56px;
    background: var(--stand); color: #e9eaee;
    border-bottom: 3px solid var(--accent);
}

.brand {
    display: flex; align-items: center; gap: 0.5rem;
    color: #fff; font-weight: 700; letter-spacing: 0.02em;
}
.brand:hover { text-decoration: none; }

.topbar nav { display: flex; gap: 0.25rem; }

.topbar .nav {
    padding: 0.4rem 0.7rem; border-radius: var(--radius);
    color: #c9ccd4; font-weight: 500;
}
.topbar .nav:hover { background: var(--stand-2); color: #fff; text-decoration: none; }
.topbar .nav[aria-current="page"] { background: var(--stand-2); color: #fff; }

.topbar .search { position: relative; flex: 1; max-width: 420px; margin-left: auto; }

.topbar .search input {
    width: 100%; height: 36px; padding: 0 0.75rem;
    border: 1px solid #3a3e47; border-radius: var(--radius);
    background: var(--stand-2); color: #fff; font: inherit;
}
.topbar .search input::placeholder { color: #8d929e; }
.topbar .search input:focus { outline: none; border-color: var(--accent); }

.search-results {
    position: absolute; top: calc(100% + 6px); left: 0; right: 0;
    background: var(--surface); color: var(--ink);
    border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
    max-height: 70vh; overflow: auto;
}
.search-results:empty { display: none; }
.search-results a { display: block; padding: 0.55rem 0.8rem; color: var(--ink); border-bottom: 1px solid var(--line); }
.search-results a:hover, .search-results a:focus { background: var(--accent-soft); text-decoration: none; }
.search-results small { display: block; color: var(--muted); }
.search-results .empty, .search-results .more { padding: 0.55rem 0.8rem; color: var(--muted); }

.usermenu { position: relative; }
.usermenu > button {
    display: flex; align-items: center; gap: 0.4rem;
    height: 36px; padding: 0 0.6rem; border: 0; border-radius: var(--radius);
    background: transparent; color: #e9eaee; font: inherit; cursor: pointer;
}
.usermenu > button:hover { background: var(--stand-2); }
.usermenu .menu {
    position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px;
    background: var(--surface); color: var(--ink);
    border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 0.35rem;
}
.usermenu .menu p { margin: 0; padding: 0.4rem 0.6rem; color: var(--muted); font-size: 0.85rem; }
.usermenu .menu button {
    width: 100%; text-align: left; padding: 0.45rem 0.6rem; border: 0; border-radius: 4px;
    background: transparent; font: inherit; cursor: pointer; color: var(--ink);
}
.usermenu .menu button:hover { background: var(--paper); }

/* ---- Page ------------------------------------------------------------- */

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

.page-head {
    display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
    gap: 0.75rem 1rem; margin-bottom: 1.25rem;
}
.page-head .sub { margin: 0.25rem 0 0; color: var(--muted); }
.page-head .actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.crumbs { margin-bottom: 0.35rem; font-size: 0.85rem; color: var(--muted); }

.layout-2 { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1.25rem; align-items: start; }
.stack { display: grid; gap: 1.25rem; }

/* ---- Panels ----------------------------------------------------------- */

.panel {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.panel > header {
    display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
    padding: 0.75rem 1rem; border-bottom: 1px solid var(--line);
}
.panel > .body { padding: 1rem; }
.panel > .body.flush { padding: 0; }
.panel .note { color: var(--muted); font-size: 0.9rem; margin: 0; }

.empty-state { padding: 2rem 1rem; text-align: center; color: var(--muted); }

/* ---- Flash and alerts ------------------------------------------------- */

.flash {
    margin-bottom: 1rem; padding: 0.65rem 0.9rem; border-radius: var(--radius);
    background: var(--ok-soft); color: var(--ok); border: 1px solid #bfe0cd;
}
.alert { padding: 0.65rem 0.9rem; border-radius: var(--radius); border: 1px solid; margin-bottom: 0.75rem; }
.alert.is-danger { background: var(--danger-soft); color: var(--danger); border-color: #f4c5c0; }
.alert.is-warn { background: var(--warn-soft); color: var(--warn); border-color: #f1dca8; }
.alert.is-info { background: var(--info-soft); color: #23427a; border-color: #c9d7f2; }

/* ---- Badges and tags -------------------------------------------------- */

.badge {
    display: inline-flex; align-items: center; gap: 0.25rem;
    padding: 0.05rem 0.5rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600;
    background: var(--paper); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap;
}
.badge.is-accent { background: var(--accent-soft); color: var(--accent-ink); border-color: #f6cfb6; }
.badge.is-ok { background: var(--ok-soft); color: var(--ok); border-color: #bfe0cd; }
.badge.is-warn { background: var(--warn-soft); color: var(--warn); border-color: #f1dca8; }
.badge.is-danger { background: var(--danger-soft); color: var(--danger); border-color: #f4c5c0; }
.badge.is-info { background: var(--info-soft); color: #23427a; border-color: #c9d7f2; }

.tags { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }

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

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
    height: 36px; padding: 0 0.9rem; border-radius: var(--radius);
    border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
    font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--paper); text-decoration: none; }
.btn.is-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.is-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn.is-danger { color: var(--danger); border-color: #f0b9b3; }
.btn.is-danger:hover { background: var(--danger-soft); }
.btn.is-small { height: 30px; padding: 0 0.6rem; font-size: 0.875rem; }
.btn.is-link { border-color: transparent; background: transparent; color: var(--accent-ink); padding: 0 0.4rem; }
.btn.is-link:hover { background: var(--accent-soft); }
.btn[disabled], .htmx-request .btn[type="submit"] { opacity: 0.6; pointer-events: none; }

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

.form { display: grid; gap: 0.9rem; }
.form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.9rem; }
.form .buttons { display: flex; gap: 0.5rem; justify-content: flex-end; }

.field { display: grid; gap: 0.3rem; }
.field > label, .field > .label { font-size: 0.85rem; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 0.8rem; color: var(--muted); }
.field .error { font-size: 0.82rem; color: var(--danger); }

input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="url"], input[type="tel"], input[type="number"], input[type="date"], select, textarea {
    width: 100%; min-height: 36px; padding: 0.4rem 0.65rem;
    border: 1px solid var(--line-strong); border-radius: var(--radius);
    background: var(--surface); color: var(--ink); font: inherit;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }

.check { display: flex; align-items: center; gap: 0.45rem; font-size: 0.92rem; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---- Filters ---------------------------------------------------------- */

.filters {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0.75rem;
    padding: 1rem; margin-bottom: 1rem;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.filters .field.wide { grid-column: span 2; }
.filters .buttons { display: flex; gap: 0.5rem; align-items: flex-end; }

.views { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin-bottom: 0.75rem; }
.views .view { display: inline-flex; align-items: center; gap: 0.2rem; }

/* ---- Tables ----------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; background: var(--surface); }
table.list th, table.list td { padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.list th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 650; background: #fafaf8; white-space: nowrap; }
table.list tbody tr:hover { background: #fbfaf7; }
table.list td.num, table.list th.num { text-align: right; }
table.list .main { font-weight: 600; color: var(--ink); }
table.list .sub { color: var(--muted); font-size: 0.85rem; }

.list-foot { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1rem; color: var(--muted); font-size: 0.9rem; }
.pager { display: flex; gap: 0.4rem; }

/* ---- Facts (definition lists) ----------------------------------------- */

dl.facts { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 0.45rem 1rem; margin: 0; }
dl.facts dt { color: var(--muted); font-size: 0.88rem; }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
.missing { color: var(--muted); font-style: italic; }

/* ---- Items (branches, contacts, contact points) ----------------------- */

.items { list-style: none; margin: 0; padding: 0; }
.items > li { padding: 0.75rem 1rem; border-bottom: 1px solid var(--line); }
.items > li:last-child { border-bottom: 0; }
.item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; }
.item-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }

.points { list-style: none; margin: 0.4rem 0 0; padding: 0; display: grid; gap: 0.3rem; }
.points li { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; font-size: 0.92rem; }
.points .value { font-family: var(--mono); font-size: 0.88rem; }
.points .origin { color: var(--muted); font-size: 0.8rem; }
.points li.is-invalid .value { text-decoration: line-through; color: var(--muted); }

/* ---- History ---------------------------------------------------------- */

.history { list-style: none; margin: 0; padding: 0; }
.history > li { padding: 0.6rem 1rem; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
.history > li:last-child { border-bottom: 0; }
.history .when { color: var(--muted); font-size: 0.8rem; }
.history .diff { margin: 0.2rem 0 0; padding: 0; list-style: none; color: var(--ink-2); }
.history .diff li { padding: 0.05rem 0; overflow-wrap: anywhere; }
.history .diff del { color: var(--muted); }

/* ---- Timeline --------------------------------------------------------- */

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline > .day { padding: 0.6rem 1rem; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
.timeline > .day:last-child { border-bottom: 0; }
.timeline summary { cursor: pointer; color: var(--ink-2); }
.facts-of-day { list-style: none; margin: 0.35rem 0 0; padding: 0; display: grid; gap: 0.3rem; }
.facts-of-day li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.6rem; padding-left: 0.6rem; border-left: 3px solid var(--line-strong); }
.facts-of-day li.is-listing_created { border-left-color: var(--ok); }
.facts-of-day li.is-listing_price_changed { border-left-color: var(--accent); }
.facts-of-day li.is-listing_removed { border-left-color: var(--muted); }
.facts-of-day .when { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.facts-of-day .what { flex: 1 1 16rem; overflow-wrap: anywhere; }
.facts-of-day .source { font-size: 0.8rem; white-space: nowrap; }

/* ---- Dialog ----------------------------------------------------------- */

dialog {
    width: min(560px, calc(100vw - 2rem)); padding: 0;
    border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(22 24 29 / 0.45); }
dialog > header { display: flex; justify-content: space-between; align-items: center; padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--line); }
dialog > .body { padding: 1.1rem; }
.close { border: 0; background: transparent; font-size: 1.4rem; line-height: 1; cursor: pointer; color: var(--muted); }

/* ---- Sign-in ---------------------------------------------------------- */

.guest {
    min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
    background:
        linear-gradient(180deg, var(--stand) 0 220px, var(--paper) 220px);
}
.guest-card {
    width: min(400px, 100%); padding: 1.75rem;
    background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.guest-card .brand { color: var(--ink); margin-bottom: 1.25rem; font-size: 1.15rem; }
.guest-card .btn { width: 100%; }
.guest-card .hint { margin: 0; color: var(--muted); font-size: 0.85rem; }

.error-page { text-align: center; padding: 4rem 1rem; }
.error-page .code { font-size: 3rem; font-weight: 750; color: var(--accent); margin: 0; }
.error-page .back { margin-top: 1rem; }

/* ---- Small screens ---------------------------------------------------- */

@media (max-width: 900px) {
    .layout-2 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
    .topbar { gap: 0.6rem; padding: 0 0.75rem; }
    .brand span { display: none; }
    .topbar nav .nav { padding: 0.4rem 0.5rem; }
    .usermenu .who { display: none; }
    .page { padding: 1rem 0.75rem 3rem; }
    .filters .field.wide { grid-column: auto; }
    dl.facts { grid-template-columns: minmax(0, 1fr); gap: 0.1rem; }
    dl.facts dd { margin-bottom: 0.5rem; }
    table.list .hide-sm { display: none; }
}

/* ---- Toast ------------------------------------------------------------ */

.toast {
    position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 50;
    padding: 0.7rem 1rem; border-radius: var(--radius);
    background: var(--stand); color: #fff; box-shadow: var(--shadow);
}

form.inline { display: inline; }

.form-page { max-width: 640px; }
.form-page > header { display: flex; justify-content: space-between; align-items: center; padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--line); }
.form-page > .body { padding: 1.1rem; }
.form-page .close { display: none; }

/* ---- Dealer page ------------------------------------------------------ */

.dealer-head .head-badges { margin-top: 0.45rem; }
.dealer-head .sub strong { color: var(--ink); }
.dealer-head .actions form { display: inline; }
.panel > header.sub-head { border-top: 1px solid var(--line); background: #fafaf8; }
.panel h2 .count { color: var(--muted); font-weight: 500; font-size: 0.9rem; margin-left: 0.25rem; }
.notes { white-space: pre-line; }
.point-actions { display: inline-flex; flex-wrap: wrap; gap: 0.1rem; margin-left: auto; }
.items .points { margin-bottom: 0.25rem; }

.save-view { display: inline-flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.save-view input[type="text"] { width: 220px; min-height: 30px; padding: 0.2rem 0.5rem; }
.save-view .error { color: var(--danger); font-size: 0.82rem; }
