/* ============================================================
   ECG Intake - supplement to shared.css
   Built on the shared tokens only. Touch-first (iPad): 48px controls,
   16px inputs (no Safari zoom-on-focus), big tap targets, signature pad.
   ============================================================ */

/* Hamburger drawer on every touch device (any iPad size/orientation) and on narrow windows; the fixed sidebar is for mouse + keyboard desktops only */
@media (max-width: 1100px), (hover: none) and (pointer: coarse) {
  body { padding-left: 0; }
  .nav-hamburger { display: flex; width: 44px; height: 44px; }
  .app-sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  .app-sidebar.open { transform: translateX(0); }
}
body { -webkit-tap-highlight-color: transparent; padding-bottom: env(safe-area-inset-bottom); }
button, a, .row-tap, .chip--select { touch-action: manipulation; }

.brand-logo { height: 30px; width: auto; max-width: 160px; object-fit: contain; }
.brand-name { font-weight: 600; letter-spacing: .2px; }
:root:not([data-theme="light"]) .nav-logo img.brand-logo { filter: none; }

/* ---- touch sizing ---- */
.field input, .field select, .field textarea, input.input, select.input, textarea.input {
  font-size: 16px; min-height: 48px; padding: 10px 12px;
}
.btn { min-height: 48px; padding: 0 20px; font-size: 15px; line-height: 1.2; }
.btn--lg { min-height: 52px; padding: 0 26px; font-size: 16px; }
.btn--sm { min-height: 40px; padding: 0 14px; font-size: 14px; }
/* plain .btn (no variant) = neutral outlined button, same look as .btn--ghost (shared.css leaves it unstyled) */
.btn:not(.btn--primary):not(.btn--danger):not(.btn--ghost) { background: var(--surface); color: var(--text-mid); border-color: var(--border-soft); }
.btn:not(.btn--primary):not(.btn--danger):not(.btn--ghost):hover:not(:disabled) { background: var(--surface-hover); color: var(--text); border-color: var(--border); }
.icon-btn { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn--danger { color: #b91c1c; }
.icon-btn--danger:hover { background: rgba(239,68,68,.12); }
.field label { font-size: 13px; }
.req { color: var(--red); margin-left: 2px; }
.field.invalid input, .field.invalid select { border-color: var(--red); box-shadow: 0 0 0 3px rgba(239,68,68,.15); }

/* ---- user menu ---- */
.menu { position: absolute; right: 18px; top: calc(var(--nav-h) - 2px); z-index: 400; background: var(--surface);
  border: 1px solid var(--border-soft); border-radius: 10px; box-shadow: var(--shadow-lg); min-width: 230px; padding: 6px; }
.menu-item { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 46px; padding: 10px; border-radius: 6px;
  background: transparent; border: 0; color: var(--text); cursor: pointer; font: inherit; text-align: left; }
.menu-item:hover { background: var(--surface-hover); }
.menu-sep { height: 1px; background: var(--border-softer); margin: 4px 0; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--brand); color: #fff; display: inline-flex;
  align-items: center; justify-content: center; font-size: 11px; font-weight: 600; flex: none; }

/* ---- list ---- */
.list-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.list-bar .search { flex: 1 1 260px; position: relative; }
.list-bar .search input { width: 100%; padding-left: 40px; border-radius: 999px; }
.list-bar .search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--text-light); pointer-events: none; }
.seg { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.seg .chip--select { min-height: 40px; padding: 8px 14px; font-size: 14px; }
table.tbl.intakes tbody tr { cursor: pointer; }
table.tbl.intakes tbody td { padding: 14px; }
table.tbl.intakes tbody tr:active { background: var(--brand-soft); }
.cell-main { font-weight: 600; color: var(--text); text-transform: uppercase; letter-spacing: .02em; font-size: 13px; }
.cell-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status--draft { background: color-mix(in srgb, var(--amber) 16%, transparent); color: #b45309; }
.status--signed { background: var(--brand-soft); color: var(--brand); }
.status--sent { background: color-mix(in srgb, var(--green) 16%, transparent); color: #047857; }
.status--failed { background: color-mix(in srgb, var(--red) 14%, transparent); color: #b91c1c; }
:root:not([data-theme="light"]) .status--draft { color: var(--amber); }
:root:not([data-theme="light"]) .status--sent { color: var(--green); }
.empty-state { padding: 48px 16px; text-align: center; color: var(--text-muted); }
@media (max-width: 820px) { .hide-narrow { display: none; } }

/* ---- form ---- */
.intake-form { max-width: 980px; }
.form-section { display: grid; grid-template-columns: 120px 1fr; gap: 20px; align-items: start; }
.section-ico { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--brand); font-size: 12px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; padding-top: 6px; }
.section-ico svg { width: 44px; height: 44px; }
.form-grid.three { grid-template-columns: 1fr 1fr 1fr; }
.span2 { grid-column: span 2; }
@media (max-width: 700px) { .form-section { grid-template-columns: 1fr; gap: 8px; } .section-ico { flex-direction: row; justify-content: flex-start; padding: 0; }
  .section-ico svg { width: 30px; height: 30px; } .form-grid, .form-grid.three { grid-template-columns: 1fr; } .span2 { grid-column: auto; } }
.action-bar { position: sticky; bottom: 0; z-index: 30; display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(10px); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); box-shadow: var(--shadow-lg); margin-top: 8px; }
.action-bar .btn { flex: 1 1 140px; min-height: 52px; font-size: 16px; }
.vat-row { display: flex; gap: 8px; align-items: stretch; }
.vat-row input { flex: 1; min-width: 0; }
.vat-msg { font-size: 13px; margin-top: 6px; display: flex; gap: 6px; align-items: center; }
.vat-msg.ok { color: var(--green); } .vat-msg.bad { color: var(--red); } .vat-msg.warn { color: var(--amber); } .vat-msg.info { color: var(--text-muted); }
.locked-banner { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--brand-soft); color: var(--brand); margin-bottom: 16px; font-weight: 500; }
.intake-form fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }

/* ---- sign screen (full screen overlay) ---- */
.sign-screen { position: fixed; inset: 0; z-index: 900; background: var(--body-bg); overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(16px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom)); }
.sign-inner { max-width: 880px; margin: 0 auto; display: grid; gap: 16px; }
.sign-cols { display: grid; gap: 16px; }
.sign-left, .sign-right { display: grid; gap: 16px; align-content: start; }
@media (min-width: 900px) {
  .sign-inner { max-width: 1240px; }
  .sign-cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); align-items: start; }
  .sign-right { position: sticky; top: 0; }
  #sigPad { height: min(300px, 38vh); }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .terms-box { max-height: 52vh; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 18px; border: 1px solid var(--border-soft); border-radius: var(--radius-sm); background: var(--surface-alt); font-size: 14px; line-height: 1.55; color: var(--text); }
}
.sign-head { display: flex; align-items: center; gap: 12px; }
.sign-head h1 { font-size: 22px; margin: 0; }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 24px; }
.summary-grid dt { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.summary-grid dd { margin: 2px 0 0; font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.terms-box { max-height: 160px; overflow-y: auto; padding: 12px 14px; border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
  background: var(--surface-alt); font-size: 14px; line-height: 1.55; color: var(--text-mid); white-space: pre-wrap; }
.accept { display: flex; gap: 14px; align-items: flex-start; padding: 14px 4px; font-size: 15px; cursor: pointer; }
.accept input { width: 28px; height: 28px; flex: none; margin: 0; accent-color: var(--brand); }
.pad-wrap { position: relative; border: 2px dashed var(--border); border-radius: var(--radius); background: #fff; }
.pad-wrap.has-ink { border-style: solid; border-color: var(--brand); }
#sigPad { display: block; width: 100%; height: 260px; touch-action: none; -webkit-user-select: none; user-select: none; cursor: crosshair; border-radius: var(--radius); }
@media (orientation: landscape) and (max-height: 700px) { #sigPad { height: 200px; } }
.pad-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none;
  color: #9ca3af; font-size: 18px; letter-spacing: .03em; }
.pad-wrap.has-ink .pad-hint { display: none; }
.pad-line { position: absolute; left: 6%; right: 6%; bottom: 52px; border-bottom: 1px solid #cbd5e1; pointer-events: none; }
.pad-x { position: absolute; left: 4%; bottom: 56px; color: #94a3b8; font-size: 20px; pointer-events: none; }
.sign-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.sign-actions .btn { flex: 1 1 180px; min-height: 52px; font-size: 16px; }
.done { text-align: center; padding: 40px 12px; }
.done .tick { width: 76px; height: 76px; margin: 0 auto 16px; border-radius: 50%; background: color-mix(in srgb, var(--green) 16%, transparent);
  color: var(--green); display: flex; align-items: center; justify-content: center; }

/* ---- settings ---- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.tabs .chip--select { min-height: 42px; padding: 9px 16px; font-size: 14px; }
.logo-row { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border-softer); flex-wrap: wrap; }
.logo-row img { height: 40px; max-width: 140px; object-fit: contain; background: #fff; border: 1px solid var(--border-soft); border-radius: 6px; padding: 4px; }
.logo-row .name { flex: 1; font-weight: 600; min-width: 140px; }
.toggle-row { display: flex; align-items: center; gap: 12px; min-height: 44px; cursor: pointer; }
.toggle-row input { width: 24px; height: 24px; accent-color: var(--brand); }

/* ---- login ---- */
.login-shell { min-height: calc(100vh - var(--nav-h)); display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 420px; }
.alert { padding: 10px 12px; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--red) 12%, transparent); color: #b91c1c; margin-bottom: 14px; font-size: 14px; }
:root:not([data-theme="light"]) .alert { color: #fca5a5; }

/* ---- toast ---- */
.toast-slot { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 1200; display: grid; gap: 8px; width: min(92vw, 420px); }
.toast { padding: 13px 16px; border-radius: var(--radius-sm); background: var(--brand-dark); color: #fff; box-shadow: var(--shadow-lg); font-size: 15px; }
.toast.err { background: #b91c1c; } .toast.ok { background: #047857; }
@media print { .app-nav, .app-sidebar, .action-bar { display: none !important; } body { padding: 0; } }

/* bare .input controls (search, selects outside .field) - same look as .field inputs */
input.input, select.input, textarea.input { width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
  color: var(--text); font: inherit; font-size: 16px; -webkit-appearance: none; appearance: none; outline: none; }
select.input { padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
input.input:focus, select.input:focus, textarea.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
input[type=search]::-webkit-search-cancel-button { -webkit-appearance: none; }

/* terms document */
.terms-box p { margin: 0 0 10px; }
.terms-box .t-title { font-size: 15px; text-align: center; border: 1.5px solid var(--text); border-radius: 12px; padding: 10px 14px; margin: 0 0 14px; }
.terms-box .t-head { font-weight: 700; margin-bottom: 4px; }
.terms-box .t-bullet, .terms-box .t-sub { display: grid; grid-template-columns: 34px 1fr; gap: 4px; }
.terms-box .t-sub { margin-left: 34px; margin-bottom: 4px; grid-template-columns: 22px 1fr; }
.terms-box .t-fields { display: grid; grid-template-columns: 170px 1fr; gap: 2px 12px; margin: 0 0 12px; }
.terms-box .t-fields dt { color: var(--text-mid); } .terms-box .t-fields dd { margin: 0; min-height: 1.5em; }
@media (max-width: 600px) { .terms-box .t-fields { grid-template-columns: 1fr; } }

/* patient photo */
.photo-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.photo-field[hidden] { display: none; }
.photo-thumb { width: 56px; height: 56px; padding: 0; border: 1px solid var(--border-soft); border-radius: 10px; overflow: hidden; background: var(--surface-alt); cursor: pointer; flex: none; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lightbox { text-align: center; } .lightbox img { max-width: 100%; max-height: 70vh; border-radius: var(--radius-sm); }
.animal-cell { display: flex; align-items: center; gap: 10px; }
.thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; flex: none; border: 1px solid var(--border-soft); }

.logo-row.archived { opacity: .6; }
.logo-row .name .cell-sub { display: block; font-weight: 400; }
.logo-row .btn--sm { min-height: 40px; }

/* invoiced icon + row actions */
.td-act { white-space: nowrap; text-align: right; } .th-act { width: 1%; }
.icon-btn.inv { color: var(--text-light); border-radius: 50%; }
.icon-btn.inv:not(:disabled):hover { background: var(--brand-soft); color: var(--brand); }
.icon-btn.inv.on { color: #047857; background: color-mix(in srgb, var(--green) 16%, transparent); }
:root:not([data-theme="light"]) .icon-btn.inv.on { color: var(--green); }
.icon-btn.inv:disabled { opacity: .35; cursor: default; }
.toast { display: flex; align-items: center; gap: 14px; justify-content: space-between; }
.toast-act { background: rgba(255,255,255,.18); color: #fff; border: 1px solid rgba(255,255,255,.45); border-radius: 6px; min-height: 36px; padding: 0 14px; font: inherit; font-weight: 700; cursor: pointer; }

/* ---- list rows reflow into two-line cards on touch devices / narrow windows (never wider than the screen, whatever the font) ---- */
.show-tab { display: none; }
@media (max-width: 1100px), (hover: none) and (pointer: coarse) {
  table.tbl.intakes, table.tbl.intakes tbody { display: block; width: 100%; }
  table.tbl.intakes thead { display: none; }
  table.tbl.intakes tr[data-id] { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "owner status act" "animal date date";
    gap: 6px 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border-softer); }
  table.tbl.intakes tr[data-id] > td { display: block; padding: 0; border: 0; min-width: 0; background: none; }
  table.tbl.intakes tr:not([data-id]) > td { display: block; width: 100%; }
  .c-owner { grid-area: owner; } .c-animal { grid-area: animal; }
  .c-date { grid-area: date; text-align: right; font-size: 13px; color: var(--text-muted); }
  .c-date .cell-sub { display: inline; margin-left: 8px; }
  .c-status { grid-area: status; justify-self: end; } .c-act { grid-area: act; }
  .c-comp, .c-vet { display: none !important; }
  .show-tab { display: block; }
  .cell-main { overflow-wrap: anywhere; letter-spacing: 0; }
  .c-owner .cell-sub, .c-animal .cell-sub { overflow-wrap: anywhere; }
  .animal-cell { min-width: 0; }
}
@media (max-width: 760px) { .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; } }

/* ---- list card hierarchy: horse = main line, owner = secondary; small icons; clearer row lines ---- */
.mini-ico { display: none; }
.owner-line, .animal-title { display: inline; }
@media (max-width: 1100px), (hover: none) and (pointer: coarse) {
  .owner-line, .animal-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
  .mini-ico { display: inline-flex; width: 18px; height: 18px; flex: none; color: var(--brand); }
  .mini-ico svg { width: 100%; height: 100%; }
  .mini-ico.horse svg { stroke-width: 38; }
  .mini-ico.user svg { stroke-width: 5; }
  .owner-line .mini-ico { color: var(--text-light); width: 15px; height: 15px; }
  table.tbl.intakes tr[data-id] { grid-template-areas: "animal status act" "owner date date"; gap: 4px 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
  table.tbl.intakes tr[data-id]:last-child { border-bottom: 0; }
  .c-animal .cell-main { font-size: 17px; font-weight: 700; color: var(--text); }
  .c-animal .cell-sub { margin-left: 26px; }
  .c-owner .cell-main { font-size: 13px; font-weight: 500; text-transform: none; color: var(--text-mid); }
  .c-owner .cell-sub { margin-left: 23px; }
  .c-owner { align-self: start; } .c-date { align-self: start; }
}

/* ---- v3: owner shown once, status pill beside the horse, borderless iOS-style row icons ---- */
.status-inline { display: none; }
.td-act .icon-btn, .photo-row .icon-btn { border: 0; background: transparent; box-shadow: none; width: 44px; height: 44px; min-width: 44px; border-radius: 12px; padding: 0; }
.td-act .icon-btn:not(:disabled):hover, .photo-row .icon-btn:hover { background: var(--surface-hover); }
.td-act .icon-btn:active, .photo-row .icon-btn:active { background: var(--surface-subtle); }
.td-act .icon-btn svg, .photo-row .icon-btn svg { width: 26px; height: 26px; }
.icon-btn.inv { border-radius: 12px; color: var(--text-light); background: transparent; }
.icon-btn.inv.on { background: transparent; color: #34c759; }
.icon-btn.inv.on svg circle { fill: currentColor; }
.icon-btn.inv.on svg path { stroke: #fff; }
.icon-btn--danger, .td-act .icon-btn--danger { color: #ff3b30; background: transparent; }
:root:not([data-theme="light"]) .icon-btn--danger, :root:not([data-theme="light"]) .td-act .icon-btn--danger { color: #ff453a; }
@media (max-width: 1100px), (hover: none) and (pointer: coarse) {
  table.tbl.intakes tr[data-id] { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "animal act" "owner date"; padding: 10px 8px 10px 16px; }
  .c-status { display: none !important; }
  .status-inline { display: inline-flex; flex: none; margin-left: 4px; }
  .animal-title { flex-wrap: wrap; row-gap: 4px; }
  .c-date .cell-sub { display: none; }
  .c-act { display: flex; align-items: center; justify-content: flex-end; gap: 0; }
}
