/* Modern interface layer. Loaded after base.html's own styles, so it refines them
   without rewriting every template. Colours come from the tenant theme variables
   (--brand etc. in _theme.html): nothing here is tied to one customer's brand. */

:root {
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --ring: color-mix(in srgb, var(--brand) 28%, transparent);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 1px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.07), 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.12), 0 4px 10px rgba(15, 23, 42, 0.06);
}

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: Inter, "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
  background:
    radial-gradient(900px 420px at 8% -8%, color-mix(in srgb, var(--brand) 9%, transparent) 0%, transparent 70%),
    radial-gradient(700px 380px at 100% 0%, color-mix(in srgb, var(--brand) 5%, transparent) 0%, transparent 70%),
    var(--bg);
  background-attachment: fixed;
}
h1 { font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem); letter-spacing: -0.02em; font-weight: 750; }
h2 { font-size: clamp(1.2rem, 1.05rem + 0.6vw, 1.45rem); letter-spacing: -0.015em; }
h3 { letter-spacing: -0.01em; }
a { text-underline-offset: 3px; }
::selection { background: color-mix(in srgb, var(--brand) 22%, transparent); }

/* Keyboard focus is always visible, and only for the keyboard. */
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
:focus:not(:focus-visible) { outline: none; }

/* Skip link */
.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 200;
  background: var(--brand); color: #fff; padding: 10px 14px; border-radius: 10px; font-weight: 700;
}
.skip-link:focus { top: 10px; }

/* === Header: compact, glassy, sticky === */
header {
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: saturate(170%) blur(14px);
  -webkit-backdrop-filter: saturate(170%) blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset, 0 6px 20px rgba(15, 23, 42, 0.04);
}
.header-inner { padding: 8px var(--pad); flex-wrap: nowrap; gap: 16px; }
.header-nav { width: auto; order: 0; margin-left: auto; }
.brand { gap: 10px; font-size: 1.05rem; letter-spacing: -0.01em; }
.brand img, .brand-logo { width: 36px !important; height: 36px !important; object-fit: contain; border-radius: 9px; }
nav { gap: 2px; justify-content: flex-end; }
nav a {
  position: relative; padding: 8px 14px; border-radius: 999px; font-size: 0.93rem; font-weight: 600;
  transition: background-color 160ms var(--ease), color 160ms var(--ease);
}
nav a:hover { background: color-mix(in srgb, var(--brand) 8%, transparent); color: var(--text); }
nav a[aria-current="page"] {
  color: var(--brand-strong);
  background: color-mix(in srgb, var(--brand) 12%, transparent);
}
/* Compact language switcher in the desktop top nav: just the select, inline with
   the nav links (the full labelled form is kept for the phone drawer). */
.lang-switcher-compact { margin: 0 0 0 6px; }
.lang-switcher-compact .nav-drawer-label { display: none; }
.lang-switcher-compact .row { gap: 0; }
.lang-switcher-compact select {
  min-height: 38px; padding: 6px 30px 6px 12px; font-size: 0.9rem;
  border-radius: 999px; width: auto;
}
.hamburger {
  border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-sm);
  transition: transform 140ms var(--ease), box-shadow 140ms var(--ease);
}
.hamburger:active { transform: scale(0.94); }
@media (max-width: 768px) {
  .header-inner { padding: 8px 14px; }
  .header-left { flex: 1; }
}

/* === Cards and panels: layered depth, gentle lift === */
.card, .panel, .tile {
  border-radius: 16px;
  border-color: color-mix(in srgb, var(--border) 85%, transparent);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 200ms var(--ease), transform 200ms var(--ease), border-color 200ms var(--ease);
}
a.card:hover, a.tile:hover, .card.clickable:hover, .tile:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--brand) 30%, var(--border));
}

/* === Buttons === */
.btn {
  border-radius: 12px; font-weight: 650; letter-spacing: -0.005em;
  background: linear-gradient(180deg, color-mix(in srgb, var(--brand) 92%, #fff) 0%, var(--brand) 100%);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12), 0 6px 14px color-mix(in srgb, var(--brand) 26%, transparent);
  transition: transform 140ms var(--ease), box-shadow 140ms var(--ease), background-color 140ms var(--ease);
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 2px 4px rgba(15, 23, 42, 0.14), 0 10px 20px color-mix(in srgb, var(--brand) 30%, transparent); }
.btn:active { transform: translateY(0) scale(0.985); box-shadow: var(--shadow-sm); }
.btn.secondary { background: var(--surface); box-shadow: var(--shadow-sm); }
.btn.secondary:hover { box-shadow: var(--shadow-md); }
.btn.ghost, .btn.ghost:hover { box-shadow: none; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }

/* === Form controls: every input type, not just text === */
input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="submit"]):not([type="button"]):not([type="file"]),
select, textarea {
  padding: 11px 14px; min-height: 44px; font: inherit; font-size: 16px;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  box-shadow: inset 0 1px 1px rgba(15, 23, 42, 0.03);
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease), background-color 140ms var(--ease);
  max-width: 100%;
}
input[type="search"] { -webkit-appearance: none; appearance: none; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):focus,
select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--ring);
  outline: none;
}
input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):hover:not(:focus),
select:hover:not(:focus), textarea:hover:not(:focus) { border-color: color-mix(in srgb, var(--brand) 35%, var(--border)); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--brand); width: 18px; height: 18px; }
input[type="file"] { max-width: 100%; }
select { padding-right: 34px; }

/* Click-to-edit text (behaviour in ui.js, form[data-inline-edit]): an input that
   reads as plain text until clicked, inheriting the surrounding font. The
   negative margin cancels padding + border so at rest it lines up with plain
   text. !important because the form-control rule above is far more specific. */
input.inline-edit {
  margin: 0 0 0 -7px !important; padding: 3px 6px !important; min-height: 0 !important;
  font-family: inherit; font-size: inherit !important; font-weight: inherit !important;
  line-height: inherit; color: inherit !important;
  border: 1px solid transparent !important; background: transparent !important;
  box-shadow: none !important; border-radius: 8px !important;
  cursor: text; text-overflow: ellipsis; max-width: 100%;
}
input.inline-edit::placeholder { color: var(--muted); font-style: italic; font-weight: 400; }
input.inline-edit:hover:not(:focus) { border-color: var(--border) !important; }
input.inline-edit:focus {
  text-transform: none; background: var(--surface) !important;
  border-color: var(--brand) !important; box-shadow: 0 0 0 3px var(--ring) !important;
}
input.inline-edit[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input.inline-edit[type="number"]::-webkit-inner-spin-button,
input.inline-edit[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
/* As a card heading (e.g. a shopping list's title). */
input.inline-edit.inline-edit--heading { font-size: 14px !important; font-weight: 800 !important; }
input.inline-edit.inline-edit--heading:focus { font-weight: 600 !important; }
/* 16px while editing on a phone, so iOS does not zoom the page. */
@media (max-width: 640px) { input.inline-edit:focus { font-size: 16px !important; } }

/* Present for screen readers and form behaviour (e.g. a default submit button),
   invisible on screen. */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* The Ask box and other search rows: a full-width input that keeps its button beside it. */
form.row > input[type="text"], form.row > input[type="search"], form.row > input:not([type]) { flex: 1 1 220px; min-width: 0; }

/* === Flash messages as soft toasts === */
.flash {
  border-radius: 14px; box-shadow: var(--shadow-md);
  animation: toastIn 320ms var(--ease) both;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px) scale(0.98); } to { opacity: 1; transform: none; } }

/* === Drawer: nothing may leak while closed === */
.nav-drawer { box-shadow: none; visibility: hidden; transition: transform 280ms var(--ease), visibility 0s linear 280ms; border-radius: 20px 0 0 20px; }
.nav-drawer.open { box-shadow: var(--shadow-lg); visibility: visible; transition: transform 280ms var(--ease), visibility 0s; }
.nav-drawer a { border-radius: 12px; }
.nav-overlay { backdrop-filter: blur(4px); }

/* === Tables and lists === */
/* Wrap a wide table so it scrolls sideways instead of being clipped by the card and
   body overflow:hidden (mobile UX review 2026-09-23, A1/A3). */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: separate; border-spacing: 0; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
tbody tr { transition: background-color 120ms var(--ease); }
tbody tr:hover { background: color-mix(in srgb, var(--brand) 4%, transparent); }

/* === Page entrance and reduced motion === */
/* No `both` fill: it left the final keyframe's transform (translateY(0)) on <main>
   after the animation, and any transform makes <main> the containing block for every
   position:fixed modal - so Save buttons and dialogs anchored to it instead of the
   viewport and landed off-screen on a phone (mobile UX review 2026-09-23, B1). Without
   the fill, the transform reverts to none once the entrance finishes. */
main { animation: pageIn 260ms var(--ease); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* A row of related actions that should wrap side by side rather than stack full-width
   on a phone - e.g. the topic header's Resources/Contacts/Knowledge, or a Save/Cancel
   pair (mobile UX review 2026-09-23, P6/P13). Works on any viewport. */
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; width: auto; }

/* === Phone === */
@media (max-width: 640px) {
  main { padding-left: 14px; padding-right: 14px; }
  .btn { width: auto; }
  form.row .btn, .card .btn { width: 100%; }
  /* Action rows stay horizontal and wrap, instead of stacking to full width. */
  .actions-row { flex-direction: row; flex-wrap: wrap; }
  .actions-row .btn { width: auto; flex: 1 1 40%; }
  .btn-row .btn { width: auto; }
}
@media (hover: none) {
  a.card:hover, a.tile:hover, .tile:hover, .btn:hover { transform: none; }
}

/* === Touch targets (mobile UX review 2026-09-23, P5 + P3) ===
   Lift the controls measured under 44x44 to a 44px hit area on a touch screen or a
   phone-width viewport. Desktop with a mouse is untouched. */
@media (pointer: coarse), (max-width: 640px) {
  .hamburger { min-width: 44px; min-height: 44px; }
  .subtabs a { min-height: 44px; display: inline-flex; align-items: center; }
  .flash-close { width: 44px; height: 44px; }
  .nav-drawer-close { width: 44px; height: 44px; }
  .breadcrumb a, .faq-link,
  a[href^="tel:"], a[href^="mailto:"] { display: inline-flex; align-items: center; min-height: 44px; }
  summary { min-height: 44px; }
  .reaction-btn, .btn.sm, .tab-btn, .view-btn { min-height: 44px; }
  .fc .fc-button { min-height: 44px; }
  input[type="checkbox"], input[type="radio"] { width: 24px; height: 24px; }
  label:has(> input[type="checkbox"]) { min-height: 44px; display: inline-flex; align-items: center; gap: 8px; }

  /* Maintenance hub to-do controls: give the small check, snooze and day-nav buttons
     a real 44px target, and drop the drag handle (HTML5 drag never fires on touch). */
  .planner-check-btn { width: 44px; height: 44px; }
  .planner-nav-btn { width: 44px; height: 44px; }
  .planner-task .todo-snooze { position: relative; min-width: 44px; min-height: 44px; }
  .planner-task .todo-snooze select { min-width: 44px; min-height: 44px; }
}
@media (pointer: coarse) {
  .drag-handle { display: none; }
}

/* === Settings / form layout helpers ===
   Account and admin pages had grown a bespoke inline style on every label,
   grid and divider, so the "boxes" drifted out of alignment with each other.
   These give one shared vocabulary — a labelled field, a responsive field
   grid, a titled subsection divider and a help line — so a settings page reads
   as one uniform surface. All colours come from the theme tokens. */
.stack { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span, .field-label {
  font-size: 0.82rem; font-weight: 600; letter-spacing: 0.01em; color: var(--muted);
}
.field-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
.field-grid .col-all { grid-column: 1 / -1; }
.subsection { margin-top: 16px; }
.subsection + .subsection { padding-top: 16px; border-top: 1px solid var(--border); }
.subhead { font-weight: 700; margin-bottom: 6px; }
.help { color: var(--muted); font-size: 0.9rem; margin-bottom: 12px; }
.help:last-child { margin-bottom: 0; }
/* The read-only feed/URL row: an input that keeps its button beside it and wraps
   cleanly on a phone. */
.field-inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.field-inline > input { flex: 1 1 220px; min-width: 0; }

/* Visible form validation (ui.js): a field that needs attention, the line under it
   saying what is missing, and the note by the submit button. Red, from one token. */
:root { --danger: #dc2626; }
.field-invalid,
.field-invalid:focus {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 22%, transparent) !important;
}
.field-error {
  color: var(--danger); font-size: 0.85rem; font-weight: 600;
  margin: 4px 0 8px;
}
.form-error-summary {
  color: var(--danger); background: var(--error-bg, #fef2f2);
  border: 1px solid var(--error-border, #fecaca); border-radius: 8px;
  padding: 8px 10px; margin: 8px 0; font-size: 0.9rem; font-weight: 600;
  flex-basis: 100%;
}

/* === Photo viewer (photo_viewer.js) ===
   A photo opens over the page with a big Close, so the installed phone app - no
   browser chrome - always has a way back (owner, 29 Oct 2026). */
.pv-overlay { position: fixed; inset: 0; z-index: 10000; display: flex; align-items: center;
  justify-content: center; background: rgba(0, 0, 0, 0.92); }
.pv-overlay[hidden] { display: none; }
.pv-img { max-width: 100vw; max-height: 100vh; max-height: 100dvh; object-fit: contain;
  -webkit-user-select: none; user-select: none; }
.pv-btn { position: absolute; display: flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; border: 0; border-radius: 50%; background: rgba(0, 0, 0, 0.55);
  color: #fff; font-size: 26px; line-height: 1; cursor: pointer; }
.pv-btn[hidden], .pv-count[hidden] { display: none; }
.pv-btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.pv-close { top: calc(env(safe-area-inset-top, 0px) + 10px); right: calc(env(safe-area-inset-right, 0px) + 10px); }
.pv-prev { left: calc(env(safe-area-inset-left, 0px) + 8px); top: 50%; transform: translateY(-50%); font-size: 34px; }
.pv-next { right: calc(env(safe-area-inset-right, 0px) + 8px); top: 50%; transform: translateY(-50%); font-size: 34px; }
.pv-count { position: absolute; top: calc(env(safe-area-inset-top, 0px) + 22px); left: 50%;
  transform: translateX(-50%); color: #e5e7eb; font-size: 14px; }
.pv-full { position: absolute; bottom: calc(env(safe-area-inset-bottom, 0px) + 14px); left: 50%;
  transform: translateX(-50%); padding: 10px 16px; min-height: 44px; display: inline-flex; align-items: center;
  border-radius: 999px; background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 14px; text-decoration: none; }
html.pv-open, html.pv-open body { overflow: hidden; }
