/**
 * Marine Hub Mini App — Stage 1 Premium Design System (#377)
 * Tokens + reusable primitives. Loads after styles.css.
 * Screen-specific redesigns are Stages 2–3.
 *
 * Typography (system sans, no remote fonts):
 * | Token            | Size   | LH    | Weight | Tracking |
 * | display          | 1.75rem| 1.15  | 800    | -0.02em  |
 * | screen-title     | 1.35rem| 1.2   | 750    | -0.015em |
 * | section-title    | 1.05rem| 1.25  | 700    | -0.01em  |
 * | card-title       | 0.98rem| 1.3   | 700    | 0        |
 * | body             | 0.94rem| 1.45  | 400    | 0        |
 * | body-strong      | 0.94rem| 1.45  | 650    | 0        |
 * | metadata         | 0.8rem | 1.35  | 500    | 0        |
 * | label            | 0.78rem| 1.3   | 650    | 0.01em   |
 * | caption          | 0.72rem| 1.3   | 500    | 0        |
 * | button           | 0.92rem| 1.2   | 700    | 0        |
 *
 * Spacing: 4 / 8 / 12 / 16 / 20 / 24 / 32
 * Radius: sm 8 / md 12 / lg 16 / pill 999
 */

:root,
html[data-theme="light"] {
  /* Spacing scale */
  --mh-space-1: 4px;
  --mh-space-2: 8px;
  --mh-space-3: 12px;
  --mh-space-4: 16px;
  --mh-space-5: 20px;
  --mh-space-6: 24px;
  --mh-space-7: 32px;
  --mh-page-gutter: var(--mh-space-4);
  --mh-section-gap: var(--mh-space-5);
  --mh-component-gap: var(--mh-space-3);
  --mh-card-pad: var(--mh-space-4);
  --mh-row-pad-y: 12px;
  --mh-row-pad-x: 14px;

  /* Radius scale */
  --mh-radius-sm: 8px;
  --mh-radius-md: 12px;
  --mh-radius-lg: 16px;
  --mh-radius-pill: 999px;
  --radius-sm: var(--mh-radius-sm);
  --radius-md: var(--mh-radius-md);
  --radius-lg: var(--mh-radius-lg);

  /* Typography */
  --mh-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --mh-type-display: 1.75rem;
  --mh-type-screen: 1.35rem;
  --mh-type-section: 1.05rem;
  --mh-type-card: 0.98rem;
  --mh-type-body: 0.94rem;
  --mh-type-meta: 0.8rem;
  --mh-type-label: 0.78rem;
  --mh-type-caption: 0.72rem;
  --mh-type-button: 0.92rem;
  --mh-lh-tight: 1.15;
  --mh-lh-snug: 1.25;
  --mh-lh-body: 1.45;

  /* Surface hierarchy (cool-neutral light) */
  --mh-surface-page: var(--mh-bg);
  --mh-surface-standard: var(--mh-surface);
  --mh-surface-raised: var(--mh-surface-elevated);
  --mh-surface-inset: var(--mh-surface-muted);
  --mh-surface-interactive: var(--mh-input-bg);
  --mh-surface-sticky: color-mix(in srgb, var(--mh-surface) 92%, transparent);
  --mh-surface-nav: var(--mh-nav-bg);
  --mh-surface-diag: color-mix(in srgb, var(--mh-surface-muted) 80%, transparent);

  /* Border / divider */
  --mh-border-subtle: color-mix(in srgb, var(--mh-border) 55%, transparent);
  --mh-border-standard: var(--mh-border);
  --mh-border-strong: color-mix(in srgb, var(--mh-text) 18%, var(--mh-border));
  --mh-line-divider: var(--mh-divider);

  /* Elevation */
  --mh-elev-flat: none;
  --mh-elev-low: 0 1px 3px rgba(15, 23, 42, 0.06);
  --mh-elev-med: 0 4px 14px rgba(15, 23, 42, 0.08);
  --mh-elev-sticky: 0 -6px 20px rgba(15, 23, 42, 0.08);

  /* Control sizing */
  --mh-control-h: 48px;
  --mh-control-h-sm: 40px;
  --mh-tap-min: var(--tap-min, 44px);

  --screen-pad-x: var(--mh-page-gutter);
}

html[data-theme="dark"] {
  --mh-surface-page: var(--mh-bg);
  --mh-surface-standard: var(--mh-surface);
  --mh-surface-raised: var(--mh-surface-elevated);
  --mh-surface-inset: var(--mh-surface-muted);
  --mh-surface-interactive: var(--mh-input-bg);
  --mh-surface-sticky: color-mix(in srgb, var(--mh-surface-elevated) 94%, transparent);
  --mh-surface-nav: var(--mh-nav-bg);
  --mh-surface-diag: color-mix(in srgb, var(--mh-surface-muted) 88%, transparent);
  --mh-border-subtle: color-mix(in srgb, var(--mh-border) 70%, transparent);
  --mh-border-standard: var(--mh-border);
  --mh-border-strong: color-mix(in srgb, #fff 14%, var(--mh-border));
  --mh-line-divider: var(--mh-divider);
  --mh-elev-low: 0 1px 4px rgba(0, 0, 0, 0.28);
  --mh-elev-med: 0 6px 18px rgba(0, 0, 0, 0.32);
  --mh-elev-sticky: 0 -8px 22px rgba(0, 0, 0, 0.35);
}

/* —— Typography utilities —— */
.mh-type-display {
  font-family: var(--mh-font);
  font-size: var(--mh-type-display);
  line-height: var(--mh-lh-tight);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--mh-text);
}

.mh-type-screen {
  font-family: var(--mh-font);
  font-size: var(--mh-type-screen);
  line-height: 1.2;
  font-weight: 750;
  letter-spacing: -0.015em;
  color: var(--mh-text);
}

.mh-type-section {
  font-family: var(--mh-font);
  font-size: var(--mh-type-section);
  line-height: var(--mh-lh-snug);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--mh-text);
}

.mh-type-card {
  font-family: var(--mh-font);
  font-size: var(--mh-type-card);
  line-height: 1.3;
  font-weight: 700;
  color: var(--mh-text);
}

.mh-type-body {
  font-size: var(--mh-type-body);
  line-height: var(--mh-lh-body);
  font-weight: 400;
  color: var(--mh-text);
}

.mh-type-body-strong {
  font-size: var(--mh-type-body);
  line-height: var(--mh-lh-body);
  font-weight: 650;
  color: var(--mh-text);
}

.mh-type-meta {
  font-size: var(--mh-type-meta);
  line-height: 1.35;
  font-weight: 500;
  color: var(--mh-text-secondary);
}

.mh-type-label {
  font-size: var(--mh-type-label);
  line-height: 1.3;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--mh-text-secondary);
}

.mh-type-caption {
  font-size: var(--mh-type-caption);
  line-height: 1.3;
  font-weight: 500;
  color: var(--mh-text-muted);
}

/* —— Surfaces —— */
.mh-surface {
  background: var(--mh-surface-standard);
  border: 1px solid var(--mh-border-subtle);
  border-radius: var(--mh-radius-lg);
  box-shadow: var(--mh-elev-low);
}

.mh-surface--elevated {
  background: var(--mh-surface-raised);
  border: 1px solid var(--mh-border-standard);
  border-radius: var(--mh-radius-lg);
  box-shadow: var(--mh-elev-med);
}

.mh-surface--inset {
  background: var(--mh-surface-inset);
  border: 1px solid transparent;
  border-radius: var(--mh-radius-md);
  box-shadow: var(--mh-elev-flat);
}

.mh-surface--flat {
  background: transparent;
  border: none;
  box-shadow: none;
}

.mh-card {
  padding: var(--mh-card-pad);
  background: var(--mh-surface-standard);
  border: 1px solid var(--mh-border-subtle);
  border-radius: var(--mh-radius-lg);
  box-shadow: var(--mh-elev-low);
}

.mh-card--elevated {
  box-shadow: var(--mh-elev-med);
  border-color: var(--mh-border-standard);
}

.mh-info-group {
  display: grid;
  gap: var(--mh-space-2);
  padding: var(--mh-space-3) 0;
}

.mh-list-row {
  display: flex;
  align-items: center;
  gap: var(--mh-space-3);
  min-height: var(--mh-tap-min);
  padding: var(--mh-row-pad-y) var(--mh-row-pad-x);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--mh-line-divider);
}

.mh-list-row:last-child {
  border-bottom: none;
}

.mh-divider {
  height: 1px;
  margin: var(--mh-space-3) 0;
  background: var(--mh-line-divider);
  border: none;
}

/* —— Page / section headers —— */
.mh-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--mh-space-3);
  margin: 0 0 var(--mh-space-4);
}

.mh-page-header__titles {
  min-width: 0;
  flex: 1;
}

.mh-page-header__title {
  margin: 0;
  font-size: var(--mh-type-screen);
  line-height: 1.2;
  font-weight: 750;
  letter-spacing: -0.015em;
  color: var(--mh-text);
}

.mh-page-header__subtitle {
  margin: 4px 0 0;
  font-size: var(--mh-type-meta);
  line-height: 1.35;
  font-weight: 500;
  color: var(--mh-text-muted);
}

.mh-section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--mh-space-3);
  margin: 0 0 var(--mh-space-3);
}

.mh-section-header__title {
  margin: 0;
  font-size: var(--mh-type-section);
  font-weight: 700;
  color: var(--mh-text);
}

.mh-section-header__helper,
.mh-section-header__count {
  font-size: var(--mh-type-caption);
  font-weight: 600;
  color: var(--mh-text-muted);
}

/* —— Buttons —— */
.mh-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--mh-control-h);
  min-width: var(--mh-tap-min);
  padding: 0 18px;
  border-radius: var(--mh-radius-md);
  border: 1.5px solid transparent;
  font-family: var(--mh-font);
  font-size: var(--mh-type-button);
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease, opacity 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}

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

.mh-button--primary {
  background: var(--mh-accent);
  color: var(--mh-accent-text);
  border-color: var(--mh-accent);
  box-shadow: 0 6px 16px color-mix(in srgb, var(--mh-accent) 28%, transparent);
}

.mh-button--primary:active {
  filter: brightness(0.96);
}

.mh-button--secondary {
  background: var(--mh-surface-inset);
  color: var(--mh-text);
  border-color: var(--mh-border-subtle);
}

.mh-button--outline {
  background: var(--mh-surface-standard);
  color: var(--mh-accent);
  border-color: var(--mh-accent);
}

.mh-button--text {
  background: transparent;
  color: var(--mh-accent);
  border-color: transparent;
  min-height: var(--mh-control-h-sm);
  padding: 0 10px;
  box-shadow: none;
}

.mh-button--danger {
  background: var(--mh-danger);
  color: #fff;
  border-color: var(--mh-danger);
}

.mh-button--disabled,
.mh-button:disabled,
.mh-button[aria-disabled="true"] {
  background: var(--mh-surface-inset);
  color: var(--mh-disabled);
  border-color: var(--mh-border-subtle);
  box-shadow: none;
  cursor: default;
  opacity: 1;
  pointer-events: none;
}

.mh-button--icon {
  width: var(--mh-control-h);
  padding: 0;
}

.mh-button--sm {
  min-height: var(--mh-control-h-sm);
  padding: 0 14px;
  font-size: 0.86rem;
}

.mh-button-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--mh-space-2);
}

.mh-button-row--split {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: var(--mh-space-3);
}

/* —— Inputs —— */
.mh-field {
  display: grid;
  gap: 6px;
}

.mh-field__label {
  font-size: var(--mh-type-label);
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--mh-text-secondary);
}

.mh-input,
.mh-select,
.mh-textarea {
  width: 100%;
  min-height: var(--mh-control-h);
  padding: 0 14px;
  border-radius: var(--mh-radius-md);
  border: 1px solid var(--mh-border-standard);
  background: var(--mh-surface-interactive);
  color: var(--mh-input-text);
  font-family: var(--mh-font);
  font-size: var(--mh-type-body);
  line-height: 1.3;
  box-shadow: var(--mh-elev-flat);
}

.mh-textarea {
  min-height: 96px;
  padding: 12px 14px;
  resize: vertical;
}

.mh-input::placeholder,
.mh-textarea::placeholder {
  color: var(--mh-placeholder);
}

.mh-input:focus,
.mh-select:focus,
.mh-textarea:focus {
  outline: none;
  border-color: var(--mh-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--mh-focus) 22%, transparent);
}

.mh-input:disabled,
.mh-select:disabled,
.mh-textarea:disabled,
.mh-input.is-disabled,
.mh-select.is-disabled {
  color: var(--mh-disabled);
  background: var(--mh-surface-inset);
  border-color: var(--mh-border-subtle);
  cursor: default;
}

.mh-input.is-error,
.mh-select.is-error,
.mh-textarea.is-error {
  border-color: var(--mh-danger);
}

.mh-field__error {
  font-size: var(--mh-type-caption);
  color: var(--mh-danger);
}

.mh-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.mh-input-wrap .mh-input {
  padding-left: 40px;
}

.mh-input-wrap__icon {
  position: absolute;
  left: 12px;
  color: var(--mh-text-muted);
  display: inline-flex;
  pointer-events: none;
}

/* —— Chips / status —— */
.mh-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 12px;
  border-radius: var(--mh-radius-pill);
  border: 1px solid var(--mh-border-subtle);
  background: var(--mh-surface-standard);
  color: var(--mh-text-secondary);
  font-size: var(--mh-type-caption);
  font-weight: 650;
}

.mh-chip--filter {
  cursor: pointer;
}

.mh-chip--active {
  background: color-mix(in srgb, var(--mh-accent) 12%, var(--mh-surface));
  border-color: color-mix(in srgb, var(--mh-accent) 35%, var(--mh-border));
  color: var(--mh-accent);
}

.mh-chip--category {
  background: var(--mh-surface-inset);
  border-color: transparent;
}

.mh-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 10px;
  border-radius: var(--mh-radius-pill);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: var(--mh-surface-inset);
  color: var(--mh-text-secondary);
}

.mh-badge--urgent,
.mh-status--urgent {
  background: color-mix(in srgb, var(--mh-warning) 16%, var(--mh-surface));
  color: var(--mh-warning);
}

.mh-badge--direct,
.mh-badge--applied,
.mh-badge--interview,
.mh-badge--offer,
.mh-status--direct,
.mh-status--applied,
.mh-status--interview,
.mh-status--offer {
  background: color-mix(in srgb, var(--mh-success) 14%, var(--mh-surface));
  color: var(--mh-success);
}

.mh-badge--rejected,
.mh-badge--closed,
.mh-status--rejected,
.mh-status--closed {
  background: color-mix(in srgb, var(--mh-danger) 12%, var(--mh-surface));
  color: var(--mh-danger);
}

.mh-badge--sync,
.mh-status--sync {
  background: color-mix(in srgb, var(--mh-accent) 12%, var(--mh-surface));
  color: var(--mh-accent);
}

/* —— Sticky action bar —— */
.mh-sticky-bar {
  position: sticky;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: var(--mh-space-3);
  padding: 10px var(--mh-page-gutter) calc(10px + var(--safe-bottom));
  background: var(--mh-surface-sticky);
  border-top: 1px solid var(--mh-border-subtle);
  box-shadow: var(--mh-elev-sticky);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

body:not([data-active-view="job-detail"]):not([data-active-view="recruiter-detail"]) .mh-sticky-bar {
  bottom: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: 10px;
}

/* —— Empty / loading / error —— */
.mh-empty,
.mh-error,
.mh-loading {
  display: grid;
  gap: var(--mh-space-2);
  padding: var(--mh-space-6) var(--mh-space-4);
  text-align: center;
  border-radius: var(--mh-radius-lg);
  background: var(--mh-surface-inset);
}

.mh-empty__title,
.mh-error__title {
  margin: 0;
  font-size: var(--mh-type-section);
  font-weight: 700;
  color: var(--mh-text);
}

.mh-empty__text,
.mh-error__text {
  margin: 0;
  font-size: var(--mh-type-meta);
  color: var(--mh-text-muted);
}

.mh-skeleton {
  display: block;
  height: 14px;
  border-radius: var(--mh-radius-sm);
  background: linear-gradient(
    90deg,
    var(--mh-surface-inset) 0%,
    color-mix(in srgb, var(--mh-surface) 70%, var(--mh-surface-inset)) 50%,
    var(--mh-surface-inset) 100%
  );
  background-size: 200% 100%;
  animation: mh-skel 1.2s ease-in-out infinite;
}

.mh-skeleton--title {
  height: 22px;
  width: 62%;
}

.mh-skeleton--row {
  height: 56px;
  margin-top: 10px;
}

@keyframes mh-skel {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

/* —— Component board (Visual Review / Stage 1 proof) —— */
.mh-ds-board {
  display: grid;
  gap: var(--mh-section-gap);
  padding: var(--mh-space-4);
  margin-bottom: var(--mh-space-6);
  background: var(--mh-surface-page);
}

.mh-ds-board[hidden] {
  display: none !important;
}

.mh-ds-board__block {
  display: grid;
  gap: var(--mh-space-3);
}

.mh-ds-board__label {
  margin: 0;
  font-size: var(--mh-type-caption);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--mh-text-muted);
}

.mh-ds-swatches {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.mh-ds-swatch {
  min-height: 56px;
  border-radius: var(--mh-radius-md);
  border: 1px solid var(--mh-border-subtle);
  display: flex;
  align-items: flex-end;
  padding: 6px 8px;
  font-size: 0.65rem;
  font-weight: 650;
  color: var(--mh-text);
}

.mh-ds-swatch--page {
  background: var(--mh-surface-page);
}
.mh-ds-swatch--standard {
  background: var(--mh-surface-standard);
}
.mh-ds-swatch--raised {
  background: var(--mh-surface-raised);
}
.mh-ds-swatch--inset {
  background: var(--mh-surface-inset);
}
