/* ==========================================================================
   R4 Restoration brand theme — layered on top of Bootstrap 5.
   Source: R4 Restoration Claude Design System (tokens/colors.css,
   typography.css, spacing.css, base.css). Values below are copied from
   those files; update from the design system there, not invented here.

   Heading sizes are scaled down from the source marketing-site tokens
   (h1 56px there) to fit a dense admin UI — the design system itself notes
   it was built for a marketing site, not this product, since no app UI was
   attached when it was generated. Color, type family, weight, casing,
   spacing and radii are otherwise copied as-is.
   ========================================================================== */

:root {
  /* ---- Brand palette (tokens/colors.css) ---- */
  --r4-blueprint: #3399ff;
  --r4-bluesky: #76e5ff;
  --r4-navy-slate: #57687f;
  --r4-shou-sugi-ban: #2c3036;
  --r4-tar-black: #221f1f;
  --r4-duck-yellow: #ffcb37;
  --r4-concrete: #eff1f3;
  --r4-grey-40: #c5ccd3;
  --r4-grey-20: #9099a3;
  --r4-white: #ffffff;
  --r4-fire: #f37032;
  --r4-mold: #90cc4b;
  --r4-storm: #9099a3;
  --r4-gradient-blue: linear-gradient(120deg, var(--r4-blueprint) 0%, var(--r4-bluesky) 100%);

  --color-brand-primary: var(--r4-blueprint);
  --color-brand-secondary: var(--r4-navy-slate);
  --color-brand-accent: var(--r4-duck-yellow);
  --surface-page: var(--r4-white);
  --surface-muted: var(--r4-concrete);
  --surface-dark: var(--r4-shou-sugi-ban);
  --surface-card: var(--r4-white);
  --border-default: var(--r4-grey-40);
  --border-strong: var(--r4-grey-20);
  --text-heading: var(--r4-tar-black);
  --text-body: var(--r4-shou-sugi-ban);
  --text-muted: var(--r4-navy-slate);
  --text-on-dark: var(--r4-white);
  --text-link: var(--r4-blueprint);
  --text-link-hover: #1f7fe0;
  --status-fire: var(--r4-fire);
  --status-water: var(--r4-blueprint);
  --status-mold: var(--r4-mold);
  --status-storm: var(--r4-storm);
  --focus-ring: var(--r4-blueprint);

  /* ---- Type (tokens/typography.css) ---- */
  --font-body: 'Open Sans', system-ui, sans-serif;
  --font-display: 'League Gothic', 'Open Sans', system-ui, sans-serif;
  --ls-heading-caps: 0.02em;
  --lh-heading: 1.15;
  --lh-body: 1.6;

  /* ---- Spacing / radii / shadow (tokens/spacing.css) ---- */
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 24px; --space-6: 32px; --space-7: 48px; --space-8: 64px; --space-9: 96px;
  --radius-sm: 4px; --radius-md: 8px; --radius-lg: 14px;
  --notch-size: 22px;
  --shadow-sm: 0 1px 2px rgba(34, 31, 31, 0.08);
  --shadow-md: 0 4px 16px rgba(44, 48, 54, 0.10);
  --shadow-lg: 0 12px 32px rgba(44, 48, 54, 0.16);
  --ease-standard: cubic-bezier(.4, 0, .2, 1);

  /* ---- Bootstrap root variables that genuinely cascade from :root ---- */
  --bs-body-font-family: var(--font-body);
  --bs-body-color: var(--text-body);
  --bs-body-bg: var(--surface-muted);
  --bs-border-color: var(--border-default);
  --bs-border-radius: var(--radius-md);
  --bs-border-radius-sm: var(--radius-sm);
  --bs-border-radius-lg: var(--radius-lg);
  --bs-link-color: var(--text-link);
  --bs-link-color-rgb: 51, 153, 255;
  --bs-link-hover-color: var(--text-link-hover);
  --bs-emphasis-color: var(--text-heading);
  --bs-box-shadow: var(--shadow-md);
  --bs-box-shadow-sm: var(--shadow-sm);
  --bs-box-shadow-lg: var(--shadow-lg);
}

/* ---- Headings: League Gothic, uppercase, brand tracking (tokens/base.css) ----
   Sizes are admin-density, not the 56/40/28/22px marketing-site scale. */
h1, h2, h3 {
  font-family: var(--font-display);
  color: var(--text-heading);
  text-transform: uppercase;
  letter-spacing: var(--ls-heading-caps);
  line-height: var(--lh-heading);
}
/* Bootstrap's reboot zeroes every heading's margin-top, so back-to-back
   sections (a stat grid followed directly by "Everything else", a table
   followed by the next h2, …) had no breathing room at all — h1 stays
   flush with the page's own top padding, but h2/h3 need real separation
   from whatever precedes them. */
h1 { font-size: 1.9rem; font-weight: 400; margin-bottom: var(--space-5); }
h2 { font-size: 1.3rem; font-weight: 400; margin-top: var(--space-7); margin-bottom: var(--space-4); }
h3 { font-size: 1.1rem; font-weight: 400; margin-top: var(--space-5); margin-bottom: var(--space-3); }
h4, h5, h6 {
  font-family: var(--font-body);
  font-weight: 800;
  color: var(--text-heading);
}
body { line-height: var(--lh-body); }

/* ---- Bootstrap component overrides: Bootstrap's precompiled CSS bakes
   literal colors per component/variant, so root-var overrides alone don't
   retheme them — these target the exact classes this app actually uses. ---- */
.btn-primary {
  --bs-btn-bg: var(--color-brand-primary);
  --bs-btn-border-color: var(--color-brand-primary);
  --bs-btn-hover-bg: var(--text-link-hover);
  --bs-btn-hover-border-color: var(--text-link-hover);
  --bs-btn-active-bg: var(--text-link-hover);
  --bs-btn-active-border-color: var(--text-link-hover);
  --bs-btn-disabled-bg: var(--color-brand-primary);
  --bs-btn-disabled-border-color: var(--color-brand-primary);
  --bs-btn-focus-shadow-rgb: 51, 153, 255;
}
.btn-outline-secondary {
  --bs-btn-color: var(--text-heading);
  --bs-btn-border-color: var(--border-strong);
  --bs-btn-hover-bg: var(--surface-muted);
  --bs-btn-hover-color: var(--text-heading);
  --bs-btn-hover-border-color: var(--border-strong);
}
.btn-outline-danger { --bs-btn-focus-shadow-rgb: 220, 53, 69; }

.form-control:focus, .form-select:focus, .form-check-input:focus {
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 .25rem rgba(51, 153, 255, .25);
}
/* A 16px box needs more edge contrast than a full-width input to read as
   "present" at a glance — the theme's default border/fill (--border-default
   on --surface-muted) is subtle by design for large surfaces and all but
   disappears at checkbox size. */
.form-check-input {
  background-color: var(--surface-card);
  border-color: var(--border-strong);
}
.form-check-input:checked {
  background-color: var(--color-brand-primary);
  border-color: var(--color-brand-primary);
}

.nav-pills .nav-link.active {
  color: var(--color-brand-primary) !important;
  font-weight: 600;
}

/* ---- Navbar ---- */
.navbar-dark {
  --bs-navbar-color: var(--r4-grey-40);
  --bs-navbar-hover-color: var(--r4-white);
  --bs-navbar-active-color: var(--r4-white);
  --bs-navbar-brand-padding-y: .3rem;
  --bs-navbar-nav-link-padding-x: 1rem;
  background-color: var(--surface-dark) !important;
  box-shadow: var(--shadow-md);
}
.navbar > .container-fluid { min-height: 3.75rem; gap: var(--space-4); }

.navbar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: var(--ls-heading-caps);
  font-size: 1.4rem;
  margin-right: var(--space-6);
}
.navbar-brand img { height: 1.75rem; width: auto; display: block; }

.navbar-nav { gap: .15rem; }
.navbar-nav .nav-link {
  white-space: nowrap;
  padding-top: .55rem;
  padding-bottom: .55rem;
  border-bottom: 2px solid transparent;
  transition: color .1s, border-color .1s;
}
.navbar-nav .nav-link:hover { border-bottom-color: var(--r4-grey-20); }
.navbar-nav .nav-link.active {
  color: var(--r4-white) !important;
  font-weight: 600;
  border-bottom-color: var(--color-brand-primary);
}

/* The global `a:hover { text-decoration: underline }` below is meant for
   body copy links, not chrome — nothing in the navbar (nav items, brand,
   profile dropdown toggle) should underline on hover. */
.navbar a:hover { text-decoration: none; }

/* The nav-links + avatar dropdown don't shrink, so on a full link list the
   search box is what gives when the row gets tight. Bootstrap's
   .input-group defaults to flex-wrap:wrap, which — with no room to spare —
   wrapped the search button onto its own line, orphaned under the input.
   Force it to stay one line and shrink the text field itself instead,
   down to a usable floor. */
.navbar form[role="search"] { min-width: 0; flex-shrink: 1; }
.navbar .input-group { flex-wrap: nowrap; min-width: 6rem; }
/* Field + button must share one border treatment on the dark navbar.
   Bootstrap's .form-control / .btn-outline-light disagree by default, and the
   legacy bare-input rule below is specific enough to restyle .form-control
   with a light-page border-radius that breaks the input-group seam. */
.navbar .input-group > .form-control,
.navbar .input-group > .btn {
  color: var(--r4-white);
  background-color: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: none;
}
.navbar .input-group > .form-control::placeholder { color: rgba(255, 255, 255, 0.55); }
.navbar .input-group > .form-control:focus {
  color: var(--r4-white);
  background-color: rgba(255, 255, 255, 0.12);
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 .25rem rgba(51, 153, 255, .25);
  z-index: 3;
}
.navbar .input-group > .btn:hover {
  color: var(--r4-white);
  background-color: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.5);
}

.navbar-user .pill { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.18); color: var(--r4-white); }

@media (max-width: 991.98px) {
  .navbar-user {
    border-top: 1px solid rgba(255,255,255,.12);
    margin-top: var(--space-3);
    padding-top: var(--space-3);
  }
}

.badge {
  --bs-badge-border-radius: var(--radius-sm);
  font-weight: 600;
}
.badge.text-bg-secondary { background-color: var(--surface-muted) !important; color: var(--text-body) !important; border: 1px solid var(--border-default); }

.alert-success { --bs-alert-bg: #eaf6ee; --bs-alert-border-color: #bfe2c9; --bs-alert-color: #1e5c33; }
.alert-danger { --bs-alert-bg: #fbeaea; --bs-alert-border-color: #f0c4c4; --bs-alert-color: #7a2020; }
.alert-primary { --bs-alert-bg: #e8f3ff; --bs-alert-border-color: #bfe0ff; --bs-alert-color: var(--text-heading); }

.card { box-shadow: var(--shadow-sm); }
.table > :not(caption) > * > * { background-color: transparent; }
thead, .table-light { --bs-table-bg: var(--surface-muted); }

a { text-decoration: none; }
a:hover { text-decoration: underline; }

/* Brand's signature shape device: a 45° cut bottom-right corner, used sparingly
   in place of rounded corners (the brand explicitly avoids pill shapes). */
.r4-notch {
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - var(--notch-size)), calc(100% - var(--notch-size)) 100%, 0 100%);
}

@media print {
  .navbar, .no-print { display: none !important; }
}

[x-cloak] { display: none !important; }

/* ==========================================================================
   Compatibility layer for this app's existing layout classes.

   The pass that adopted Bootstrap converted every button/table/form-control
   class to the real Bootstrap classes (btn-outline-secondary, table-hover,
   form-control, …) — those are genuinely Bootstrap now. The handful of
   classes below are this app's own small layout vocabulary (a bordered
   panel, a labeled form row, a stat tile, a status pill) that predates this
   theme and isn't part of Bootstrap's component set. Rather than rewrite
   every template's div structure into card/card-body/row/col-* (high
   rewrite risk for no visual difference), they're restyled here using
   Bootstrap's own tokens so they sit naturally alongside real Bootstrap
   components. Add a new one here instead of inventing another ad hoc class
   in a template.
   ========================================================================== */

.panel {
  background: var(--surface-card);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5) var(--space-6);
  margin-bottom: var(--space-6);
}
.field { margin-bottom: var(--space-4); }
.row-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 0 var(--space-4); }
.actions { display: flex; align-items: center; gap: var(--space-2); margin: var(--space-5) 0 var(--space-6); flex-wrap: wrap; }
.search-bar { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-6); flex-wrap: wrap; }
.search-bar input, .search-bar select { width: auto; min-width: 9rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: var(--space-4); }
.stat { background: var(--surface-card); border: 1px solid var(--bs-border-color); border-radius: var(--bs-border-radius); padding: var(--space-4) var(--space-4); box-shadow: var(--shadow-sm); }
.stat .n { font-size: 1.6rem; font-weight: 700; }
.stat .l { font-size: .78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
a.stat { color: inherit; text-decoration: none; display: block; transition: box-shadow .1s, border-color .1s; }
a.stat:hover { border-color: var(--color-brand-primary); box-shadow: var(--shadow-md); text-decoration: none; }
.pagination { display: flex; gap: var(--space-2); margin-top: var(--space-4); font-size: .85rem; }
.err { color: var(--bs-danger); font-size: .8rem; margin-top: .2rem; }
.muted { color: var(--text-muted) !important; }
.low { color: var(--bs-danger) !important; }
form.inline, .inline { display: inline; }
.pill {
  display: inline-block; padding: .1rem .5rem; font-size: .75rem; font-weight: 600;
  background: var(--surface-muted); border: 1px solid var(--bs-border-color);
  border-radius: var(--radius-sm); color: var(--text-body);
}

/* Bare form controls: same visual language as .form-control/.form-select
   without requiring that class on every <input>/<select>/<textarea> in
   ~15 templates predating this theme. Skip .form-control/.form-select —
   those already have Bootstrap sizing (and navbar input-group radius), and
   this rule's attribute-selector specificity was overriding them. */
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not(.form-control),
select:not(.form-select),
textarea:not(.form-control) {
  display: block; width: 100%; font: inherit; color: var(--text-body);
  background: var(--surface-card); border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius); padding: .375rem .75rem;
}
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not(.form-control):focus,
select:not(.form-select):focus,
textarea:not(.form-control):focus {
  outline: 0; border-color: var(--focus-ring); box-shadow: 0 0 0 .25rem rgba(51, 153, 255, .25);
}
input:disabled { background: var(--surface-muted); opacity: .75; }
/* Scoped away from .form-check-input: `input[type="checkbox"]` outranks a
   plain class selector on specificity alone, so without this exclusion it
   was clobbering Bootstrap's real .form-check-input sizing (width/height,
   appearance) down to an invisible ~2px box. This rule now only reaches the
   handful of unclassed legacy checkboxes still predating Bootstrap adoption. */
input[type="checkbox"]:not(.form-check-input) { width: auto; min-width: auto; accent-color: var(--color-brand-primary); }
label { font-size: .85rem; color: var(--text-muted); margin-bottom: .25rem; display: block; }

/* Bare <button> (no Bootstrap class): same treatment as .btn.btn-primary,
   for the many plain submit buttons predating this theme. */
button:not([class]) {
  display: inline-block; font: inherit; font-weight: 400; text-align: center; cursor: pointer;
  color: #fff; background: var(--color-brand-primary); border: 1px solid var(--color-brand-primary);
  border-radius: var(--bs-border-radius); padding: .375rem .75rem;
}
button:not([class]):hover { background: var(--text-link-hover); border-color: var(--text-link-hover); }
