/* ===== YourTrip — base: reset, tipografia, layout della shell, utility ===== */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    line-height: var(--lh-base);
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: 'cv11', 'ss01';
    overflow: hidden; /* lo scroll avviene in .shell__scroll */
}
img, svg, video, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; }
h1, h2, h3, h4, h5, h6, p, ul, ol, figure, blockquote, dl, dd { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
hr { border: 0; border-top: var(--bw) solid var(--border); margin: var(--sp-6) 0; }
[hidden] { display: none !important; }
::selection { background: var(--accent-soft); color: var(--text); }

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

/* Scrollbar sobria */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 3px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Tipografia ---------- */
.h1, h1 { font-size: var(--fs-2xl); line-height: var(--lh-tight); font-weight: var(--fw-bold); letter-spacing: var(--tracking-tight); }
.h2, h2 { font-size: var(--fs-xl); line-height: var(--lh-tight); font-weight: var(--fw-bold); letter-spacing: var(--tracking-tight); }
.h3, h3 { font-size: var(--fs-lg); line-height: var(--lh-snug); font-weight: var(--fw-semibold); letter-spacing: -0.01em; }
.h4, h4 { font-size: var(--fs-md); line-height: var(--lh-snug); font-weight: var(--fw-semibold); }
.micro { font-size: var(--fs-micro); font-weight: var(--fw-semibold); text-transform: uppercase; letter-spacing: var(--tracking-micro); color: var(--text-2); }
.lead { font-size: var(--fs-md); color: var(--text-2); line-height: var(--lh-base); }
.text-xs { font-size: var(--fs-xs); }
.text-sm { font-size: var(--fs-sm); }
.text-md { font-size: var(--fs-md); }
.text-lg { font-size: var(--fs-lg); }
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.strong { font-weight: var(--fw-semibold); }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); font-size: max(0.92em, var(--fs-xs)); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.prewrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.text-ok { color: var(--ok); }
.text-warn { color: var(--warn); }
.text-danger { color: var(--danger); }
.text-accent { color: var(--accent-text); }

/* ---------- Utility di layout (poche, documentate in ARCHITECTURE.md) ---------- */
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack-xs { display: flex; flex-direction: column; gap: var(--sp-1); }
.stack-sm { display: flex; flex-direction: column; gap: var(--sp-2); }
.stack-lg { display: flex; flex-direction: column; gap: var(--sp-8); }
.row { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.row-sm { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); min-width: 0; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.shrink-0 { flex-shrink: 0; }
.ml-auto { margin-left: auto; }
.grid { display: grid; gap: var(--sp-4); }
.grid-2 { display: grid; gap: var(--sp-4); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: var(--sp-4); grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { display: grid; gap: var(--sp-4); grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.mt-2 { margin-top: var(--sp-2); } .mt-4 { margin-top: var(--sp-4); } .mt-6 { margin-top: var(--sp-6); } .mt-8 { margin-top: var(--sp-8); }
.mb-2 { margin-bottom: var(--sp-2); } .mb-4 { margin-bottom: var(--sp-4); } .mb-6 { margin-bottom: var(--sp-6); }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

@media (max-width: 1023px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 767px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } .grid-auto { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Shell ---------- */
.shell {
    display: grid;
    grid-template-columns: var(--nav-w) minmax(0, 1fr);
    height: 100vh;
    height: 100dvh;
}

/* Barra di navigazione laterale */
.sidenav {
    display: flex;
    flex-direction: column;
    gap: var(--sp-1);
    background: var(--surface);
    border-right: var(--bw) solid var(--border);
    padding: var(--sp-5) var(--sp-3) var(--sp-4);
    min-height: 0;
    overflow-y: auto;
    z-index: var(--z-nav);
}
.brand {
    display: inline-flex; align-items: center; gap: var(--sp-2);
    font-size: var(--fs-md); font-weight: var(--fw-bold); letter-spacing: -0.02em;
    color: var(--text); padding: 0 var(--sp-3);
}
.brand:hover { text-decoration: none; }
.brand__mark {
    width: 26px; height: 26px; border-radius: 7px; background: var(--ink); color: var(--on-ink);
    display: inline-flex; align-items: center; justify-content: center; font-size: 13px;
}
.sidenav__trip {
    display: flex; align-items: center; gap: var(--sp-2);
    margin: var(--sp-5) 0 var(--sp-4);
    padding: var(--sp-3);
    border: var(--bw) solid var(--border);
    border-radius: var(--r);
    color: var(--text);
    background: var(--surface);
    transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.sidenav__trip:hover { background: var(--surface-hover); text-decoration: none; }
.sidenav__trip-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.sidenav__trip-label { font-size: var(--fs-micro); font-weight: var(--fw-semibold); text-transform: uppercase; letter-spacing: var(--tracking-micro); color: var(--text-2); }
.sidenav__trip-name { font-size: var(--fs-sm); font-weight: var(--fw-semibold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidenav__trip .stop-strip { margin-top: 6px; }
.sidenav__trip > .fa-solid { color: var(--text-3); font-size: 12px; }
.sidenav__nav { display: flex; flex-direction: column; gap: 2px; }
.sidenav__footer { margin-top: auto; padding-top: var(--sp-4); display: flex; flex-direction: column; gap: 2px; border-top: var(--bw) solid var(--border); }

.navlink {
    display: flex; align-items: center; gap: var(--sp-3);
    height: 40px; padding: 0 var(--sp-3);
    border-radius: var(--r-sm);
    color: var(--text-2);
    font-size: var(--fs-sm); font-weight: var(--fw-medium);
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
    width: 100%; text-align: left;
}
.navlink:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.navlink .fa-solid { width: 18px; text-align: center; font-size: 15px; }
.navlink[aria-current="page"] { background: var(--surface-sunken); color: var(--text); font-weight: var(--fw-semibold); }
.navlink__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Area principale */
.shell__main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
    display: flex; align-items: center; gap: var(--sp-4);
    min-height: var(--topbar-h);
    padding: var(--sp-3) var(--content-pad);
    border-bottom: var(--bw) solid var(--border);
    background: var(--bg);
    z-index: var(--z-topbar);
}
.topbar__heading { display: flex; flex-direction: column; justify-content: center; min-width: 0; flex: 1; }
.topbar__title { font-size: var(--fs-lg); font-weight: var(--fw-bold); letter-spacing: -0.01em; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .topbar__back { display: none; }
.topbar__tools { display: flex; align-items: center; gap: var(--sp-2); }
.topbar__tools:empty { display: none; }
.topbar__actions { display: flex; align-items: center; gap: 2px; }

.crumbs { display: flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--text-2); min-width: 0; margin-bottom: 2px; }
.crumbs:empty { display: none; }
.crumbs a { color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.crumbs a:hover { color: var(--text); }
.crumbs__sep { color: var(--text-3); font-size: 10px; }
.crumbs .stop-dot { width: 8px; height: 8px; }

.shell__scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
.yt-view {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: var(--sp-8) var(--content-pad) var(--sp-16);
}
/* Viste a tutta altezza (mappa): niente padding/larghezza massima, niente scroll esterno */
.shell.is-full .shell__scroll { overflow: hidden; display: flex; flex-direction: column; }
.yt-view--full { max-width: none; padding: 0; margin: 0; height: 100%; width: 100%; flex: 1; min-height: 0; position: relative; }

/* Barra in basso (mobile) */
.bottomnav { display: none; }

/* ---------- Tablet: nav a sole icone ---------- */
@media (max-width: 1023px) and (min-width: 768px) {
    .shell { grid-template-columns: var(--nav-w-compact) minmax(0, 1fr); }
    .sidenav { padding: var(--sp-4) var(--sp-2); align-items: center; }
    .brand { padding: 0; }
    .brand__text, .navlink__label, .sidenav__trip-text, .sidenav__trip > .fa-solid { display: none; }
    .sidenav__trip { justify-content: center; padding: var(--sp-2); width: 48px; height: 48px; margin: var(--sp-4) 0; }
    .sidenav__trip-icon { display: inline-flex !important; }
    .navlink { justify-content: center; padding: 0; width: 48px; height: 44px; }
    .navlink .fa-solid { font-size: 17px; }
    .sidenav__footer { align-items: center; }
    :root { --content-pad: var(--sp-6); }
}
.sidenav__trip-icon { display: none; color: var(--text-2); }

/* ---------- Mobile: barra in basso ---------- */
@media (max-width: 767px) {
    :root { --content-pad: var(--sp-4); }
    body { font-size: 15px; }
    .shell { grid-template-columns: minmax(0, 1fr); }
    .sidenav { display: none; }
    .topbar { min-height: var(--topbar-h-mobile); padding: var(--sp-2) var(--sp-4); gap: var(--sp-2); }
    .topbar__title { font-size: var(--fs-md); }
    .topbar .topbar__back { display: inline-flex; }
    .topbar .topbar__back[hidden] { display: none; }
    /* Mobile: solo l'ultimo antenato (es. il nome del viaggio sopra il titolo) */
    .crumbs > *:not(:last-child) { display: none; }
    .crumbs a { max-width: 100%; }
    .topbar__tools .btn span { display: none; }
    .topbar__tools .btn { padding: 0; width: 40px; justify-content: center; }
    .shell__main { padding-bottom: calc(var(--bottomnav-h) + var(--safe-bottom)); }
    .yt-view { padding: var(--sp-5) var(--content-pad) var(--sp-12); }
    .h1, h1 { font-size: var(--fs-xl); }
    .h2, h2 { font-size: var(--fs-lg); }
    .bottomnav {
        display: grid; grid-template-columns: repeat(5, 1fr);
        position: fixed; left: 0; right: 0; bottom: 0;
        height: calc(var(--bottomnav-h) + var(--safe-bottom));
        padding-bottom: var(--safe-bottom);
        background: var(--surface);
        border-top: var(--bw) solid var(--border);
        z-index: var(--z-nav);
    }
    .bottomnav__item {
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
        color: var(--text-2); font-size: var(--fs-xs); font-weight: var(--fw-medium);
        min-width: 0;
    }
    .bottomnav__item .fa-solid { font-size: 18px; }
    .bottomnav__item:hover { text-decoration: none; color: var(--text); }
    .bottomnav__item[aria-current="page"] { color: var(--text); }
    .bottomnav__item[aria-current="page"] .fa-solid { color: var(--accent); }
    .bottomnav__label { font-size: var(--fs-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
}

/* Stampa: solo il contenuto */
@media print {
    body { overflow: visible; background: #fff; }
    .sidenav, .topbar, .bottomnav, .toasts { display: none !important; }
    .shell { display: block; height: auto; }
    .shell__scroll { overflow: visible; }
}
