/* Canile Megavet · disegno per telefono. Sopra 820 px di larghezza non cambia nulla. */

/* Elementi presenti solo su telefono (nascosti altrove) */
.sb-mob, .sb-scrim, .sb-sheet { display: none; }

.vs-back { display: none; }

@media (max-width: 820px) {
  :root { --bar-h: 58px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px); }
  html, body { height: 100dvh; -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; }
  body { -webkit-tap-highlight-color: transparent; }
  button, a, select, input, textarea { touch-action: manipulation; }
  /* Evita lo zoom automatico di iOS quando si tocca un campo */
  input, select, textarea { font-size: 16px !important; }
  input[type="checkbox"], input[type="radio"] { font-size: initial !important; }

  /* Struttura: una sola colonna, spazio per la barra in basso */
  .app-root { grid-template-columns: minmax(0, 1fr) !important; grid-template-rows: 0 minmax(0, 1fr) !important; height: 100dvh !important; padding-bottom: calc(var(--bar-h) + var(--safe-b)); }
  .sb-nav { height: 0 !important; padding: 0 !important; border: 0 !important; overflow: visible !important; }
  .sb-d { display: none !important; }

  /* Barra di navigazione in basso */
  .sb-mob { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; height: calc(var(--bar-h) + var(--safe-b)); padding: 0 4px var(--safe-b); background: var(--surface); border-top: 1px solid var(--line); }
  .sb-tab { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border: 0; background: transparent; font-family: inherit; font-size: 11px; font-weight: 600; text-decoration: none; cursor: pointer; padding: 0; }
  .sb-tab span { font-size: 11px; line-height: 1; }
  .sb-scrim { display: block; position: fixed; inset: 0; z-index: 70; background: var(--scrim, rgba(10, 25, 25, .4)); }
  .sb-sheet { display: flex; flex-direction: column; gap: 4px; position: fixed; left: 0; right: 0; bottom: 0; z-index: 80; max-height: 88dvh; overflow: auto; padding: 8px 16px calc(14px + var(--safe-b)); background: var(--surface); border-radius: 18px 18px 0 0; box-shadow: var(--shadow-pop); font-size: 15px; color: var(--ink); font-family: 'Geist', ui-sans-serif, system-ui, sans-serif; }
  .sb-grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line-2); margin: 0 auto 8px; flex: none; }
  .sb-user { display: flex; align-items: center; gap: 12px; padding: 4px 2px 12px; }
  .sb-av { width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--line-2); font-size: 13px; font-weight: 600; color: var(--ink-2); }
  .sb-user b { display: block; font-weight: 600; }
  .sb-sub { display: block; font-size: 13px; color: var(--ink-3); }
  .sb-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
  .sb-link { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 76px; padding: 10px 4px; border-radius: 14px; text-decoration: none; font-size: 12.5px; font-weight: 600; text-align: center; }
  .sb-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 50px; padding: 0 8px; border: 0; border-radius: 12px; background: transparent; color: var(--ink); font-family: inherit; font-size: 15px; text-align: left; cursor: pointer; }
  .sb-row:active { background: var(--surface-2); }
  .sb-out { color: var(--danger); font-weight: 500; }
  .sb-pw { display: flex; flex-direction: column; gap: 10px; padding: 6px 4px 10px; }
  .sb-pw input { height: 46px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 12px; background: var(--surface); color: var(--ink); font-family: inherit; }
  .sb-save { height: 46px; border: 0; border-radius: 12px; background: var(--primary); color: var(--on-primary); font-family: inherit; font-size: 15px; font-weight: 600; }

  /* Pagine con barra del titolo e contenuti scorrevoli */
  .m-pad { padding: 14px 16px 0 !important; }
  .m-list { padding: 0 16px 28px !important; }
  .kbd-hint { display: none !important; }
  /* Pulsante principale fluttuante, sopra la barra in basso */
  .fab { position: fixed !important; right: 16px; bottom: calc(var(--bar-h) + var(--safe-b) + 14px); z-index: 55; height: 52px !important; padding: 0 20px 0 16px !important; border-radius: 26px !important; box-shadow: 0 10px 24px -6px rgba(8, 60, 60, .45); font-size: 15px !important; }
  /* Anteprima / dettaglio a tutto schermo */
  .m-sheet { position: fixed !important; inset: 0 !important; width: 100% !important; max-width: none !important; z-index: 90 !important; border-left: 0 !important; padding-bottom: calc(var(--safe-b)); }

  /* Lista cani: da tabella a schede */
  .dog-table { min-width: 0 !important; border: 0 !important; background: transparent !important; border-radius: 0 !important; overflow: visible !important; }
  .dog-head { display: none !important; }
  .dog-row { grid-template-columns: minmax(0, 1fr) auto !important; gap: 6px 12px !important; padding: 13px 14px !important; margin-bottom: 10px; border: 1px solid var(--line) !important; border-radius: 14px; background: var(--surface) !important; box-shadow: none !important; }
  .dog-row[aria-selected="true"] { background: var(--primary-soft) !important; }
  .dog-row > [role="cell"] { min-width: 0; }
  .dog-row > [role="cell"]:nth-child(1) { grid-column: 1; grid-row: 1; }
  .dog-row > [role="cell"]:nth-child(3) { grid-column: 2; grid-row: 1; text-align: right; align-self: start; }
  .dog-row > [role="cell"]:nth-child(7) { grid-column: 1 / 3; grid-row: 2; }
  .dog-row > [role="cell"]:nth-child(2) { grid-column: 1; grid-row: 3; display: flex; gap: 8px; align-items: baseline; font-size: 13px; color: var(--ink-2); }
  .dog-row > [role="cell"]:nth-child(6) { grid-column: 2; grid-row: 3; text-align: right; font-size: 13px; }
  .dog-row > [role="cell"]:nth-child(4), .dog-row > [role="cell"]:nth-child(5), .dog-row > [role="cell"]:nth-child(8) { display: none !important; }

  /* Scheda del cane */
  .sc-head { padding: 12px 16px 0 !important; }
  .sc-title { flex-wrap: nowrap !important; gap: 12px !important; align-items: flex-start !important; }
  .sc-info { min-width: 0 !important; }
  .sc-info h1 { font-size: 22px !important; }
  .sc-actions { flex-basis: 100%; flex-wrap: nowrap !important; overflow-x: auto; margin: 4px -16px 0 !important; padding: 2px 16px 6px; scrollbar-width: none; }
  .sc-actions::-webkit-scrollbar { display: none; }
  .sc-actions > * { flex: none; }
  .sc-title { flex-wrap: wrap !important; }
  .sc-body { display: flex !important; flex-direction: column; align-items: stretch !important; gap: 14px !important; padding: 14px 16px 28px !important; }
  .sc-aside { display: contents !important; }
  .sc-sec { order: 4; }
  .sc-o1 { order: 1; }
  .sc-o2 { order: 2; }
  .sc-tl { order: 3; }
  .sc-tabs { flex-wrap: nowrap !important; overflow-x: auto; margin: 0 -16px 12px !important; padding: 0 16px 4px; scrollbar-width: none; }
  .sc-tabs::-webkit-scrollbar { display: none; }
  .sc-tabs > * { flex: none; }

  /* Moduli e finestre: pannello che sale dal basso, un campo per riga, campi e pulsanti grandi */
  @keyframes mfUp { from { transform: translateY(28px); opacity: .5; } to { transform: none; opacity: 1; } }
  .mf-scrim { padding: 0 !important; display: flex !important; align-items: flex-end !important; justify-content: stretch !important; }
  .mf-dialog { width: 100% !important; max-width: 100% !important; max-height: calc(100dvh - 10px - var(--safe-t)) !important; border-radius: 20px 20px 0 0 !important; border: 0 !important; animation: mfUp .2s ease-out !important; }
  .mf-head { padding: 16px 8px 12px 18px !important; }
  .mf-head h2 { font-size: 19px !important; }
  .mf-x { width: 44px !important; height: 44px !important; }
  .mf-body { padding: 16px 18px 22px !important; gap: 24px !important; -webkit-overflow-scrolling: touch; }
  .mf-grid { grid-template-columns: minmax(0, 1fr) !important; gap: 16px !important; }
  .mf-dialog input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), .mf-dialog select { height: 48px !important; border-radius: 12px !important; }
  .mf-dialog textarea { min-height: 96px; border-radius: 12px !important; }
  .mf-dialog label { font-size: 13.5px !important; }
  .mf-dialog button { min-height: 44px; }
  .mf-foot { padding: 12px 18px calc(12px + var(--safe-b)) !important; flex-wrap: wrap !important; gap: 10px !important; }
  .mf-foot button:first-of-type { flex: 0 0 32% !important; }
  .mf-foot button { flex: 1 1 0; height: 50px !important; font-size: 16px !important; justify-content: center; border-radius: 14px !important; }
  .mf-foot span[role="alert"] { flex: 0 0 100%; margin: 0 0 2px !important; text-align: center; }

  /* Visite: elenco, poi dettaglio a tutto schermo */
  .vs-split { display: block !important; }
  .vs-list { border-right: 0 !important; height: 100%; }
  .vs-list > div:first-child { padding: 14px 16px 10px !important; }
  .vs-list button { min-height: 56px; }
  .vs-detail { display: none !important; }
  .vs-detail[data-open="1"] { display: block !important; position: fixed; inset: 0; z-index: 90; background: var(--bg); padding-bottom: var(--safe-b); }
  .vs-dh { padding: 10px 14px 10px !important; gap: 10px !important; padding-top: calc(10px + var(--safe-t)) !important; }
  .vs-back { display: inline-flex !important; align-items: center; flex: 0 0 100%; justify-content: flex-start; height: 40px; margin: 0 -4px; padding: 0 6px; border: 0; background: none; color: var(--primary-ink); font-family: inherit; font-size: 16px; font-weight: 600; cursor: pointer; }
  .vs-acts { display: flex !important; flex: 0 0 100%; gap: 8px; overflow-x: auto; margin: 0 -14px; padding: 2px 14px 4px; scrollbar-width: none; order: 5; }
  .vs-acts::-webkit-scrollbar { display: none; }
  .vs-acts > * { flex: none; }
  .vs-acts button { height: 44px !important; font-size: 15px !important; }
  .vs-detail > div:last-of-type { padding: 14px 14px 100px !important; gap: 16px !important; }
  /* Azione principale (Chiudi visita / Salva modifiche): barra fissa in basso */
  .vs-acts button:last-of-type { position: fixed !important; left: 14px; right: 14px; bottom: calc(var(--safe-b) + 12px); height: 54px !important; z-index: 95; justify-content: center; border-radius: 16px !important; font-size: 17px !important; box-shadow: 0 12px 28px -8px rgba(8, 60, 60, .5); }

  /* Agenda */
  .ag-head { padding: 12px 16px 10px !important; gap: 10px !important; }
  .ag-head > div[style*="flex:1"] { display: none; }
  .ag-head button, .ag-head input { min-height: 44px; }
  .ag-day { padding: 14px 16px 100px !important; gap: 16px !important; }
  .ag-weekwrap { padding: 14px 16px 100px !important; overflow-x: visible !important; }
  .ag-week { grid-template-columns: minmax(0, 1fr) !important; min-width: 0 !important; gap: 12px !important; }
  .ag-items { min-height: 0 !important; }
  .ag-week section[data-today] { scroll-margin-top: 8px; }
  .ag-week section > button { min-height: 48px; }
  .ag-items > button { min-height: 52px; }
  .ag-row { grid-template-columns: 56px minmax(0, 1fr) auto !important; gap: 6px 12px !important; padding: 12px 14px !important; }
  .ag-row > div:nth-child(3) { grid-column: 2 / 4; grid-row: 2; }
  .ag-row > div:nth-child(4) { grid-column: 3; grid-row: 1; }
  .ag-row > div:nth-child(5) { grid-column: 1 / 4; grid-row: 3; justify-content: stretch !important; }
  .ag-row > div:nth-child(5) button { flex: 1; min-height: 46px; justify-content: center; }

  /* Laboratorio */
  .lb-head { padding: 16px 16px 0 !important; gap: 10px !important; }
  .lb-head h1 { width: 100%; }
  .lb-head > div[style*="flex:1"] { display: none; }
  .lb-tabs { width: 100%; }
  .lb-tabs button { flex: 1 1 45%; justify-content: center; height: 42px !important; }
  .lb-search, .lb-search input { width: 100% !important; }
  .lb-search input { height: 44px !important; font-size: 16px !important; }
  .lb-head > a, .lb-head > button { flex: 1 1 auto; justify-content: center; height: 46px !important; }
  .lb-hint { margin: 8px 16px 0 !important; }
  .lb-wrap { padding: 12px 12px 100px !important; gap: 12px !important; }
  .lb-wrap > section { flex: 1 1 100% !important; }
  .lb-thead { display: none !important; }
  .lb-grid { grid-template-columns: minmax(0, 1fr) auto !important; gap: 8px 12px !important; padding: 14px 14px 8px !important; }
  .lb-grid > div:nth-child(1) { grid-column: 1; grid-row: 1; }
  .lb-grid > div:nth-child(5) { grid-column: 2; grid-row: 1; }
  .lb-grid > div:nth-child(2) { grid-column: 1 / 3; grid-row: 2; }
  .lb-grid > div:nth-child(3) { grid-column: 1 / 3; grid-row: 3; }
  .lb-grid > div:nth-child(4) { grid-column: 1 / 3; grid-row: 4; }
  .lb-note { padding: 0 14px 8px !important; }
  .lb-acts { padding: 0 14px 14px !important; }
  .lb-acts button { flex: 1 1 40%; min-height: 44px; height: auto !important; justify-content: center; }

  /* Esami */
  .es-filters { padding: 12px 16px 0 !important; }
  .es-filters button { min-height: 38px; }
  .es-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; padding: 14px 16px 0 !important; gap: 10px !important; }
  .es-row { grid-template-columns: minmax(0, 1fr) auto !important; gap: 6px 10px !important; padding: 14px !important; }
  .es-row > span:nth-child(3) { grid-column: 1; grid-row: 1; }
  .es-row > span:nth-child(5) { grid-column: 2; grid-row: 1; }
  .es-row > span:nth-child(4) { grid-column: 1 / 3; grid-row: 2; white-space: normal !important; }
  .es-row > span:nth-child(1) { grid-column: 1; grid-row: 3; font-size: 12px; color: var(--ink-3); }
  .es-row > span:nth-child(2) { grid-column: 2; grid-row: 3; font-size: 12px; }
  .es-side { max-width: none !important; flex: 1 1 100% !important; }
  .es-detail { position: fixed !important; inset: 0 0 calc(var(--bar-h) + var(--safe-b)) 0; width: auto !important; z-index: 60; border-left: 0 !important; }
  .es-detail button[aria-label="Chiudi"] { width: 44px !important; height: 44px !important; }
  .es-detail button { min-height: 40px; }

  .es-row > span:nth-child(2) { text-align: right; }
  /* Magazzino */
  .mg-head { padding: 16px 16px 10px !important; }
  .mg-head > div { gap: 10px !important; }
  .mg-search { min-width: 100% !important; flex: 1 1 100% !important; }
  .mg-search input { font-size: 16px !important; }
  .mg-head > div > button { flex: 1 1 40%; justify-content: center; height: 48px !important; }
  .mg-head [aria-pressed] { height: 38px !important; }
  .mg-scroll { padding: 0 12px 100px !important; }
  .mg-table { min-width: 0 !important; }
  .mg-thead { display: none !important; }
  .mg-row { grid-template-columns: minmax(0, 1fr) auto !important; gap: 8px 12px !important; padding: 14px !important; }
  .mg-row > div:nth-child(1) { grid-column: 1; grid-row: 1; }
  .mg-row > div:nth-child(7) { grid-column: 2; grid-row: 1; gap: 8px !important; }
  .mg-row > div:nth-child(7) button { width: 46px !important; height: 46px !important; }
  .mg-row > div:nth-child(1) > div { white-space: normal !important; }
  .mg-row > div:nth-child(3) { grid-column: 1 / 3; grid-row: 2; }
  .mg-row > div:nth-child(4) { grid-column: 1; grid-row: 3; }
  .mg-row > div:nth-child(5) { grid-column: 2; grid-row: 3; text-align: right; }
  .mg-row > div:nth-child(2), .mg-row > div:nth-child(6) { display: none; }
  .mv-row { grid-template-columns: minmax(0, 1fr) auto !important; gap: 6px 12px !important; padding: 14px !important; }
  .mv-row > div:nth-child(3) { grid-column: 1; grid-row: 1; }
  .mv-row > div:nth-child(4) { grid-column: 2; grid-row: 1; text-align: right; }
  .mv-row > div:nth-child(5) { grid-column: 1 / 3; grid-row: 2; }
  .mv-row > div:nth-child(1) { grid-column: 1; grid-row: 3; display: flex; gap: 8px; }
  .mv-row > div:nth-child(2) { grid-column: 2; grid-row: 3; text-align: right; }
  .mv-row > div:nth-child(6) { grid-column: 1 / 3; grid-row: 4; font-size: 12px !important; color: var(--ink-3) !important; }

  /* Archivio */
  .ar-head { padding: 16px 16px 12px !important; gap: 10px !important; }
  .ar-head [role=tablist] { width: 100%; }
  .ar-head [role=tab] { flex: 1; justify-content: center; height: 42px !important; }
  .ar-search { min-width: 100% !important; flex: 1 1 100% !important; }
  .ar-search input { font-size: 16px !important; }
  .ar-head > button { height: 44px !important; }
  .ar-scroll { padding: 0 12px 100px !important; }
  .ar-table { min-width: 0 !important; }
  .ar-thead { display: none !important; }
  .ar-row { grid-template-columns: minmax(0, 1fr) auto !important; gap: 8px 12px !important; padding: 14px !important; }
  .ar-row > div:nth-child(1) { grid-column: 1; grid-row: 1; }
  .ar-row > div:nth-child(3) { grid-column: 2; grid-row: 1; }
  .ar-row > div:nth-child(2) { grid-column: 1 / 3; grid-row: 2; display: flex; gap: 8px; align-items: baseline; }
  .ar-row > div:nth-child(4) { grid-column: 1 / 3; grid-row: 3; }
  .ar-row > div:nth-child(5) { grid-column: 1 / 3; grid-row: 4; }
  .ar-row > div:nth-child(6) { display: none !important; }
  .ar-row > div:nth-child(1) > div:last-child > div:last-child { white-space: normal !important; }
  .ar-detail { position: fixed !important; inset: 0 0 calc(var(--bar-h) + var(--safe-b)) 0 !important; width: auto !important; max-width: none !important; z-index: 60 !important; border-left: 0 !important; }
  .ar-detail button[aria-label="Chiudi"] { width: 44px !important; height: 44px !important; }
  .ar-detail button, .ar-detail a { min-height: 44px; }

  /* Impostazioni */
  .st-root { grid-template-rows: 0 auto minmax(0, 1fr) !important; }
  .st-nav { display: flex; flex-wrap: nowrap; align-items: center; gap: 6px; overflow-x: auto !important; overflow-y: hidden; padding: 12px 12px !important; border-right: 0 !important; border-bottom: 1px solid var(--line); -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .st-nav::-webkit-scrollbar { display: none; }
  .st-nav h1 { display: none; }
  .st-nav button { flex: none; width: auto !important; height: 42px !important; padding: 0 14px !important; white-space: nowrap; border: 1px solid var(--line-2) !important; border-radius: 999px !important; }
  .st-main { padding: 16px 14px 100px !important; }
  .st-form { grid-template-columns: minmax(0, 1fr) !important; }
  .st-form input, .st-form select, .st-form textarea { font-size: 16px !important; min-height: 44px; }
  .st-table { overflow-x: auto !important; }
  .st-table > div { min-width: 560px; }
}
