/* Base Reset, Typography & Shared Executive Precision Components */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 84px;
}

body {
  margin: 0;
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-wrap: anywhere;
}

::selection {
  background-color: var(--fiamma-fucsia);
  color: #FFFFFF;
}

a {
  color: inherit;
  text-decoration: none;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button, a, input, textarea, select, summary {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

img, video, svg {
  max-width: 100%;
  display: block;
}

img {
  height: auto;
}

h1, h2, h3, h4, p, figure, dl, dd {
  margin: 0;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

em {
  font-style: normal;
  color: var(--accent-primary);
}

[hidden] {
  display: none !important;
}

/* Keyboard Focus Ring (WCAG 2.2 AA) */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* Skip Link & Screen Reader Utilities */
.skip-link {
  position: fixed;
  top: -100px;
  left: var(--space-4);
  z-index: 1000;
  background: var(--action-primary);
  color: var(--text-inverse);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-control);
  font-weight: 600;
  font-size: 13px;
  box-shadow: var(--shadow-md);
}

.skip-link:focus {
  top: var(--space-3);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.preserve-lines {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  display: block;
}

.honeypot {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* Layout Containers */
.wrap {
  width: min(var(--max-width), calc(100% - 64px));
  margin-inline: auto;
}

@media (max-width: 767px) {
  .wrap {
    width: calc(100% - 32px);
  }
}

/* Standardized Wordmark */
.wordmark {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  line-height: 0;
  color: light-dark(#000000, #FFFFFF);
}

.wordmark-logo {
  height: 20px;
  width: auto;
  max-width: 100%;
}

.wordmark-logo-dot {
  fill: var(--fiamma-fucsia, #D62F79);
}

@media (max-width: 767px) {
  .wordmark-logo {
    height: 18px;
  }
}

.wordmark-dot {
  color: var(--accent-primary);
  font-weight: 800;
  margin-inline: 1px;
}

/* Eyebrows, Labels & Status Badges */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-primary);
}

.micro-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-pill);
  background-color: var(--accent-primary);
  flex-shrink: 0;
}

.status-dot-muted {
  background-color: var(--border-strong);
}

.status,
.badge,
.category-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.01em;
  background-color: var(--surface-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.category-label {
  color: var(--text-primary);
}

.status-approved,
.badge-success {
  --_tone: var(--status-success);
}

.status-pending,
.badge-review {
  --_tone: var(--status-review);
}

.status-changes,
.badge-warning {
  --_tone: var(--status-correction);
}

.status-danger,
.badge-danger {
  --_tone: var(--danger);
}

.status-approved,
.badge-success,
.status-pending,
.badge-review,
.status-changes,
.badge-warning,
.status-danger,
.badge-danger {
  background-color: color-mix(in srgb, var(--_tone) 12%, transparent);
  color: var(--_tone);
  border-color: color-mix(in srgb, var(--_tone) 34%, transparent);
}

/* Buttons & Interactive Controls (44px min touch target) */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-target);
  padding: 10px 18px;
  border-radius: var(--radius-control);
  border: 1px solid var(--border-subtle);
  background-color: var(--surface);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.button:hover {
  background-color: var(--surface-subtle);
  border-color: var(--border-strong);
}

.button-dark,
.button-primary {
  background-color: var(--action-primary);
  border-color: var(--action-primary);
  color: var(--text-inverse);
}

.button-emerald {
  background-color: var(--accent-primary);
  border-color: var(--accent-primary);
  color: var(--text-inverse);
}

.button-dark:hover,
.button-primary:hover,
.button-emerald:hover {
  background-color: var(--fiamma-fucsia);
  border-color: var(--fiamma-fucsia);
  color: #FFFFFF;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.button-danger {
  background-color: var(--danger);
  border-color: var(--danger);
  color: light-dark(#FFFFFF, #1C1C1C);
}

.button-danger:hover {
  background-color: color-mix(in srgb, var(--danger) 84%, var(--text-primary));
  border-color: color-mix(in srgb, var(--danger) 84%, var(--text-primary));
  color: light-dark(#FFFFFF, #1C1C1C);
}

.button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap-target);
  min-width: var(--tap-target);
  height: var(--tap-target);
  padding: 0;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
  background-color: var(--surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.theme-toggle:hover {
  background-color: var(--surface-subtle);
  border-color: var(--border-strong);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

.theme-toggle .theme-icon-sun {
  display: none;
}

.theme-toggle .theme-icon-moon {
  display: block;
}

html[data-theme="dark"] .theme-toggle .theme-icon-sun {
  display: block;
}

html[data-theme="dark"] .theme-toggle .theme-icon-moon {
  display: none;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .theme-toggle .theme-icon-sun {
    display: block;
  }

  html:not([data-theme="light"]) .theme-toggle .theme-icon-moon {
    display: none;
  }
}

.text-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 36px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  transition: color 0.15s ease;
}

.text-link:hover {
  color: var(--accent-primary);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.link-button {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-target);
  padding: 6px 10px;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.link-button:hover {
  color: var(--text-primary);
  background-color: var(--surface-subtle);
}

/* Shared Account & Portal Pill Menu */
.nav-portal-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 38px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background-color: var(--surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.nav-portal-pill::-webkit-details-marker {
  display: none;
}

.nav-portal-pill:hover,
.account-menu[open] > .nav-portal-pill {
  background-color: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent-primary);
}

.nav-portal-label {
  max-width: 18ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-menu {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.account-menu-chevron {
  flex-shrink: 0;
  color: var(--text-secondary);
  transition: transform 0.15s ease, color 0.15s ease;
}

.account-menu[open] .account-menu-chevron {
  transform: rotate(180deg);
  color: var(--accent-primary);
}

.account-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 60;
  min-width: 184px;
  padding: 6px;
  border-radius: var(--radius-md);
  background-color: var(--surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.account-menu:not([open]) .account-dropdown {
  display: none;
}

.account-dropdown-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 38px;
  padding: 8px 12px;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.account-dropdown-item:hover,
.account-dropdown-item:focus-visible {
  background-color: var(--surface-subtle);
  color: var(--text-primary);
}

.account-dropdown-danger {
  color: var(--danger);
}

.account-dropdown-danger:hover,
.account-dropdown-danger:focus-visible {
  background-color: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}

.portal-logout-form {
  margin: 0;
}

/* Surfaces, Alerts & Empty States */
.surface-card {
  background-color: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}

.notices {
  background-color: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-left: 4px solid var(--accent-primary);
  color: var(--text-primary);
  padding: var(--space-3) var(--space-4);
  margin: var(--space-4) 0;
  border-radius: var(--radius-control);
  font-size: 13px;
}

.notices p + p {
  margin-top: var(--space-2);
}

.notices a {
  font-weight: 600;
  color: var(--accent-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.form-notice,
:not(.form-notice):not(.field-errors) > .errorlist {
  list-style: none;
  margin: 0 0 var(--space-4);
  padding: var(--space-3) var(--space-4);
  background-color: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 34%, transparent);
  border-left: 4px solid var(--danger);
  border-radius: var(--radius-control);
  font-size: 13px;
  font-weight: 500;
}

.form-notice ul,
.field-errors ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.form-notice li + li,
.field-errors li + li,
.errorlist li + li {
  margin-top: 4px;
}

.field-errors {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--danger);
}

.empty-state {
  padding: var(--space-6);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-card);
  background-color: var(--surface);
  color: var(--text-secondary);
  font-size: 13px;
}

/* Shared Form Elements */
.form-field {
  margin-bottom: var(--space-4);
}

.form-field label,
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.form-field input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.form-field textarea,
.form-field select,
.input-control {
  display: block;
  width: 100%;
  min-height: var(--tap-target);
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-control);
  background-color: var(--surface);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus,
.input-control:focus {
  border-color: var(--action-primary);
}

.form-field textarea {
  resize: vertical;
  min-height: 110px;
}

.field-help,
.helptext {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.muted {
  color: var(--text-secondary);
  font-size: 12px;
}

.overdue {
  color: var(--danger);
  font-weight: 600;
}

@media (max-width: 767px) {
  .form-field input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  .form-field textarea,
  .form-field select,
  .input-control {
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0s !important;
  }
}
