/* Shared base for the three web apps (customer, vet, admin).
   Linked after shared.css and before each app's own main.css:

     <link data-trunk rel="css" href="../../crates/ui/style/shared.css" />
     <link data-trunk rel="css" href="../../crates/ui/style/web.css" />
     <link data-trunk rel="css" href="style/main.css" />

   It carries the default (tenant-themable) palette, the surface design
   tokens, and every structural rule the web apps share. An app's main.css
   only keeps its palette overrides and its own components.

   Visual language mirrors the mobile app (apps/app-ui): soft shadow cards
   instead of hard borders, rounder/roomier controls, a calm page
   background. Per-tenant theming stays variable-driven — customer/vet
   inject --primary/--accent via an inline <body> style; admin overrides
   the palette in its main.css. */

:root {
    /* Tenant-themable palette (defaults = customer/vet blue+green). */
    --primary:    #2563eb;
    --accent:     #10b981;
    --text:       #0f172a;
    --muted:      #6b7280;
    --bg:         #ffffff;
    --bg-soft:    #f5f5f7;
    --border:     #e5e7eb;
    --warn:       #b45309;
    --danger:     #b91c1c;
    /* Focus ring colour — admin overrides to its accent. */
    --focus:      var(--primary);

    /* Surface design tokens (from app-ui). */
    --radius-card:    0.875rem;
    --radius-control: 0.5rem;
    --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04),
                   0 1px 1px rgba(15, 23, 42, 0.03);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg-soft);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--primary); }

/* ====================== Topbar ====================== */

.topbar {
    background: var(--primary);
    color: #fff;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}
/* Brand is a logo + name row; the gap keeps them from touching when a
   practice logo is present. */
.topbar .brand {
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}
/* Per-practice logo in the bar. Capped height; width auto-scales. */
.topbar-logo {
    height: 1.75rem;
    width: auto;
    display: block;
    border-radius: 4px;
}

/* Pre-login practice branding above the login card: centred logo + name. */
.login-branding {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.login-logo {
    max-height: 4rem;
    max-width: 70%;
    width: auto;
    height: auto;
}
.login-brand-name {
    font-weight: 600;
    margin: 0;
    text-align: center;
}
/* The nav buttons + locale picker live in this slot; space them so the
   now-opaque ghost buttons don't visually run together. */
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.topbar a, .topbar form button {
    color: #fff;
    text-decoration: none;
}
/* Ghost buttons sit on the coloured bar, so they can't use the white
   page fill — give them the same translucent treatment as the locale
   picker (see shared.css) instead of white-on-white. */
.topbar .button-ghost {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.35);
}
.topbar .button-ghost:hover { background: rgba(255, 255, 255, 0.2); }

main {
    max-width: 720px;
    margin: 1.5rem auto;
    padding: 0 1rem;
}

h1, h2, h3 { line-height: 1.2; margin: 1.5rem 0 0.75rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }

/* ====================== Card / rows ====================== */

.card {
    background: var(--bg);
    border-radius: var(--radius-card);
    padding: 1rem 1.25rem;
    margin: 1rem 0;
    box-shadow: var(--shadow-card);
}

.card-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
}
.card-row + .card-row { margin-top: 0.5rem; }
.label { color: var(--muted); font-size: 0.875rem; }
.value { font-weight: 600; }
.value-large { font-size: 1.5rem; font-weight: 700; }

.muted { color: var(--muted); }
.warn  { color: var(--warn); }
.danger { color: var(--danger); }

/* ====================== Budget bar ====================== */

.budget-bar {
    height: 0.5rem;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 0.5rem;
}
.budget-bar-fill {
    height: 100%;
    background: var(--accent);
    transition: width 200ms;
}
.budget-bar-fill.over { background: var(--warn); }

/* ====================== Control grouping ======================
   CONVENTION: interactive controls (buttons, inputs, selects) must never
   visually touch. Always group adjacent controls in a flex container with
   `gap` — never place two controls as bare siblings. Use one of:
     .action-row  (shared.css) — a row of buttons
     .field-row   (below)      — label + input + optional action button
     .log-tabs / .pager        — purpose-built groups
   The shared form layout already spaces stacked fields via `form { gap }`.
*/

/* Label + control (+ action) on one line, evenly spaced and wrapping. */
.field-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    margin: 0.25rem 0;
}

/* Label text stacked above its control (feeding picker search box). */
.field-stack {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
/* Full-width, left-aligned list buttons (larder + catalog picker results),
   stacked so adjacent options never touch — Spec: controls never touch. */
.is-block {
    display: block;
    width: 100%;
    text-align: left;
    margin: 0.25rem 0;
}
/* A compact standalone input (outside <form>, so it needs its own look). */
.field-input {
    width: 6rem;
    padding: 0.6rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    background: var(--bg);
    color: inherit;
    font: inherit;
    -webkit-appearance: none;
            appearance: none;
}
.field-input:focus {
    outline: 2px solid var(--focus);
    outline-offset: 1px;
    border-color: var(--focus);
}
/* The picker search box opts into full width via .is-block, but plain
   `.is-block` loses to the later, equal-specificity `.field-input { width:6rem }`.
   This combined selector wins so the feeding search field spans the row. */
.field-input.is-block { width: 100%; }

/* ====================== Forms ====================== */

form { display: flex; flex-direction: column; gap: 0.75rem; }
form label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.875rem;
    color: var(--muted);
}
form input, form select, form textarea {
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    background: var(--bg);
    color: inherit;
    font-size: 1rem;
    font-family: inherit;
    -webkit-appearance: none;
            appearance: none;
}
form input:focus, form select:focus, form textarea:focus {
    outline: 2px solid var(--focus);
    outline-offset: 1px;
    border-color: var(--focus);
}
/* Checkboxes/radios must keep their native rendering — the blanket
   `appearance: none` above otherwise strips the check/fill so the control
   looks empty even when on. Restore native look + theme the fill. */
form input[type="checkbox"], form input[type="radio"] {
    -webkit-appearance: auto;
    appearance: auto;
    width: 1.1rem;
    height: 1.1rem;
    padding: 0;
    margin: 0;
    flex: none;
    accent-color: var(--primary);
}

/* Collapsible advanced-options block inside forms. */
.advanced-options {
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    padding: 0.5rem 0.75rem;
}
.advanced-options > summary {
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--muted);
    font-weight: 600;
}
.advanced-options[open] > summary { margin-bottom: 0.5rem; }

/* ====================== Buttons ====================== */

.button-primary,
.button-accent,
.button-ghost,
.button-danger {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 2.5rem;
    padding: 0.6rem 1.1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-control);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.button-primary { background: var(--primary); color: #fff; }
.button-accent  { background: var(--accent);  color: #fff; }
.button-ghost   { background: var(--bg); color: var(--text); border-color: var(--border); }
.button-danger  { background: var(--danger); color: #fff; }
.button-primary:active,
.button-accent:active,
.button-ghost:active,
.button-danger:active { transform: translateY(1px); }
.button-primary:disabled,
.button-accent:disabled,
.button-ghost:disabled,
.button-danger:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ====================== Impersonation banner ====================== */

.impersonation-banner {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    background: #b45309;
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
}
.impersonation-banner .button-ghost {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.45);
    min-height: 2rem;
    padding: 0.3rem 0.8rem;
}

/* ====================== Pager (numbered pages) ====================== */

.pager {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin: 1.25rem 0 0.5rem;
}
.pager-btn {
    appearance: none;
    min-width: 2.25rem;
    min-height: 2.25rem;
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    background: var(--bg);
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}
.pager-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.pager-btn-active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ====================== Recommendation row (vet budget aid) ====================== */

.recommendation-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin: 0.25rem 0 0.5rem;
}
.recommendation-row .button-ghost {
    min-height: 2rem;
    padding: 0.3rem 0.8rem;
}

/* ====================== Correctable entry rows ====================== */

.entry-row {
    list-style: none;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}
.entry-row:last-child { border-bottom: none; }
.entry-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}
.entry-tail {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.entry-action {
    min-height: 1.9rem;
    padding: 0.25rem 0.7rem;
    font-size: 0.85rem;
}
.entry-label { width: auto; flex: 1 1 8rem; min-width: 6rem; }
/* `.hidden` (shared.css) must beat the `display:flex` of these rows when
   the edit/display halves toggle — raise specificity so it wins. */
.entry-row .field-row.hidden,
.entry-row .action-row.hidden,
.entry-row .entry-main.hidden { display: none; }

/* Collapsible history entry: summary row (date + value + disclosure chevron),
   body revealed on expand (edit controls + photos). */
.entry-summary {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    list-style: none;
}
.entry-summary::-webkit-details-marker { display: none; }
.entry-summary::before {
    content: "▸";
    color: var(--muted);
    font-size: 0.8em;
    flex: 0 0 auto;
    transition: transform 0.15s ease;
}
.entry-details[open] > .entry-summary::before { transform: rotate(90deg); }
.entry-summary .value { margin-left: auto; }
.entry-body {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.5rem 0 0.25rem 1.4rem;
}

/* ====================== Lists ====================== */

.pet-list a {
    text-decoration: none;
    color: var(--text);
    display: block;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}
.pet-list a:hover { background: var(--bg-soft); }

/* ====================== Alerts ====================== */

.alert {
    background: #fef3c7;
    color: #92400e;
    border-left: 4px solid var(--warn);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-control);
}
.alert.danger { background: #fee2e2; color: var(--danger); border-color: var(--danger); }

/* ====================== Monospace token ====================== */

.code-token {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-weight: 600;
}

/* ====================== Asset uploader ======================
   (Gallery/tile/thumb/label moved to shared.css so the shared
   AssetGallery component is styled on mobile too.) */

.followup-attach {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--border);
}
.followup-attach h3 {
    font-size: 0.95rem;
    margin: 0 0 0.5rem;
    color: var(--muted);
}


/* ====================== Lightbox ====================== */

.lightbox-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    z-index: 1000;
}
.lightbox {
    background: var(--bg);
    border-radius: var(--radius-card);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-width: min(90vw, 1024px);
    max-height: 90vh;
}
.lightbox-stage {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    min-height: 50vh;
}
.lightbox-img {
    display: block;
    max-width: 100%;
    max-height: calc(90vh - 70px);
    object-fit: contain;
}
.lightbox-nav {
    appearance: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 0;
    font-size: 2rem;
    line-height: 1;
    width: 2.5rem;
    height: 4rem;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    user-select: none;
}
.lightbox-nav:hover:not(:disabled) { background: rgba(255, 255, 255, 0.3); }
.lightbox-nav:disabled { opacity: 0.2; cursor: not-allowed; }
.lightbox-nav-prev { left: 0.5rem; border-radius: 0 0.5rem 0.5rem 0; }
.lightbox-nav-next { right: 0.5rem; border-radius: 0.5rem 0 0 0.5rem; }
.lightbox-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    align-items: center;
    justify-content: flex-end;
}
.lightbox-actions .muted { margin-right: auto; }
.lightbox-meta {
    margin: 0;
    padding: 0.5rem 1rem 0;
    text-align: center;
    font-size: 0.85rem;
}
