/* ==========================================================================
   VETLY - Gestionale clinica veterinaria
   ========================================================================== */
:root {
  --brand: #0f766e;
  --brand-600: #0d6660;
  --brand-50: #e7f4f2;
  --brand-100: #c9e8e3;
  --side: #0c2f2c;
  --side-2: #12423e;
  --side-text: #b9d6d1;
  --bg: #f3f5f4;
  --card: #ffffff;
  --text: #1b2a28;
  --muted: #61716e;
  --line: #e2e8e6;
  --line-2: #eef2f1;
  --danger: #c2410c;
  --danger-bg: #fdeee6;
  --warn: #a16207;
  --warn-bg: #fdf6dc;
  --ok: #15803d;
  --ok-bg: #e5f6ea;
  --info: #1d4ed8;
  --info-bg: #e7eefe;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 40, 37, .06), 0 1px 3px rgba(16, 40, 37, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); color: var(--text); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; } h4 { font-size: 14px; }
p { margin: 0 0 .8em; }
code { background: var(--line-2); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.ic { width: 18px; height: 18px; flex: none; vertical-align: middle; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.txt-danger { color: var(--danger); }
.txt-ok { color: var(--ok); }
.txt-warn { color: var(--warn); }
.mt { margin-top: 16px; } .mb { margin-bottom: 16px; } .mb0 { margin-bottom: 0; }
.hidden { display: none !important; }
.flex { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-text); position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 700; font-size: 18px; letter-spacing: .2px; }
.brand img { width: 32px; height: 32px; }
.brand small { display: block; font-weight: 400; font-size: 11.5px; color: var(--side-text); letter-spacing: 0; }
.nav { padding: 6px 10px 16px; display: flex; flex-direction: column; gap: 2px; }
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6f9a94; padding: 14px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 8px; color: var(--side-text); font-weight: 500; }
.nav a:hover { background: var(--side-2); color: #fff; text-decoration: none; }
.nav a.active { background: var(--brand); color: #fff; }
.nav .count { margin-left: auto; background: #e8590c; color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; line-height: 18px; font-weight: 600; }
.side-foot { margin-top: auto; padding: 14px 18px; font-size: 11.5px; color: #6f9a94; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 30; background: rgba(255,255,255,.95); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 10px 24px; min-height: 58px; }
.menu-btn { display: none; background: none; border: 0; padding: 6px; cursor: pointer; color: var(--text); }
.gsearch { position: relative; flex: 1; max-width: 460px; min-width: 0; }
.gsearch input[type=search] { width: 100%; padding: 8px 12px 8px 36px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); font: inherit; }
.gsearch input[type=search]:focus { outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px var(--brand-50); }
.gsearch .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; }
.userchip { flex: none; display: flex; align-items: center; gap: 8px; margin-left: auto; color: var(--text); }
.userchip:hover { text-decoration: none; }
.userchip .who { line-height: 1.2; text-align: right; }
.userchip .who small { display: block; color: var(--muted); font-size: 11.5px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-100); color: var(--brand-600); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex: none; }
.avatar.lg { width: 56px; height: 56px; font-size: 20px; }
.icon-link { color: var(--muted); display: inline-flex; padding: 6px; border-radius: 8px; }
.icon-link:hover { background: var(--bg); color: var(--text); }

.content { padding: 22px 24px 40px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Cards & grid ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; min-width: 0; }
.card > h3:first-child, .card-head h3 { margin: 0; }
.card-head { display: flex; align-items: center; gap: 10px; margin: -2px 0 14px; flex-wrap: wrap; }
.card-head .actions { margin-left: auto; display: flex; gap: 6px; }
.card.flush { padding: 0; }
.card.flush .card-head { padding: 14px 18px 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.grid-side { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.grid-2 > .card, .grid-3 > .card, .grid-side > .card { margin-bottom: 0; }
.stack > * + * { margin-top: 18px; }

.kpi { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); color: var(--text); }
.kpi:hover { text-decoration: none; border-color: var(--brand-100); }
.kpi .kico { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; background: var(--brand-50); color: var(--brand); flex: none; }
.kpi .kico.warn { background: var(--warn-bg); color: var(--warn); }
.kpi .kico.danger { background: var(--danger-bg); color: var(--danger); }
.kpi .kico.info { background: var(--info-bg); color: var(--info); }
.kpi .kval { font-size: 22px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .klbl { color: var(--muted); font-size: 12.5px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; line-height: 1.35; }
.btn:hover { background: var(--bg); text-decoration: none; }
.btn .ic { width: 16px; height: 16px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); }
.btn-danger { color: var(--danger); border-color: #f2c9b5; }
.btn-danger:hover { background: var(--danger-bg); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { background: #126a33; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 4px 9px; font-size: 12.5px; border-radius: 7px; }
.btn-lg { padding: 10px 20px; font-size: 15px; }
.btn-block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 8px 8px 0; }
.btn-group .btn.active { background: var(--brand-50); color: var(--brand-600); border-color: var(--brand-100); position: relative; }
.inline-form { display: inline; margin: 0; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid > .field { grid-column: span 4; }
.form-grid > .c2 { grid-column: span 2; } .form-grid > .c3 { grid-column: span 3; } .form-grid > .c4 { grid-column: span 4; }
.form-grid > .c5 { grid-column: span 5; } .form-grid > .c6 { grid-column: span 6; } .form-grid > .c8 { grid-column: span 8; }
.form-grid > .c9 { grid-column: span 9; } .form-grid > .c12 { grid-column: 1 / -1; }
.field label, .lbl { display: block; font-size: 12.5px; font-weight: 600; color: #3c4c49; margin-bottom: 4px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.req::after { content: " *"; color: var(--danger); }
.input, .select, .textarea, select, textarea, input[type=text], input[type=email], input[type=tel], input[type=number], input[type=date], input[type=datetime-local], input[type=time], input[type=password], input[type=search] {
  width: 100%; padding: 8px 10px; border: 1px solid #cfd8d6; border-radius: 8px; background: #fff; font: inherit; color: var(--text); min-height: 38px;
}
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }
input[readonly] { background: var(--bg); }
.check { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; cursor: pointer; margin-right: 14px; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }
.form-actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; align-items: center; }
.section-title { grid-column: 1 / -1; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--brand-600); border-bottom: 1px solid var(--line); padding-bottom: 5px; margin-top: 8px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .input, .filters select, .filters input { width: auto; min-width: 140px; }
.filters .grow { flex: 1; min-width: 200px; }
.filters .grow input { width: 100%; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 9px 12px; border-bottom: 1px solid var(--line); background: #fafbfb; white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fafcfb; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table td.act { white-space: nowrap; text-align: right; }
.table .strong { font-weight: 600; }
.table tr.row-muted td { color: var(--muted); }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.card.flush .table th:first-child, .card.flush .table td:first-child { padding-left: 18px; }
.card.flush .table th:last-child, .card.flush .table td:last-child { padding-right: 18px; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px !important; }

/* ---------- Badges & alerts ---------- */
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--line-2); color: #4b5b58; white-space: nowrap; line-height: 20px; }
.b-prenotato, .b-emessa, .b-avvisato, .b-info { background: var(--info-bg); color: var(--info); }
.b-confermato { background: #ece9fe; color: #5b3fc4; }
.b-arrivato, .b-aperta, .b-da_avvisare, .b-warn, .b-scorta { background: var(--warn-bg); color: var(--warn); }
.b-in_visita { background: #f3e8ff; color: #7e22ce; }
.b-completato, .b-pagata, .b-chiusa, .b-fatto, .b-ok, .b-carico { background: var(--ok-bg); color: var(--ok); }
.b-annullato, .b-annullata, .b-ignorato, .b-bozza { background: #eef0f0; color: #66706e; }
.b-non_presentato, .b-danger, .b-scarico, .b-scaduto { background: var(--danger-bg); color: var(--danger); }
.b-admin { background: #fde8e8; color: #b42318; }
.b-veterinario { background: var(--brand-50); color: var(--brand-600); }
.b-reception { background: var(--info-bg); color: var(--info); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid transparent; }
.alert-ok { background: var(--ok-bg); color: #14532d; border-color: #c4e8cf; }
.alert-warn { background: var(--warn-bg); color: #713f12; border-color: #f1e2a6; }
.alert-danger, .alert-err { background: var(--danger-bg); color: #7c2d12; border-color: #f6cdb8; }
.alert-info { background: var(--info-bg); color: #1e3a8a; border-color: #cbd8fb; }
.alert-pill { display: flex; gap: 8px; align-items: flex-start; background: var(--danger-bg); color: #7c2d12; border-radius: 8px; padding: 8px 12px; font-weight: 500; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }
.tabs .n { background: var(--line-2); border-radius: 999px; padding: 0 7px; font-size: 11.5px; margin-left: 4px; color: var(--muted); }

/* ---------- Entity header ---------- */
.entity { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.entity .title { font-size: 22px; font-weight: 700; }
.entity .meta { color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; margin-top: 3px; }
.entity .meta span { display: inline-flex; gap: 5px; align-items: center; }
.entity .meta .ic { width: 15px; height: 15px; }
.entity .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.species-ico { width: 56px; height: 56px; border-radius: 14px; background: var(--brand-50); color: var(--brand); display: flex; align-items: center; justify-content: center; flex: none; }
.species-ico .ic { width: 30px; height: 30px; }
dl.props { display: grid; grid-template-columns: 130px 1fr; gap: 7px 12px; margin: 0; }
dl.props dt { color: var(--muted); font-size: 12.5px; }
dl.props dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.list li:last-child { border-bottom: 0; }
.list .when { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 48px; }
.list .grow { flex: 1; min-width: 0; }
.list .grow small { display: block; color: var(--muted); }

/* ---------- Timeline (cartella clinica) ---------- */
.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl-item { position: relative; margin-bottom: 16px; }
.tl-item::before { content: ""; position: absolute; left: -21px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2px solid var(--brand); }
.tl-item.vacc::before { border-color: #7e22ce; }
.tl-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tl-body { margin-top: 6px; color: #2f3d3a; }
.tl-body b { color: var(--text); }
.vitals { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.vitals span { background: var(--bg); border-radius: 6px; padding: 1px 8px; font-size: 12.5px; }

/* ---------- Agenda ---------- */
.agenda-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.agenda-bar .period { font-weight: 700; font-size: 16px; margin: 0 6px; }
.agenda { display: grid; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; overflow: auto; max-height: calc(100vh - 210px); position: relative; }
.ag-head { position: sticky; top: 0; z-index: 3; background: #fafbfb; border-bottom: 1px solid var(--line); padding: 8px; text-align: center; font-weight: 600; font-size: 13px; }
.ag-head.today { color: var(--brand); }
.ag-head small { display: block; color: var(--muted); font-weight: 500; }
.ag-corner { position: sticky; top: 0; left: 0; z-index: 4; background: #fafbfb; border-bottom: 1px solid var(--line); }
.ag-times { position: sticky; left: 0; z-index: 2; background: #fff; border-right: 1px solid var(--line); }
.ag-time { font-size: 11.5px; color: var(--muted); text-align: right; padding: 0 8px; transform: translateY(-7px); font-variant-numeric: tabular-nums; }
.ag-col { position: relative; border-right: 1px solid var(--line-2); min-width: 130px; }
.ag-col:last-child { border-right: 0; }
.ag-col.today { background: #fbfefd; }
.ag-col.closed { background: repeating-linear-gradient(45deg, #fafafa, #fafafa 6px, #f3f4f4 6px, #f3f4f4 12px); }
.ag-slot { border-bottom: 1px solid var(--line-2); cursor: pointer; }
.ag-slot.hour { border-bottom-color: var(--line); }
.ag-slot:hover { background: var(--brand-50); }
.ag-ev { position: absolute; left: 3px; right: 3px; border-radius: 6px; padding: 3px 6px; font-size: 12px; line-height: 1.3; overflow: hidden; color: #10302c; background: var(--brand-50); border-left: 3px solid var(--brand); box-shadow: 0 1px 2px rgba(0,0,0,.06); cursor: pointer; z-index: 1; }
.ag-ev:hover { text-decoration: none; filter: brightness(.97); z-index: 2; }
.ag-ev b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ag-ev span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #3b524e; }
.ag-ev.st-annullato, .ag-ev.st-non_presentato { opacity: .5; text-decoration: line-through; }
.ag-ev.st-completato { opacity: .75; }
.ag-ev.st-arrivato { outline: 2px solid #eab308; }
.ag-ev.st-in_visita { outline: 2px solid #a855f7; }
.ag-now { position: absolute; left: 0; right: 0; height: 2px; background: #e8590c; z-index: 2; pointer-events: none; }
.ag-now::before { content: ""; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: #e8590c; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 10px; }

/* ---------- Dialog ---------- */
dialog.modal { border: 0; border-radius: 12px; padding: 0; width: min(680px, calc(100vw - 24px)); box-shadow: 0 20px 50px rgba(0,0,0,.25); color: var(--text); }
dialog.modal::backdrop { background: rgba(12, 30, 28, .45); }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; }
.modal-head .x { margin-left: auto; background: none; border: 0; cursor: pointer; color: var(--muted); padding: 4px; }
.modal-body { padding: 18px; max-height: calc(100vh - 160px); overflow-y: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- Autocomplete ---------- */
.ac-wrap { position: relative; }
.ac-list { position: absolute; z-index: 50; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.12); max-height: 340px; overflow-y: auto; display: none; }
.ac-list.open { display: block; }
.ac-item { display: flex; gap: 10px; align-items: center; padding: 8px 12px; cursor: pointer; color: var(--text); }
.ac-item:hover, .ac-item.hl { background: var(--brand-50); text-decoration: none; }
.ac-item small { display: block; color: var(--muted); }
.ac-item .ic { color: var(--brand); }
.ac-group { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 12px 4px; }
.ac-empty { padding: 12px; color: var(--muted); }
.ac-selected { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--brand-100); background: var(--brand-50); border-radius: 8px; min-height: 38px; }
.ac-selected button { margin-left: auto; background: none; border: 0; cursor: pointer; color: var(--muted); }

/* ---------- Pager ---------- */
.pager { display: flex; gap: 4px; align-items: center; padding: 12px 18px; flex-wrap: wrap; }
.pager a, .pager span.cur { min-width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; border: 1px solid var(--line); color: var(--text); padding: 0 8px; }
.pager span.cur { background: var(--brand); border-color: var(--brand); color: #fff; }
.pager a:hover { background: var(--bg); text-decoration: none; }
.pager .tot { margin-left: auto; color: var(--muted); }

/* ---------- Charts ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart text { font: 11px var(--font); fill: var(--muted); }
.chart .bar { fill: var(--brand); }
.chart .bar:hover { fill: var(--brand-600); }
.chart .line { fill: none; stroke: var(--brand); stroke-width: 2.5; }
.chart .grid { stroke: var(--line-2); }
.chart .pt { fill: #fff; stroke: var(--brand); stroke-width: 2; }
.hbar { display: grid; grid-template-columns: 130px 1fr 70px; gap: 8px; align-items: center; margin-bottom: 8px; font-size: 13px; }
.hbar .track { background: var(--line-2); border-radius: 4px; height: 10px; overflow: hidden; }
.hbar .fill { background: var(--brand); height: 100%; border-radius: 4px; }
.hbar .v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Invoice editor ---------- */
.lines td { vertical-align: middle; }
.lines input, .lines select { min-height: 34px; padding: 5px 8px; }
.lines .w-q { width: 80px; } .lines .w-p { width: 110px; } .lines .w-s { width: 72px; } .lines .w-i { width: 84px; }
.totals { margin-left: auto; width: 320px; max-width: 100%; }
.totals div { display: flex; justify-content: space-between; padding: 5px 0; font-variant-numeric: tabular-nums; }
.totals .grand { border-top: 2px solid var(--text); font-size: 17px; font-weight: 700; margin-top: 4px; padding-top: 8px; }

/* ---------- Auth ---------- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: radial-gradient(1200px 600px at 10% -10%, #d6efe9 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #dcebe8 0%, transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 30px; box-shadow: 0 12px 40px rgba(16, 40, 37, .12); }
.auth-card.wide { max-width: 900px; }
.auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.auth-brand b { font-size: 22px; display: block; }
.auth-brand small { color: var(--muted); }
.auth-card .field { margin-bottom: 14px; }
.setup-log { margin: 0; padding-left: 18px; }
.setup-log li { margin-bottom: 4px; }
.setup-log .err { color: var(--danger); }
.setup-log pre { white-space: pre-wrap; font-size: 11.5px; color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-side { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 60; transform: translateX(-100%); transition: transform .2s ease; }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 8px 16px; }
  .content { padding: 16px 16px 32px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .form-grid > .field, .form-grid > .c2, .form-grid > .c3, .form-grid > .c4, .form-grid > .c5, .form-grid > .c6, .form-grid > .c8, .form-grid > .c9 { grid-column: 1 / -1; }
  .userchip .who { display: none; }
  .hide-sm { display: none !important; }
  dl.props { grid-template-columns: 110px 1fr; }
  .hbar { grid-template-columns: 90px 1fr 60px; }
  .filters .input, .filters select, .filters input { min-width: 0; flex: 1 1 140px; }
}
@media (max-width: 520px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi .kval { font-size: 18px; }
  .topbar { gap: 8px; }
  .kpi { padding: 12px; }
  .kpi .kico { display: none; }
  .page-head .actions { margin-left: 0; width: 100%; }
}

/* ---------- Stampa ---------- */
.print-doc { max-width: 800px; margin: 0 auto; background: #fff; padding: 36px 40px; color: #111; font-size: 13px; }
.print-doc h1 { font-size: 20px; }
.print-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid var(--brand); padding-bottom: 14px; margin-bottom: 18px; }
.print-head .clinic b { font-size: 17px; color: var(--brand-600); }
.print-head .clinic div { color: #444; font-size: 12px; }
.print-box { border: 1px solid #ddd; border-radius: 6px; padding: 10px 12px; }
.print-box .lbl { color: #666; }
.print-doc table { width: 100%; border-collapse: collapse; margin: 12px 0; }
.print-doc th, .print-doc td { border-bottom: 1px solid #ddd; padding: 6px 8px; text-align: left; }
.print-doc th { background: #f4f6f5; font-size: 11.5px; text-transform: uppercase; }
.print-doc td.num, .print-doc th.num { text-align: right; }
.print-foot { margin-top: 30px; font-size: 11.5px; color: #555; }
.sign { margin-top: 50px; display: flex; justify-content: flex-end; }
.sign div { width: 260px; border-top: 1px solid #333; text-align: center; padding-top: 4px; font-size: 12px; }
.print-toolbar { max-width: 800px; margin: 16px auto; display: flex; gap: 8px; }
body.print-body { background: #e9edec; }
@media print {
  @page { margin: 14mm; }
  body, body.print-body { background: #fff; }
  .sidebar, .topbar, .no-print, .print-toolbar, .page-head .actions { display: none !important; }
  .app { display: block; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .print-doc { padding: 0; max-width: none; }
  a { color: inherit; }
}

/* ==========================================================================
   v2 - Accesso, area pubblica, portale proprietari, consulti
   ========================================================================== */
.login-page { margin: 0; background: #fff; }
.login-split { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); min-height: 100vh; }
.login-hero { position: relative; background-size: cover; background-position: center 30%; color: #fff; }
.login-hero::before { content: ""; position: absolute; inset: 0; background: linear-gradient(160deg, rgba(8, 48, 44, .82) 0%, rgba(15, 118, 110, .55) 45%, rgba(8, 40, 37, .78) 100%); }
.login-hero-inner { position: relative; z-index: 1; height: 100%; display: flex; flex-direction: column; padding: 32px 44px; }
.login-logo { display: inline-flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 20px; }
.login-logo:hover { text-decoration: none; }
.login-claim { margin: auto 0; max-width: 520px; }
.login-claim h1 { font-size: 40px; line-height: 1.12; margin: 0 0 16px; letter-spacing: -.5px; }
.login-claim p { font-size: 16px; color: #d7efea; margin-bottom: 20px; }
.login-claim ul { list-style: none; padding: 0; margin: 0 0 26px; display: grid; gap: 10px; }
.login-claim li { display: flex; gap: 10px; align-items: center; font-weight: 500; }
.login-claim li .ic { width: 20px; height: 20px; background: rgba(255,255,255,.16); border-radius: 8px; padding: 4px; box-sizing: content-box; }
.login-cta { background: #fff; color: var(--brand-600); border-color: #fff; font-weight: 600; }
.login-cta:hover { background: #e9f6f3; }
.login-credit { font-size: 11px; color: rgba(255,255,255,.65); }
.login-panel { display: flex; align-items: center; justify-content: center; padding: 32px 24px; background: radial-gradient(800px 400px at 100% 0%, #e3f3ef 0%, transparent 60%), #fff; }
.login-box { width: 100%; max-width: 400px; }
.login-box h2 { font-size: 26px; margin: 22px 0 4px; }
.login-alt { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); text-align: center; }
.login-alt a { font-weight: 600; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 12px; padding: 4px; gap: 4px; }
.seg a { display: flex; align-items: center; justify-content: center; gap: 7px; padding: 9px; border-radius: 9px; color: var(--muted); font-weight: 600; }
.seg a:hover { text-decoration: none; color: var(--text); }
.seg a.active { background: #fff; color: var(--brand-600); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
@media (max-width: 900px) {
  .login-split { grid-template-columns: minmax(0, 1fr); }
  .login-hero { min-height: 300px; }
  .login-hero-inner { padding: 22px 20px; }
  .login-claim { margin: 26px 0 10px; }
  .login-claim h1 { font-size: 28px; }
  .login-claim p, .login-claim ul { display: none; }
}

/* Intestazione pubblica / portale */
.pub-body { background: var(--bg); min-height: 100vh; }
.pub-top { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
.pub-top-in { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; gap: 18px; padding: 10px 20px; min-height: 60px; flex-wrap: wrap; }
.pub-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: var(--text); }
.pub-brand:hover { text-decoration: none; }
.pub-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.pub-nav a { padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; display: inline-flex; gap: 6px; align-items: center; }
.pub-nav a:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.pub-nav a.active { color: var(--brand-600); background: var(--brand-50); }
.pub-nav .count { background: #e8590c; color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; line-height: 18px; }
.pub-user { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.pub-main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 48px; }
.pub-foot { text-align: center; color: var(--muted); font-size: 12.5px; padding: 24px; }
.pub-hero { background: linear-gradient(120deg, #0c2f2c, #0f766e); color: #fff; border-radius: 16px; padding: 30px; margin-bottom: 22px; position: relative; overflow: hidden; }
.pub-hero h1 { font-size: 28px; margin-bottom: 6px; }
.pub-hero p { color: #cfeae5; margin: 0 0 18px; }
.pub-hero .filters { margin: 0; }
.pub-hero .filters input, .pub-hero .filters select { border-color: transparent; }
@media (max-width: 700px) { .pub-user .who { display: none; } .pub-main { padding: 16px 14px 36px; } .pub-hero { padding: 22px 18px; } }

/* Schede cliniche */
.clinic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.clinic-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.clinic-cover { height: 86px; background: linear-gradient(120deg, var(--c1, #0f766e), var(--c2, #14b8a6)); position: relative; }
.clinic-cover .clinic-ini { position: absolute; left: 18px; bottom: -24px; width: 56px; height: 56px; border-radius: 14px; background: #fff; color: var(--c1, #0f766e); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 20px; box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.clinic-body { padding: 32px 18px 18px; flex: 1; display: flex; flex-direction: column; gap: 8px; }
.clinic-body h3 { margin: 0; font-size: 17px; }
.clinic-meta { color: var(--muted); font-size: 13px; display: flex; gap: 6px; align-items: center; }
.clinic-meta .ic { width: 15px; height: 15px; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { background: var(--bg); color: #3b4a47; border-radius: 999px; padding: 2px 10px; font-size: 12px; }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.urg { background: var(--danger-bg); color: var(--danger); }
.clinic-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 8px; }

/* Thread consulto */
.thread { display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 78%; padding: 10px 14px; border-radius: 14px; background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow); }
.msg.me { align-self: flex-end; background: var(--brand-50); border-color: var(--brand-100); }
.msg.sys { align-self: center; background: transparent; border: 0; box-shadow: none; color: var(--muted); font-size: 12.5px; text-align: center; max-width: 90%; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 8px; }
.msg .who b { color: var(--text); }
.msg .txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin-top: 8px; cursor: zoom-in; }
.composer { display: grid; gap: 10px; }
.composer textarea { min-height: 90px; }
.foto-prev { display: none; align-items: center; gap: 10px; }
.foto-prev.on { display: flex; }
.foto-prev img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.unread { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #e8590c; margin-right: 6px; }
.pet-card { display: flex; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.pet-card .species-ico { width: 46px; height: 46px; border-radius: 12px; }
.pet-card .species-ico .ic { width: 24px; height: 24px; }
.b-aperto, .b-in_attesa { background: var(--warn-bg); color: var(--warn); }
.b-chiuso, .b-attiva { background: var(--ok-bg); color: var(--ok); }
.b-sospesa { background: var(--danger-bg); color: var(--danger); }
.b-consulto { background: var(--info-bg); color: var(--info); }
.b-appuntamento { background: #ece9fe; color: #5b3fc4; }
.steps { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.reg-wrap { max-width: 760px; margin: 0 auto; }
