/* Design system ripreso da "Gestionale Freelance VR" (src/styles/global.css):
   palette zinco monocromatica, IBM Plex Sans + Mono, griglia a puntini,
   etichette mono maiuscole, card con angoli a staffa. */
:root {
  color-scheme: light;

  --bg: #ffffff;
  --bg-elevated: #f4f4f5;
  --bg-input: #ffffff;
  --border: #d4d4d8;
  --border-soft: #e4e4e7;
  --text: #18181b;
  --text-muted: #71717a;
  --accent: #18181b;
  --accent-contrast: #ffffff;
  --danger: #18181b;
  --success: #3f3f46;
  --warning: #52525b;

  --grid-dot: rgba(24, 24, 27, 0.06);

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --header-height: 56px;

  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  background-color: var(--bg);
  background-image: radial-gradient(var(--grid-dot) 1px, transparent 1px);
  background-size: 22px 22px;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
code { font-family: var(--font-mono); font-size: 0.85em; }
mark { background: var(--text); color: var(--accent-contrast); padding: 0 2px; border-radius: 2px; }

h1, h2, h3 {
  line-height: 1.2;
  margin: 0 0 var(--space-3);
  font-weight: 600;
  letter-spacing: -0.01em;
}
h1 {
  position: relative;
  padding-bottom: var(--space-3);
  margin-bottom: var(--space-4);
}
h1::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  width: 72px;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent);
}
h2 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--text-muted);
}
p { margin: 0 0 var(--space-3); color: var(--text-muted); }

.muted { color: var(--text-muted); }
.mono-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

/* ---------- Layout ---------- */
.app-shell { display: flex; flex-direction: column; height: 100vh; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
  z-index: 20;
}
.app-header .brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.app-header .brand { border: 0; background: none; padding: 0; cursor: pointer; }
.app-header .brand:hover { color: var(--text); }
.app-header .brand::before {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--accent);
  flex-shrink: 0;
}

.app {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}
/* Nessun contatto selezionato: la lista occupa tutta la pagina */
body:not(.show-detail) .detail { display: none; }
body:not(.show-detail) .list-pane { border-right: 0; }
body:not(.show-detail) .list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  align-content: start;
  gap: var(--space-2);
  padding: var(--space-4);
}
body:not(.show-detail) .list-item { border-color: var(--border-soft); background: var(--bg-input); }
body:not(.show-detail) .list-item:hover { border-color: var(--accent); background: var(--bg-elevated); }
body:not(.show-detail) .empty-list { grid-column: 1 / -1; }
/* Contatto selezionato: lista a sinistra, scheda a destra */
body.show-detail .app { grid-template-columns: 240px 360px minmax(0, 1fr); }

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  overflow-y: auto;
}

.side-section { display: flex; flex-direction: column; gap: 2px; }
.side-title {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 0 var(--space-2) var(--space-2);
}

.cat-nav { display: flex; flex-direction: column; gap: 2px; }
.cat-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  border: 1px solid transparent;
  background: none;
  text-align: left;
  padding: 6px var(--space-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.95rem;
}
.cat-item:hover { color: var(--text); border-color: var(--border); background: var(--bg-input); }
.cat-item.active { color: var(--text); font-weight: 600; border-color: var(--accent); background: var(--bg-input); }
.cat-item .dot { width: 6px; height: 6px; background: var(--border); flex: none; }
.cat-item.active .dot { background: var(--accent); }
.cat-item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-item .count { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.cat-item .del { display: none; color: var(--text-muted); padding: 0 2px; }
.cat-item:hover .del { display: inline; }
.cat-item:hover .del + .count { display: none; }
.cat-item .del:hover { color: var(--text); }

.add-cat input {
  width: 100%;
  margin-top: var(--space-1);
  border: 1px dashed var(--border);
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 6px var(--space-2);
  font-size: 0.9rem;
}
.add-cat input:focus { border-style: solid; }

.tools .btn.ghost { justify-content: flex-start; }

/* Riquadro stato file */
.storage {
  margin-top: auto;
  border: 1px solid var(--border);
  background: var(--bg-input);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.storage .row { display: flex; align-items: center; gap: var(--space-2); }
.storage .status-dot { width: 8px; height: 8px; flex: none; border: 1px solid var(--text-muted); background: transparent; }
.storage .status-dot.ok { background: var(--accent); border-color: var(--accent); }
.storage .status-dot.warn { background: transparent; border-color: var(--warning); }
.storage .status-dot.err { background: transparent; border: 2px solid var(--danger); }
.storage .status-dot.busy { background: var(--text-muted); border-color: var(--text-muted); animation: pulse 1s infinite; }
.storage .file { font-family: var(--font-mono); font-weight: 500; font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.storage .sub { color: var(--text-muted); }
.storage .actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .storage .status-dot.busy { animation: none; } }

/* Mostra/nascondi barra laterale */
.header-left { display: flex; align-items: center; gap: var(--space-4); }
.sidebar-toggle {
  border: 0; background: none; padding: 0;
  font-family: var(--font-mono); font-size: 0.7rem; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted);
  text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 4px;
}
.sidebar-toggle:hover { color: var(--text); text-decoration-color: var(--accent); }
body.sidebar-hidden .app { grid-template-columns: minmax(0, 1fr); }
body.sidebar-hidden.show-detail .app { grid-template-columns: 360px minmax(0, 1fr); }
body.sidebar-hidden .sidebar { display: none; }

/* ---------- Bottoni ---------- */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-4);
  font-size: 0.95rem;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button:focus-visible, .list-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button svg, .btn svg {
  width: 16px; height: 16px;
  stroke: currentColor; fill: none; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--text); border-color: var(--text); }
.btn.small { padding: var(--space-1) var(--space-3); font-size: 0.85rem; }
.btn.block { width: 100%; }
.btn.ghost {
  border-color: transparent;
  background: none;
  color: var(--text-muted);
  padding: 6px var(--space-2);
  font-size: 0.9rem;
}
.btn.ghost:hover { color: var(--text); border-color: var(--border); background: var(--bg-input); }

.linkbtn {
  border: 0; background: none; padding: 0;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
}
.linkbtn:hover { color: var(--text); text-decoration: underline; }

/* ---------- Input ---------- */
input, select, textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-size: 1rem;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Lista contatti ---------- */
.list-pane {
  border-right: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.searchbar { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
.searchbar-full {
  flex-shrink: 0;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.searchbar-full input { font-size: 1.05rem; padding-top: 10px; padding-bottom: 10px; }
.search-wrap { position: relative; }
.search-wrap svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; fill: none; stroke: var(--text-muted); stroke-width: 1.8; stroke-linecap: round;
}
.search-wrap input { padding-left: 34px; padding-right: 34px; }
.search-wrap input::-webkit-search-cancel-button { display: none; }
.search-wrap kbd {
  position: absolute; right: 9px; top: 50%; transform: translateY(-50%);
  font: 500 0.7rem var(--font-mono); color: var(--text-muted);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0 5px;
}
.list-meta {
  display: flex; justify-content: space-between; align-items: center; gap: var(--space-2);
  font-family: var(--font-mono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted);
}
.list-meta select {
  width: auto; border: 0; background: none; padding: 0;
  font: inherit; color: var(--text-muted); text-transform: uppercase; cursor: pointer;
}
.list-meta select:focus { outline-offset: 2px; }

.list { list-style: none; margin: 0; padding: var(--space-2); overflow-y: auto; flex: 1; }
.list-item {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
}
.list-item:hover { border-color: var(--border); background: var(--bg-elevated); }
.list-item.active { border-color: var(--accent); background: var(--bg-elevated); }
.list-item .body { min-width: 0; flex: 1; }
.list-item .top { display: flex; justify-content: space-between; gap: var(--space-2); align-items: baseline; }
.list-item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .when { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-muted); flex: none; }
.list-item .sub { color: var(--text-muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .snippet {
  font-size: 0.85rem; color: var(--text-muted); margin-top: var(--space-1);
  padding-left: var(--space-2); border-left: 2px solid var(--border);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.list-item .snippet b {
  font-family: var(--font-mono); font-weight: 500; font-size: 0.7rem;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--text);
}
.empty-list { padding: var(--space-6) var(--space-4); text-align: center; color: var(--text-muted); }

.avatar {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  font-family: var(--font-mono); font-weight: 500; font-size: 0.8rem; letter-spacing: 0.04em;
  color: var(--text);
}
.list-item.active .avatar { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.avatar.big { width: 64px; height: 64px; font-size: 1.2rem; border-radius: var(--radius-md); background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }

.badge, .chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
}

/* ---------- Dettaglio ---------- */
.detail { overflow-y: auto; padding: var(--space-6) var(--space-6) 64px; }
.detail-inner { max-width: 800px; }
.back { display: none; }

.detail-head { display: flex; gap: var(--space-4); align-items: center; }
.detail-head .titles { flex: 1; min-width: 0; }
.detail-head h1 { font-size: 1.75rem; margin-bottom: var(--space-2); }
.detail-head .sub { color: var(--text-muted); }
.head-actions { display: flex; gap: var(--space-2); flex: none; }

.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin: var(--space-4) 0 0; }
.cat-select {
  width: auto;
  appearance: none; -webkit-appearance: none;
  cursor: pointer;
  padding: 2px 26px 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  font-family: var(--font-mono); font-size: 0.7rem; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--accent-contrast);
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23fff' fill='none' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 9px center;
}

/* Card con angoli a staffa (card-hero di Gestionale) */
.info {
  position: relative;
  display: grid; grid-template-columns: 140px 1fr; gap: var(--space-2) var(--space-4);
  margin: var(--space-5) 0 0;
  padding: var(--space-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.info::before, .info::after {
  content: ''; position: absolute; width: 14px; height: 14px; pointer-events: none;
}
.info::before { top: -1px; left: -1px; border-top: 2px solid var(--accent); border-left: 2px solid var(--accent); }
.info::after { bottom: -1px; right: -1px; border-bottom: 2px solid var(--accent); border-right: 2px solid var(--accent); }
.info dt {
  font-family: var(--font-mono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); padding-top: 3px;
}
.info dd { margin: 0; overflow-wrap: anywhere; }
.info a { color: var(--text); text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 3px; }
.info a:hover { text-decoration-color: var(--accent); }
.info .mini {
  margin-left: var(--space-2);
  font-family: var(--font-mono); font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); text-decoration: none;
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 1px 5px;
}
.info .mini:hover { color: var(--text); border-color: var(--accent); }
.info-empty { color: var(--text-muted); grid-column: 1 / -1; }

.meta-line {
  margin-top: var(--space-3);
  font-family: var(--font-mono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted);
}

.notes { margin-top: var(--space-6); }
.section-title { display: flex; align-items: baseline; gap: var(--space-3); }
.section-title .count { font-size: 0.75rem; letter-spacing: 0.04em; }

.composer {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea { min-height: 88px; resize: vertical; line-height: 1.55; }
.composer-foot { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); margin-top: var(--space-3); }
.composer-foot .hint {
  font-family: var(--font-mono); font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted);
}

.timeline { list-style: none; margin: var(--space-5) 0 0; padding: 0 0 0 var(--space-4); border-left: 1px solid var(--border); }
.note { position: relative; padding: 0 0 var(--space-5) var(--space-4); }
.note::before {
  content: ''; position: absolute; left: calc(-1 * var(--space-4) - 4px); top: 6px;
  width: 7px; height: 7px; background: var(--accent);
}
.note-head { display: flex; gap: var(--space-3); align-items: baseline; flex-wrap: wrap; }
.note-date { font-family: var(--font-mono); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.note-rel { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-muted); }
.note-actions { margin-left: auto; display: flex; gap: var(--space-3); opacity: 0; transition: opacity .12s; }
.note:hover .note-actions, .note:focus-within .note-actions { opacity: 1; }
.note-text {
  white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6;
  margin-top: var(--space-2);
  padding: var(--space-3);
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}
.note-edited { font-family: var(--font-mono); font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-top: var(--space-1); }
.note textarea { min-height: 80px; margin-top: var(--space-2); resize: vertical; }
.note .edit-actions { display: flex; gap: var(--space-2); margin-top: var(--space-2); }
.no-notes { margin-top: var(--space-4); }

/* ---------- Form ---------- */
.form-grid { display: grid; grid-template-columns: 1fr; gap: var(--space-3); }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.form fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  padding: var(--space-4);
  margin: 0 0 var(--space-4);
}
.form legend {
  font-family: var(--font-mono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); padding: 0 var(--space-2); margin-left: calc(-1 * var(--space-2));
  background: var(--bg);
}
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field.wide { grid-column: 1 / -1; }
.field > span {
  font-family: var(--font-mono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted);
}
.field small { font-size: 0.75rem; color: var(--text-muted); }
.field textarea { min-height: 80px; resize: vertical; }
.form-actions {
  display: flex; gap: var(--space-2);
  position: sticky; bottom: -64px;
  padding: var(--space-4) 0;
  background: linear-gradient(transparent, var(--bg) 35%);
}

/* ---------- Modale (Modal di Gestionale) ---------- */
.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  color: var(--text);
  padding: var(--space-4);
  width: min(760px, calc(100vw - var(--space-4) * 2));
  max-height: calc(100vh - var(--space-4) * 2);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.6); }
.modal-inner { display: flex; flex-direction: column; max-height: calc(100vh - var(--space-4) * 2 - var(--space-4) * 2); }
.modal-head { flex-shrink: 0; }
.modal-head h2 { margin: 0 0 var(--space-2); }
.modal-head p { margin: 0; }
.modal-body { margin: var(--space-3) -3px 0; padding: 3px; overflow-y: auto; overscroll-behavior: contain; min-height: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding-top: var(--space-4); margin-top: var(--space-3); border-top: 1px solid var(--border); flex-shrink: 0; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); }
th {
  color: var(--text-muted); font-weight: 500;
  font-family: var(--font-mono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em;
  position: sticky; top: 0; background: var(--bg-elevated);
}
.map-table td.sample { color: var(--text-muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-table select { padding: var(--space-1) var(--space-2); font-size: 0.9rem; }
.map-table tr.ignored td:not(:last-child) { opacity: .45; }
.import-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-4); }

/* ---------- Toast (update-prompt di Gestionale) ---------- */
.toast {
  position: fixed; left: 50%; bottom: var(--space-5);
  transform: translate(-50%, 12px);
  z-index: 100;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  max-width: calc(100vw - var(--space-5) * 2);
  font-size: 0.9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .app { grid-template-columns: 210px minmax(0, 1fr); }
  body.show-detail .app { grid-template-columns: 210px 300px minmax(0, 1fr); }
  .detail { padding: var(--space-5) var(--space-5) 64px; }
}

@media (max-width: 1180px) {
  body.sidebar-hidden.show-detail .app { grid-template-columns: 300px minmax(0, 1fr); }
}

@media (max-width: 860px) {
  .app-shell { height: auto; min-height: 100vh; }
  .app-header { position: sticky; top: 0; }
  .searchbar-full { position: sticky; top: var(--header-height); z-index: 15; }
  body.show-detail .searchbar-full { display: none; }
  .app { display: block; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); gap: var(--space-3); }
  .cat-nav { flex-direction: row; overflow-x: auto; gap: var(--space-1); padding-bottom: 2px; }
  .cat-item { width: auto; flex: none; border-color: var(--border); background: var(--bg-input); border-radius: 999px; padding: var(--space-1) var(--space-3); }
  .add-cat, .side-title { display: none; }
  .tools { flex-direction: row; flex-wrap: wrap; }
  .tools .btn.block { width: auto; }
  .storage { margin-top: 0; }
  .list-pane { border-right: 0; min-height: 60vh; }
  .list { overflow: visible; }
  .detail { display: none; padding: var(--space-4) var(--space-4) 64px; }
  body.show-detail .sidebar, body.show-detail .list-pane { display: none; }
  body.show-detail .detail { display: block; }
  .back { display: inline-flex; margin-bottom: var(--space-4); }
  .detail-head { flex-wrap: wrap; }
  .head-actions { width: 100%; }
  .info { grid-template-columns: 1fr; gap: 2px 0; }
  .info dd { margin-bottom: var(--space-2); }
  .note-actions { opacity: 1; }
}

/* Su touch (niente hover) la × resta visibile sulla categoria selezionata */
@media (hover: none) {
  .cat-item.active .del { display: inline; }
  .cat-item.active .del + .count { display: none; }
}
