/* 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);
}
.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; }

/* 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; }
}
