/* Trama: stile dell'app. Colori, raggi e misure solo dai token (tokens.css, generato da replica/design/tokens.json);
   componenti come in replica/design/components.md. */
:root {
  --muted: var(--text-muted); --shadow: var(--sh-pop);  /* nomi usati da editor.css, preso da Filo */
  --col: 180px; --col-title: 280px; --col-add: 40px; --row-h: 34px;
  --ease-out: cubic-bezier(.2,.7,.3,1);
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font-sans); font-size: var(--fs-base-ui); line-height: 1.45; color: var(--text); background: var(--bg); }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-strong); }
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.small { font-size: var(--fs-sm); }
.error { color: var(--danger); font-size: 13px; margin: 6px 0 0; min-height: 0; }
.error:empty { display: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ic, .ic-svg { display: inline-flex; flex: none; }
.ic svg { display: block; }

/* pulsanti e campi (da Filo, bordo dei campi border-input) */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 14px; border-radius: var(--r-ctl); font-weight: 600; font-size: var(--fs-base-ui);
  border: 1px solid var(--border-input); background: var(--bg); color: var(--text); transition: background var(--t-fast); }
.btn:hover { background: var(--bg-hover); }
.btn:active { background: var(--border); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-strong); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: var(--on-danger); }
.btn.ghost { border-color: transparent; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.lg { height: 40px; border-radius: var(--r-md); }
.btn:disabled, .btn[aria-busy="true"] { opacity: .5; cursor: default; }
.danger-text { color: var(--danger); }
.icon-btn { width: 28px; height: 28px; border-radius: var(--r-ctl); display: inline-grid; place-items: center; color: var(--text-muted); flex: none; }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.input { width: 100%; height: 32px; padding: 6px 10px; border: 1px solid var(--border-input); border-radius: var(--r-lg); background: var(--bg); }
.input.sm { height: 28px; padding: 3px 8px; font-size: 13px; }
textarea.input { height: auto; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.input::placeholder { color: var(--placeholder); }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--text); }
.field input:not(.input), .field select:not(.input) { height: 32px; padding: 6px 10px; border: 1px solid var(--border-input); border-radius: var(--r-lg); background: var(--bg); font-weight: 400; }
.field-lab { font-size: 13px; font-weight: 600; margin: 4px 0; }
.hint { font-weight: 400; color: var(--text-muted); }
.row-end { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 10px; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 13px; }

/* accesso */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; background: var(--bg-soft); }
.login-card { width: 100%; max-width: 380px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-modal); padding: 28px; box-shadow: var(--sh-sm); }
.login-brand { margin: 0 0 4px; font-size: 28px; font-weight: 800; color: var(--accent-strong); }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }

/* guscio */
#app { height: 100%; display: flex; flex-direction: column; }
.topbar { height: var(--topbar); flex: none; display: flex; align-items: center; gap: 10px; padding: 0 12px; background: var(--top-bg); color: var(--on-top); }
.topbar .brand { font-weight: 800; font-size: 17px; letter-spacing: .01em; }
.topbar .spacer { flex: 1; }
.icon-btn.on-top { color: var(--on-top); }
.icon-btn.on-top:hover { background: var(--search-bg); color: var(--on-top); }
.topbar :focus-visible { outline-color: var(--side-active); }
#side-toggle { display: none; }
.me-btn { border-radius: 50%; display: inline-grid; }
.av { display: inline-grid; place-items: center; border-radius: 50%; font-weight: 700; flex: none; line-height: 1; }
.av.off { opacity: .8; }
.shell { flex: 1; display: flex; min-height: 0; }
.side { width: var(--sidebar); flex: none; background: var(--side-bg); color: var(--side-text); overflow-y: auto; padding: 10px 0 24px; }
.side :focus-visible { outline-color: var(--side-active); outline-offset: -2px; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 14px 10px; }
.space-name { color: var(--side-strong); font-weight: 800; font-size: 15px; }
.side-new { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: var(--r-ctl); color: var(--side-strong); background: var(--side-hover); font-weight: 600; font-size: 13px; }
.side-new:hover { background: var(--search-bg-focus); }
.side-error { color: var(--side-strong); font-size: 13px; padding: 0 14px; margin: 0; }
.side-error:empty { display: none; }
.side-sec { margin-top: 10px; }
.side-sec-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 10px 2px 16px; }
.side-sec-head h2 { margin: 0; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--side-text); }
.side-sec-add { width: 22px; height: 22px; border-radius: var(--r-sm); display: inline-grid; place-items: center; color: var(--side-icon); }
.side-sec-add:hover { background: var(--side-hover); color: var(--side-strong); }
.tree, .tree-sub { list-style: none; margin: 0; padding: 0; }
.tree-item { display: flex; align-items: center; gap: 4px; min-height: 30px; margin: 0 8px; padding: 4px 8px; border-radius: var(--r-ctl); cursor: pointer; font-size: 14px; }
.tree-item:hover { background: var(--side-hover); }
.tree-item.active { background: var(--side-active); color: var(--side-active-text); }
.tree-item.active:focus-visible { outline-color: var(--side-active-text); }
.tree-tog { width: 20px; height: 20px; display: inline-grid; place-items: center; color: var(--side-icon); transition: transform var(--t-fast); flex: none; }
.tree-tog.none { visibility: hidden; }
.tree-tog.open { transform: rotate(90deg); }
.tree-item.active .tree-tog, .tree-item.active .tree-ic { color: inherit; }
.tree-ic { width: 18px; display: inline-grid; place-items: center; color: var(--side-icon); flex: none; font-size: 15px; }
.tree-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-name.untitled { font-style: italic; }
.tree-add { width: 22px; height: 22px; border-radius: var(--r-sm); display: none; place-items: center; color: var(--side-icon); }
.tree-item:hover .tree-add, .tree-item:focus-within .tree-add { display: inline-grid; }
.tree-item.active .tree-add { color: inherit; }
.tree-empty { padding: 4px 16px 4px 40px; font-size: 13px; color: var(--side-text); }
.main { flex: 1; min-width: 0; overflow: auto; position: relative; }
.main:focus { outline: none; }

/* intestazione e pagine */
.page-head { min-height: 44px; display: flex; align-items: center; padding: 0 20px; border-bottom: 1px solid var(--border); }
.crumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 4px; margin: 0; padding: 0; font-size: 13px; color: var(--text-muted); }
.crumbs li + li::before { content: "/"; margin-right: 4px; color: var(--text-muted); }
.crumbs a { color: var(--text-muted); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; color: var(--text); }
.crumb-cur { color: var(--text); }
.page-body { max-width: 860px; margin: 0 auto; padding: 8px 0 80px; }
.home { max-width: 640px; margin: 64px auto; padding: 0 24px; }
.home h1 { font-size: var(--fs-page-title); font-weight: 800; margin: 0 0 8px; }
.home-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 64px 24px; color: var(--text-muted); text-align: center; }

/* database */
.dbview { padding: 24px 0 64px; }
.db-head { display: flex; align-items: center; gap: 10px; padding: 0 48px; }
.db-ic { font-size: 30px; color: var(--text-muted); display: inline-grid; }
.db-title { flex: 1; min-width: 0; border: 0; background: none; font-size: var(--fs-page-title); font-weight: 800; padding: 2px 4px; border-radius: var(--r-ctl); }
.db-title:hover:not([readonly]) { background: var(--bg-hover); }
.db-title::placeholder { color: var(--placeholder); }
.ro-tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-muted); }
.view-bar { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 12px 48px 0; border-bottom: 1px solid var(--border); }
.view-tabs { display: flex; gap: 2px; }
.view-tab { display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 6px 10px; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; }
.view-tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.view-tools { display: flex; align-items: center; gap: 8px; padding-bottom: 6px; }
.row-count { font-size: 12px; color: var(--text-muted); }
.grid-wrap { overflow-x: auto; padding-bottom: 8px; }
.grid-wrap > .grid { margin: 0 48px; }
.grid-foot { position: sticky; left: 0; padding: 0 48px; display: flex; flex-direction: column; width: min(100%, 100vw); }
.grid { display: grid; grid-template-columns: var(--cols); width: max-content; min-width: calc(100% - 96px); }
.grow { display: contents; }
.gcell { min-height: var(--row-h); border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); padding: 6px 8px; display: flex; align-items: center; gap: 6px; min-width: 0; position: relative; }
.gcell:first-child { position: sticky; left: 0; background: var(--bg); z-index: 1; box-shadow: var(--sh-frozen); }
.gh { background: var(--bg-soft); min-height: 32px; padding: 0; position: sticky; top: 0; z-index: 2; }
.gh:first-child { z-index: 3; background: var(--bg-soft); }
.gh-btn { width: 100%; height: 100%; display: flex; align-items: center; gap: 6px; padding: 6px 8px; font-size: 13px; font-weight: 600; color: var(--muted-on-soft); text-align: left; }
.gh-btn:hover { background: var(--bg-hover); }
.gh-btn:focus-visible { outline-offset: -2px; }
.gh-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gh-add { justify-content: center; }
.gpad { border-right: 0; }
.gc { cursor: default; }
.gc:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.grow:hover > .gc { background: var(--bg-hover); }
.grow.open > .gc { background: var(--sel-bg); }
.grow.flash > .gc { background: var(--sel-bg); transition: background 1s; }
.gc.err { outline: 1px solid var(--danger); outline-offset: -1px; }
.val { display: flex; align-items: center; gap: 4px; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.gcell .val { display: block; }
.gcell .val-select, .gcell .val-status, .gcell .val-multi_select, .gcell .val-person { display: flex; flex-wrap: nowrap; }
.val-number { font-variant-numeric: tabular-nums; }
.gc[data-type="number"] { justify-content: flex-end; }
.gc[data-type="title"] .val { font-weight: 600; flex: 1; }
.untitled { color: var(--text-muted); font-weight: 400; }
.open-btn { display: none; align-items: center; gap: 4px; height: 24px; padding: 0 6px; border: 1px solid var(--border-input); border-radius: var(--r-ctl); background: var(--bg); font-size: 12px; font-weight: 600; color: var(--text-muted); flex: none; }
.gc:hover .open-btn, .gc:focus .open-btn, .gc:focus-within .open-btn { display: inline-flex; }
.grid-empty { display: flex; align-items: center; gap: 12px; padding: 16px 8px; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.grid-new { display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 8px; color: var(--text-muted); text-align: left; border-bottom: 1px solid var(--border); }
.grid-new:hover { background: var(--bg-hover); color: var(--text); }
.cell-check { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.cell-editor { position: fixed; z-index: 40; background: var(--bg); box-shadow: var(--sh-pop); border-radius: var(--r-sm); }
.cell-input { display: block; width: 100%; min-height: 34px; border: 2px solid var(--accent); border-radius: var(--r-sm); padding: 5px 7px; background: var(--bg); outline: none; }
.cell-input.multi { width: 300px; resize: vertical; }
.cell-input[aria-invalid="true"] { border-color: var(--danger); }
.cell-err { color: var(--danger); font-size: 13px; padding: 0 8px; }
.cell-err:empty { display: none; }
.cell-err:not(:empty) { padding: 4px 8px; }
.skel-line, .skel-grid { background: var(--skel); border-radius: var(--r-sm); margin: 0 48px 12px; animation: skel 1.2s ease-in-out infinite; }
.skel-line { height: 32px; } .skel-line.w40 { width: 40%; } .skel-grid { height: 240px; }
@keyframes skel { 50% { opacity: .5; } }

/* etichette e persone */
.pill { display: inline-flex; align-items: center; gap: 5px; border-radius: var(--r-chip); padding: 1px 8px; font-size: var(--fs-sm); font-weight: 500; line-height: 18px; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
:root[data-contrast="alto"] .pill { box-shadow: inset 0 0 0 1px currentColor; }
.st-dot { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid currentColor; flex: none; }
.st-doing { background: linear-gradient(90deg, currentColor 50%, transparent 50%); }
.st-done { background: currentColor; }
.person { display: inline-flex; align-items: center; gap: 6px; margin-right: 6px; }
.person.off { color: var(--text-muted); }
.pill-x { display: inline-grid; place-items: center; margin-left: 2px; color: inherit; }
.swatch { width: 18px; height: 18px; border-radius: var(--r-sm); flex: none; }
.lab-grafite { background: var(--label-grafite-bg); color: var(--label-grafite-text); }
.lab-sabbia { background: var(--label-sabbia-bg); color: var(--label-sabbia-text); }
.lab-rame { background: var(--label-rame-bg); color: var(--label-rame-text); }
.lab-ocra { background: var(--label-ocra-bg); color: var(--label-ocra-text); }
.lab-oliva { background: var(--label-oliva-bg); color: var(--label-oliva-text); }
.lab-salvia { background: var(--label-salvia-bg); color: var(--label-salvia-text); }
.lab-laguna { background: var(--label-laguna-bg); color: var(--label-laguna-text); }
.lab-cielo { background: var(--label-cielo-bg); color: var(--label-cielo-text); }
.lab-indaco { background: var(--label-indaco-bg); color: var(--label-indaco-text); }
.lab-glicine { background: var(--label-glicine-bg); color: var(--label-glicine-text); }
.lab-ciclamino { background: var(--label-ciclamino-bg); color: var(--label-ciclamino-text); }
.lab-granata { background: var(--label-granata-bg); color: var(--label-granata-text); }

/* popover, menu, selettori */
.popover { position: fixed; z-index: 60; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-pop); min-width: 240px; max-width: 360px; max-height: 70vh; overflow: auto; animation: pop var(--t-med) var(--ease-out); }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }
.menu { padding: 6px 0; min-width: 200px; display: flex; flex-direction: column; }
.menu .mi, .menu > button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 0 14px; height: 32px; font-size: 14px; }
.menu .mi:hover, .menu .mi:focus-visible, .menu > button:hover { background: var(--accent); color: var(--on-accent); outline: 0; }
.menu .mi.danger { color: var(--danger); }
.opt-pick, .prop-new, .prop-edit, .date-pick { padding: 12px; display: flex; flex-direction: column; gap: 8px; width: 300px; }
.opt-chosen { display: flex; flex-wrap: wrap; gap: 4px; }
.opt-chosen:empty { display: none; }
.opt-list { display: flex; flex-direction: column; max-height: 280px; overflow: auto; }
.opt-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 32px; padding: 0 8px; border-radius: var(--r-ctl); cursor: pointer; text-align: left; }
.opt-row:hover, .opt-row.act { background: var(--bg-hover); }
.opt-row.act { outline: 2px solid var(--accent); outline-offset: -2px; }
.opt-row[aria-selected="true"] { background: var(--sel-bg); }
.opt-group { font-size: 12px; font-weight: 700; color: var(--text-muted); padding: 6px 8px 2px; }
.opt-empty { color: var(--text-muted); padding: 8px; font-size: 13px; }
.pop-title { margin: 0; font-size: 14px; font-weight: 700; }
.type-list { display: flex; flex-direction: column; max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: var(--r-lg); padding: 4px; }
.type-opt { display: flex; align-items: center; gap: 8px; min-height: 30px; padding: 0 8px; border-radius: var(--r-ctl); text-align: left; color: var(--text); }
.type-opt .ic { color: var(--text-muted); }
.type-opt:hover { background: var(--bg-hover); }
.type-opt[aria-selected="true"] { background: var(--sel-bg); font-weight: 600; }
.prop-cfg { display: flex; flex-direction: column; gap: 6px; }
.opt-edit { display: flex; flex-direction: column; gap: 6px; }
.opt-edit-row { display: flex; align-items: center; gap: 6px; }
.opt-edit-row .input { min-width: 0; }

/* modale */
.modal-back { position: fixed; inset: 0; background: var(--scrim); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade var(--t-med) ease-out; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--bg); border-radius: var(--r-modal); width: 100%; max-width: 520px; max-height: 88vh; display: flex; flex-direction: column; box-shadow: var(--sh-pop); }
.modal.wide { max-width: 720px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px 6px; }
.modal-head h2 { margin: 0; font-size: var(--fs-modal); font-weight: 700; }
.modal-body { padding: 10px 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { padding: 12px 22px 18px; display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.modal-foot .error { margin: 0 auto 0 0; }
.confirm-text { margin: 0; }
.newdb { display: flex; flex-direction: column; gap: 14px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab { padding: 8px 12px; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.tpl-card { display: flex; flex-direction: column; gap: 4px; padding: 12px; border: 1px solid var(--border-input); border-radius: var(--r-card); text-align: left; }
.tpl-card:hover { background: var(--bg-hover); }
.tpl-card[aria-checked="true"] { background: var(--sel-bg); border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.tpl-ic { font-size: 22px; }
.tpl-sub { font-size: 13px; color: var(--text); }
.tpl-props { font-size: 12px; color: var(--text-muted); }

/* pannello della voce */
.row-panel { position: fixed; top: var(--topbar); right: 0; bottom: 0; width: min(560px, 100vw); background: var(--bg); box-shadow: var(--sh-panel); z-index: 30; display: flex; flex-direction: column; animation: panel var(--t-slow) var(--ease-out); border-left: 1px solid var(--border); }
@keyframes panel { from { opacity: 0; transform: translateX(12px); } }
.panel-bar { height: 44px; flex: none; display: flex; align-items: center; gap: 4px; padding: 0 10px; border-bottom: 1px solid var(--border); }
.panel-body { flex: 1; overflow: auto; }
.panel-props { padding: 4px 0 12px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.pp-list { display: flex; flex-direction: column; }
.pp-row { display: grid; grid-template-columns: 140px 1fr; align-items: center; min-height: 34px; gap: 8px; }
.pp-name { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); min-width: 0; }
.pp-name span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pp-val { min-height: 30px; padding: 4px 6px; border-radius: var(--r-ctl); display: flex; align-items: center; flex-wrap: wrap; gap: 4px; cursor: pointer; }
.pp-val:hover { background: var(--bg-hover); }
.pp-val .val { flex-wrap: wrap; white-space: normal; }
.empty-val { color: var(--text-muted); }

/* toast e suggerimenti */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(440px, calc(100vw - 32px)); display: flex; align-items: center; gap: 10px;
  background: var(--toast-bg); color: var(--toast-text); padding: 10px 14px; border-radius: var(--r-lg); box-shadow: var(--sh-pop); z-index: 80; font-size: 14px; }
.toast-act { color: var(--toast-action); font-weight: 700; }
.toast :focus-visible { outline-color: var(--toast-action); }
.tip { position: fixed; z-index: 90; background: var(--toast-bg); color: var(--toast-text); font-size: 12px; padding: 4px 8px; border-radius: var(--r-sm); pointer-events: none; max-width: 280px; }

/* telefono: barra laterale come cassetto */
@media (max-width: 760px) {
  #side-toggle { display: inline-grid; }
  .side { position: fixed; top: var(--topbar); bottom: 0; left: 0; width: 280px; z-index: 45; transform: translateX(-100%); transition: transform 200ms var(--ease-out); }
  body.side-open .side { transform: none; box-shadow: var(--sh-pop); }
  .db-head, .view-bar { padding-left: 16px; padding-right: 16px; }
  .grid-wrap > .grid { margin: 0 16px; } .grid-foot { padding: 0 16px; }
  .skel-line, .skel-grid { margin-left: 16px; margin-right: 16px; }
  :root { --col-title: 180px; --row-h: 40px; }
  .page-head { padding: 0 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
