/**
 * Shared reset + layout primitives (code_standards.md §2.1/§2.5). Plain CSS, no preprocessor.
 *
 * Theming: every color that represents one of the fixed 12 color roles is referenced via
 * `var(--color-x)`, populated by `GET /api/v1/theme/current.css` -- as of Phase 4.8 there is exactly
 * one active theme for the whole application, served identically to every page (authenticated or not),
 * so every page links that one endpoint (architecture.md §11, code_standards.md §2.7). Only pure
 * non-brand UI chrome (box-shadow blur/spread/color, `transparent`, a one-off scrim, or a color with no
 * matching role -- see the button text-color note below) stays a plain hardcoded value, per §2.7's
 * explicit carve-out.
 */

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

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

/**
 * Phase 4.8 width constraint (human-requested, exact spec): the overall app shell (navbar inner content
 * + sidebar/main region together) uses a responsive percentage-based width, not a fixed pixel width --
 * at the human's reference resolution of Full HD 1920x1080 this yields ~1728px of content width with
 * ~96px of margin on each side. One shared class, referenced everywhere a width-constrained region is
 * needed (scripts/lib/layout.js's shell markup, and login.html) rather than duplicated per page/rule.
 */
.app-shell {
  width: 90%;
  max-width: 1728px;
  margin: 0 auto;
}

.page-shell {
  max-width: 420px;
  margin: 48px auto;
  padding: 32px;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

h1 {
  font-size: 1.25rem;
  margin: 0 0 4px;
}

.page-subtitle {
  margin: 0 0 24px;
  color: var(--color-text-secondary);
  font-size: 0.9rem;
}

form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

label {
  font-size: 0.85rem;
  font-weight: 600;
}

/**
 * Shared form-control styling (Phase 4.10 pass) -- applies app-wide (text inputs, number/date/tel/
 * search, <select>, <textarea>) so nothing falls back to unstyled native browser chrome, which can
 * look broken/inverted in dark mode (e.g. a native <select> rendering white-on-white). Background/text
 * come from --color-surface/--color-text-primary rather than browser/OS defaults so every control
 * tracks the active theme in both light and dark mode. Radius matches this project's existing
 * button/input radius (6px, see button rules below).
 */
input[type='text'],
input[type='email'],
input[type='password'],
input[type='number'],
input[type='date'],
input[type='tel'],
input[type='search'],
select,
textarea {
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  background-color: var(--color-surface);
  color: var(--color-text-primary);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
  resize: vertical;
}

input[type='text']:focus,
input[type='email']:focus,
input[type='password']:focus,
input[type='number']:focus,
input[type='date']:focus,
input[type='tel']:focus,
input[type='search']:focus,
select:focus,
textarea:focus,
input[type='text']:focus-visible,
input[type='email']:focus-visible,
input[type='password']:focus-visible,
input[type='number']:focus-visible,
input[type='date']:focus-visible,
input[type='tel']:focus-visible,
input[type='search']:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 20%, transparent);
}

/* Checkboxes/radios -- native controls, just tinted to the active theme's primary color instead of the
   browser/OS default accent, plus a visible focus ring matching the rest of the form controls above. */
input[type='checkbox'],
input[type='radio'] {
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary);
  cursor: pointer;
}

input[type='checkbox']:focus-visible,
input[type='radio']:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

button {
  padding: 10px 16px;
  border: 1px solid var(--color-primary);
  border-radius: 6px;
  background-color: var(--color-primary);
  /* Button foreground text has no dedicated role in the fixed 12 (architecture.md §11.1) -- it only
     needs to contrast against --color-primary, which every preset (incl. Midnight's light primary)
     keeps light-on-dark/dark-on-light consistent with a plain white. Treated the same as §2.7's
     "pure black/white, no brand meaning" carve-out; flagged to the PM as a possible future dedicated
     role if a preset ever breaks this assumption. */
  color: #ffffff;
  font-size: 1rem;
  cursor: pointer;
  transition: background-color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}

button:hover {
  background-color: var(--color-primary-hover);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

button:disabled {
  background-color: var(--color-secondary);
  border-color: var(--color-secondary);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

button.secondary {
  background-color: var(--color-surface);
  color: var(--color-secondary);
  border-color: var(--color-secondary);
}

button.secondary:hover {
  background-color: var(--color-background);
}

.help-text {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  margin: 0;
}

.error-list {
  background-color: color-mix(in srgb, var(--color-danger) 12%, var(--color-surface));
  border: 1px solid var(--color-danger);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--color-danger);
  font-size: 0.9rem;
}

.error-list ul {
  margin: 0;
  padding-left: 18px;
}

.success-panel {
  background-color: color-mix(in srgb, var(--color-success) 12%, var(--color-surface));
  border: 1px solid var(--color-success);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--color-success);
  font-size: 0.9rem;
}

/**
 * Phase 12 -- first-time TOTP enrollment QR display (login.html/portal-login.html). Deliberately fixed
 * white/black rather than `var(--color-x)` -- a QR code's own modules aren't themeable brand content
 * (code_standards.md §2.7's documented non-brand-chrome carve-out), and the SVG backend/lib/totp.php's
 * build_totp_qr_svg() returns has no background rect of its own (BaconQrCode's SvgImageBackEnd only
 * draws the dark modules), so without a fixed light frame the code would render transparent and could
 * become unscannable against a dark active theme/color-mode. This must stay legible regardless of
 * whatever theme/light-dark-mode is currently active app-wide.
 */
.totp-enroll-qr-frame {
  display: flex;
  justify-content: center;
  padding: 16px;
  background-color: #ffffff;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.totp-enroll-qr-frame svg {
  width: 220px;
  height: 220px;
}

.totp-enroll-secret {
  display: block;
  padding: 8px 10px;
  background-color: var(--color-background);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
  user-select: all;
  word-break: break-all;
}

/* Phase 10 -- non-blocking soft-dependency warning banner (master_requirements.md §3: `clients`
   disabled while a dependent module like `ticketing`/`invoicing_billing`/`client_portal` stays
   enabled). Same visual convention as `.error-list`/`.success-panel` immediately above, just keyed to
   --color-warning -- a warning, never a hard block, so the page underneath it stays fully usable. */
.warning-panel {
  background-color: color-mix(in srgb, var(--color-warning) 12%, var(--color-surface));
  border: 1px solid var(--color-warning);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--color-warning);
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.links-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-top: 8px;
}

.links-row a {
  color: var(--color-primary);
}

[hidden] {
  display: none !important;
}

/* Phase 4.7 B1 -- persistent "Viewing as" impersonation banner (architecture.md §12), injected by
   nav.js's initShell() at the very top of <body> on every authenticated page whenever the session is
   an impersonation session. Deliberately high-contrast/full-width/sticky so it's impossible to confuse
   with normal page chrome -- --color-warning is the correct role here (a warning-level, always-visible
   state banner), not --color-info, since impersonation is an elevated-privilege condition the acting
   Super Admin must never lose track of. */
.impersonation-banner {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 20px;
  background-color: var(--color-warning);
  color: var(--color-text-primary);
  border-bottom: 2px solid var(--color-border);
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
}

.impersonation-banner button {
  padding: 6px 12px;
  font-size: 0.85rem;
}

/* Password requirement checklist (password-reset-confirm.html) */
.policy-checklist {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.85rem;
}

.policy-checklist li {
  padding: 2px 0;
  color: var(--color-text-secondary);
}

.policy-checklist li.met {
  color: var(--color-success);
}

.strength-meter {
  height: 6px;
  background-color: var(--color-border);
  border-radius: 3px;
  overflow: hidden;
}

.strength-meter-fill {
  height: 100%;
  width: 0%;
  background-color: var(--color-secondary);
}

.identity-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Anchor-as-button — same visual treatment as <button>, used where the action is really a navigation
   (e.g. "New Client", "Go to Clients") rather than a form submit/JS handler. */
a.button-link {
  display: inline-block;
  padding: 10px 16px;
  border: 1px solid var(--color-primary);
  border-radius: 6px;
  background-color: var(--color-primary);
  /* Same non-role foreground carve-out as button's `color` above. */
  color: #ffffff;
  font-size: 0.9rem;
  text-decoration: none;
  cursor: pointer;
  text-align: center;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

a.button-link:hover {
  background-color: var(--color-primary-hover);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

a.button-link:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

a.button-link.secondary {
  background-color: var(--color-surface);
  color: var(--color-secondary);
  border-color: var(--color-secondary);
}

a.button-link.secondary:hover {
  background-color: var(--color-background);
}
