/* ==========================================================================
   IMA Staff Portal — design system
   Brand: IMA blue #074ea2 (primary actions), IMA red #ed1c24 (brand accent,
   destructive actions). Light-first, with a dark theme.
   ========================================================================== */

:root,
[data-theme="light"] {
  color-scheme: light;

  /* Brand */
  --brand: #074ea2;
  --brand-hover: #063f84;
  --brand-active: #05346d;
  --brand-text: #074ea2;
  --brand-soft: #eaf1fb;
  --brand-soft-border: #c9daf2;
  --brand-ring: rgba(7, 78, 162, 0.28);
  --accent: #ed1c24;

  /* Surfaces */
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-hover: #f3f6fb;
  --border: #e2e7ef;
  --border-strong: #cdd5e1;

  /* Text */
  --text: #0c1a30;
  --text-2: #42526a;
  --text-3: #5f6f86;
  --on-brand: #ffffff;

  /* Status */
  --danger: #c81e25;
  --danger-hover: #a9181e;
  --danger-text: #b0191f;
  --danger-soft: #fdeeee;
  --danger-border: #f5c4c6;
  --success-text: #146c36;
  --success-soft: #eaf6ef;
  --success-border: #bfe3cd;
  --info-text: #074ea2;
  --info-soft: #eaf1fb;
  --info-border: #c9daf2;
  --warning-text: #8a5300;
  --warning-soft: #fff5e3;
  --warning-border: #f3d9a6;

  /* Elevation */
  --shadow-xs: 0 1px 2px rgba(12, 26, 48, 0.05);
  --shadow-sm: 0 1px 2px rgba(12, 26, 48, 0.04), 0 1px 3px rgba(12, 26, 48, 0.07);
  --shadow-lg: 0 24px 48px -16px rgba(12, 26, 48, 0.18), 0 2px 6px rgba(12, 26, 48, 0.05);

  --topbar-bg: rgba(255, 255, 255, 0.92);
}

[data-theme="dark"] {
  color-scheme: dark;

  --brand: #2b6cc4;
  --brand-hover: #3a7bd3;
  --brand-active: #2460b0;
  --brand-text: #86b4ef;
  --brand-soft: rgba(76, 142, 224, 0.14);
  --brand-soft-border: rgba(76, 142, 224, 0.32);
  --brand-ring: rgba(110, 165, 235, 0.4);
  --accent: #f0434a;

  --bg: #0a1120;
  --surface: #111a2c;
  --surface-2: #0e1626;
  --surface-hover: #16213a;
  --border: #223050;
  --border-strong: #2f3f63;

  --text: #e9eef6;
  --text-2: #b0bccf;
  --text-3: #8d9bb2;
  --on-brand: #ffffff;

  --danger: #cf2a31;
  --danger-hover: #dc3a41;
  --danger-text: #ff9a9e;
  --danger-soft: rgba(240, 67, 74, 0.12);
  --danger-border: rgba(240, 67, 74, 0.35);
  --success-text: #7fd8a1;
  --success-soft: rgba(52, 168, 98, 0.12);
  --success-border: rgba(52, 168, 98, 0.35);
  --info-text: #9cc3f3;
  --info-soft: rgba(76, 142, 224, 0.12);
  --info-border: rgba(76, 142, 224, 0.35);
  --warning-text: #f3c574;
  --warning-soft: rgba(230, 160, 40, 0.12);
  --warning-border: rgba(230, 160, 40, 0.35);

  --shadow-xs: none;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 24px 48px -16px rgba(0, 0, 0, 0.6);

  --topbar-bg: rgba(17, 26, 44, 0.92);
}

:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --ease: cubic-bezier(0.2, 0, 0, 1);
}

/* ---------- Base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}

a {
  color: var(--brand-text);
  text-decoration: none;
  font-weight: 500;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

strong {
  font-weight: 600;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.icon {
  width: 1.125rem;
  height: 1.125rem;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.muted {
  color: var(--text-3);
}

.mono {
  font-family: var(--mono);
  font-size: 0.85em;
}

/* ---------- Brand stripe (echoes the logo's blue + red) ---------- */

.brand-stripe {
  height: 3px;
  background: linear-gradient(90deg, var(--brand) 0 72%, var(--accent) 72% 100%);
}

/* ---------- Buttons ---------- */

.btn {
  --btn-h: 2.625rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: var(--btn-h);
  padding: 0 1.125rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease),
    color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.btn:hover {
  text-decoration: none;
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--brand-ring);
}

.btn .icon {
  width: 1rem;
  height: 1rem;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  --btn-h: 2.125rem;
  padding: 0 0.8rem;
  font-size: 0.84rem;
  border-radius: var(--radius-sm);
}

.btn-lg {
  --btn-h: 2.875rem;
  font-size: 0.95rem;
}

.btn-primary {
  background: var(--brand);
  color: var(--on-brand);
  box-shadow: var(--shadow-xs);
}

.btn-primary:hover {
  background: var(--brand-hover);
}

.btn-primary:active {
  background: var(--brand-active);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}

.btn-secondary:hover {
  background: var(--surface-hover);
  border-color: var(--text-3);
}

.btn-ghost {
  background: transparent;
  color: var(--text-2);
}

.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger-text);
}

.btn-danger-ghost:hover {
  background: var(--danger-soft);
}

.btn-danger-ghost:focus-visible {
  box-shadow: 0 0 0 3px rgba(200, 30, 37, 0.25);
}

.btn-icon {
  width: var(--btn-h);
  padding: 0;
}

/* ---------- Forms ---------- */

.form-group {
  margin-bottom: 1.125rem;
}

.form-label,
.form-group > label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.4rem;
}

.label-row label {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
}

.label-row a {
  font-size: 0.82rem;
}

.optional {
  font-weight: 400;
  color: var(--text-3);
}

.form-control {
  display: block;
  width: 100%;
  height: 2.75rem;
  padding: 0 0.875rem;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

textarea.form-control {
  height: auto;
  min-height: 8rem;
  padding: 0.75rem 0.875rem;
  resize: vertical;
  line-height: 1.6;
}

.form-control::placeholder {
  color: var(--text-3);
  opacity: 0.8;
}

.form-control:hover {
  border-color: var(--text-3);
}

.form-control:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}

.form-hint {
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-3);
}

.input-icon {
  position: relative;
}

.input-icon > .icon {
  position: absolute;
  left: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}

.input-icon > .form-control {
  padding-left: 2.5rem;
}

.password-wrapper {
  position: relative;
}

.password-wrapper .form-control {
  padding-right: 3rem;
}

.password-toggle-btn {
  position: absolute;
  right: 0.3rem;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-3);
  cursor: pointer;
  transition: color 0.15s var(--ease), background-color 0.15s var(--ease);
}

.password-toggle-btn:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.password-toggle-btn svg {
  width: 1.125rem;
  height: 1.125rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Checkbox as a selectable option card */
.check-card {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease);
}

.check-card:hover {
  border-color: var(--border-strong);
}

.check-card:has(input:checked) {
  background: var(--brand-soft);
  border-color: var(--brand-soft-border);
}

.check-card:has(input:disabled) {
  cursor: not-allowed;
}

.check-card input[type="checkbox"] {
  width: 1.125rem;
  height: 1.125rem;
  margin-top: 0.1rem;
  accent-color: var(--brand);
  cursor: inherit;
}

.check-card-title {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.check-card-desc {
  display: block;
  font-size: 0.8rem;
  color: var(--text-3);
}

/* ---------- Alerts ---------- */

.alert {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  padding: 0.8rem 0.95rem;
  margin-bottom: 1.25rem;
  font-size: 0.875rem;
  line-height: 1.5;
  border: 1px solid transparent;
  border-radius: var(--radius);
}

.alert .icon {
  width: 1.1rem;
  height: 1.1rem;
  margin-top: 0.08rem;
}

.alert-danger {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger-text);
}

.alert-success {
  background: var(--success-soft);
  border-color: var(--success-border);
  color: var(--success-text);
}

.alert-info {
  background: var(--info-soft);
  border-color: var(--info-border);
  color: var(--info-text);
}

/* ---------- Badges & avatars ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: 1.5rem;
  padding: 0 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: currentColor;
}

.badge-admin {
  background: var(--brand-soft);
  border-color: var(--brand-soft-border);
  color: var(--brand-text);
}

.badge-user {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-2);
}

.badge-you {
  height: 1.25rem;
  padding: 0 0.45rem;
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: var(--accent);
  color: #ffffff;
}

.badge-you::before {
  display: none;
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--brand-text);
  background: var(--brand-soft);
  border: 1px solid var(--brand-soft-border);
  border-radius: 50%;
}

.avatar-sm {
  width: 1.875rem;
  height: 1.875rem;
  font-size: 0.72rem;
}

.avatar-lg {
  width: 4rem;
  height: 4rem;
  font-size: 1.3rem;
}

/* ==========================================================================
   Auth layout (login, signup, password reset)
   ========================================================================== */

.auth-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 1fr;
}

.auth-aside {
  display: none;
}

.auth-main {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4.5rem 1rem 2rem;
}

.auth-main-top {
  position: absolute;
  top: 1rem;
  right: 1rem;
}

.auth-panel {
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  display: block;
  height: 64px;
  width: auto;
  margin-bottom: 2rem;
}

.auth-title {
  font-size: 1.625rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--text);
}

.auth-subtitle {
  margin-top: 0.4rem;
  margin-bottom: 1.75rem;
  font-size: 0.925rem;
  color: var(--text-2);
}

.auth-card {
  padding: 1.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.auth-card .btn-primary {
  margin-top: 0.5rem;
}

.auth-footer {
  margin-top: 1.5rem;
  font-size: 0.875rem;
  text-align: center;
  color: var(--text-2);
}

.auth-legal {
  margin-top: 2.5rem;
  font-size: 0.78rem;
  text-align: center;
  color: var(--text-3);
}

@media (min-width: 960px) {
  .auth-shell {
    grid-template-columns: minmax(420px, 5fr) 7fr;
  }

  .auth-aside {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 2.5rem 3rem;
    overflow: hidden;
    color: #ffffff;
    background: linear-gradient(160deg, #0a5bbb 0%, #074ea2 45%, #053a7a 100%);
  }

  .auth-aside::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 4px;
    background: var(--accent);
  }

  .auth-aside-brand {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.01em;
  }

  .auth-aside-brand .logo-tile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  }

  .auth-aside-brand .logo-tile img {
    width: 1.9rem;
    height: auto;
  }

  .auth-aside-copy {
    position: relative;
    z-index: 1;
    max-width: 26rem;
  }

  .auth-aside-copy .eyebrow {
    display: inline-block;
    margin-bottom: 1rem;
    padding: 0.3rem 0.7rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 999px;
  }

  .auth-aside-copy h2 {
    font-size: 2.25rem;
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.025em;
  }

  .auth-aside-copy p {
    margin-top: 1rem;
    font-size: 1rem;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.82);
  }

  .auth-aside-list {
    position: relative;
    z-index: 1;
    display: grid;
    gap: 0.85rem;
    list-style: none;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.88);
  }

  .auth-aside-list li {
    display: flex;
    align-items: center;
    gap: 0.65rem;
  }

  .auth-aside-list .icon {
    width: 1.05rem;
    height: 1.05rem;
    color: #ffffff;
    opacity: 0.9;
  }

  .auth-aside-pattern {
    position: absolute;
    right: -4.5rem;
    top: -1.5rem;
    width: min(22rem, 70%);
    opacity: 0.9;
    pointer-events: none;
  }

  .auth-main {
    padding: 3rem 2rem;
  }

  .auth-main .auth-logo {
    height: 56px;
  }
}

/* ==========================================================================
   App shell (authenticated pages)
   ========================================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--topbar-bg);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  max-width: 1200px;
  height: 4rem;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand:hover {
  text-decoration: none;
}

.brand img {
  width: 2rem;
  height: auto;
}

.brand-name {
  font-size: 1rem;
  white-space: nowrap;
}

.brand-name b {
  color: var(--brand-text);
  font-weight: 800;
}

.nav {
  display: flex;
  align-items: stretch;
  gap: 0.25rem;
  height: 100%;
}

.nav a {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0 0.75rem;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  color: var(--text-2);
}

.nav a:hover {
  color: var(--text);
  text-decoration: none;
}

.nav a[aria-current="page"] {
  color: var(--brand-text);
  font-weight: 600;
}

.nav a[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 0.75rem;
  right: 0.75rem;
  bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--brand);
}

.topbar-end {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0 0.25rem 0 0.75rem;
  margin-left: 0.25rem;
  border-left: 1px solid var(--border);
}

.user-chip-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  text-align: right;
}

.user-chip-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.user-chip-role {
  font-size: 0.72rem;
  color: var(--text-3);
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.page-narrow {
  max-width: 760px;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.page-title {
  font-size: 1.625rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.page-subtitle {
  margin-top: 0.3rem;
  font-size: 0.925rem;
  color: var(--text-2);
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
  font-size: 0.82rem;
  color: var(--text-3);
}

.breadcrumb a {
  color: var(--text-2);
}

.breadcrumb .icon {
  width: 0.875rem;
  height: 0.875rem;
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: 0.975rem;
  font-weight: 600;
  letter-spacing: -0.005em;
}

.card-desc {
  margin-top: 0.15rem;
  font-size: 0.84rem;
  color: var(--text-3);
}

.card-body {
  padding: 1.4rem;
}

.card-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  padding: 1rem 1.4rem;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.form-section + .form-section {
  margin-top: 0.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.form-row {
  display: grid;
  gap: 0 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .form-row {
    grid-template-columns: 1fr 1fr;
  }
}

/* ---------- Dashboard grid ---------- */

.grid {
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 900px) {
  .grid-dashboard {
    grid-template-columns: 340px 1fr;
    align-items: start;
  }
}

.profile {
  position: relative;
  overflow: hidden;
  text-align: center;
}

.profile-cover {
  height: 4.5rem;
  background: linear-gradient(120deg, #0a5bbb, #074ea2 60%, #053a7a);
  border-bottom: 3px solid var(--accent);
}

.profile .avatar-lg {
  margin-top: -2rem;
  background: var(--surface);
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border), var(--shadow-sm);
}

.profile-name {
  margin-top: 0.75rem;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.profile-email {
  margin-top: 0.15rem;
  font-size: 0.875rem;
  color: var(--text-2);
  word-break: break-all;
}

.profile .badge {
  margin-top: 0.85rem;
}

.details {
  display: grid;
}

.details-row {
  display: grid;
  grid-template-columns: 9rem 1fr;
  gap: 1rem;
  padding: 0.85rem 0;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
}

.details-row:first-child {
  padding-top: 0;
}

.details-row:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.details-row dt {
  color: var(--text-3);
}

.details-row dd {
  font-weight: 500;
  word-break: break-word;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--success-text);
}

.status-dot::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px var(--success-soft);
}

.tiles {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}

.tile {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  padding: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), transform 0.15s var(--ease);
}

.tile:hover {
  text-decoration: none;
  border-color: var(--brand-soft-border);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.tile-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  color: var(--brand-text);
  background: var(--brand-soft);
  border-radius: var(--radius);
}

.tile-title {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
}

.tile-desc {
  display: block;
  margin-top: 0.1rem;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-3);
}

/* ---------- Stats ---------- */

.stats {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, 1fr);
  margin-bottom: 1.5rem;
}

@media (min-width: 900px) {
  .stats {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat {
  padding: 1.1rem 1.25rem;
}

.stat-label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-3);
}

.stat-label .icon {
  width: 0.95rem;
  height: 0.95rem;
}

.stat-value {
  margin-top: 0.4rem;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-value.stat-value-sm {
  font-size: 1.1rem;
  line-height: 1.6rem;
}

.stat-accent {
  position: relative;
  overflow: hidden;
}

.stat-accent::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--brand);
}

/* ---------- Table ---------- */

.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
}

.table-toolbar .input-icon {
  flex: 1 1 260px;
  max-width: 340px;
}

.table-toolbar .form-control {
  height: 2.375rem;
  font-size: 0.875rem;
}

.table-count {
  font-size: 0.82rem;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  text-align: left;
}

.data-table th {
  padding: 0.7rem 1.1rem;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-3);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 0.8rem 1.1rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr {
  transition: background-color 0.12s var(--ease);
}

.data-table tbody tr:hover {
  background: var(--surface-hover);
}

.data-table .num {
  font-variant-numeric: tabular-nums;
  color: var(--text-3);
}

.data-table .col-actions {
  text-align: right;
  white-space: nowrap;
}

.cell-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 220px;
}

.cell-user-name {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 600;
  color: var(--text);
}

.cell-user-email {
  font-size: 0.82rem;
  color: var(--text-3);
}

.cell-date {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
}

.cell-date small {
  display: block;
  font-size: 0.78rem;
  color: var(--text-3);
}

.row-actions {
  display: inline-flex;
  gap: 0.25rem;
}

.row-actions form {
  display: inline;
}

.empty-state {
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--text-3);
}

.empty-state .icon {
  width: 2rem;
  height: 2rem;
  margin-bottom: 0.5rem;
  color: var(--border-strong);
}

.empty-state strong {
  display: block;
  color: var(--text);
}

/* ---------- Dropdown (details/summary) ---------- */

.dropdown {
  position: relative;
}

.dropdown > summary {
  list-style: none;
}

.dropdown > summary::-webkit-details-marker {
  display: none;
}

.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  z-index: 20;
  min-width: 13rem;
  padding: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.dropdown-menu a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.7rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  border-radius: var(--radius-sm);
}

.dropdown-menu a:hover {
  text-decoration: none;
  background: var(--surface-hover);
}

.dropdown-menu a .icon {
  color: var(--text-3);
}

.dropdown-menu small {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-3);
}

/* ---------- Batch import ---------- */

.template-callout {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  margin-bottom: 1.25rem;
  background: var(--brand-soft);
  border: 1px solid var(--brand-soft-border);
  border-radius: var(--radius);
}

.template-callout-title {
  font-size: 0.875rem;
  font-weight: 600;
}

.template-callout code {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-2);
}

.file-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 9.5rem;
  padding: 1.5rem 1.25rem;
  text-align: center;
  background: var(--surface-2);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease);
}

.file-dropzone:hover,
.file-dropzone.is-dragover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.file-dropzone:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}

.file-dropzone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.dropzone-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  margin-bottom: 0.35rem;
  color: var(--brand-text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
}

.dropzone-text {
  font-size: 0.9rem;
  color: var(--text-2);
}

.dropzone-text strong {
  color: var(--brand-text);
}

.dropzone-hint {
  font-size: 0.78rem;
  color: var(--text-3);
}

.dropzone-filename {
  display: none;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
  padding: 0.35rem 0.7rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--success-text);
  background: var(--success-soft);
  border: 1px solid var(--success-border);
  border-radius: 999px;
  word-break: break-all;
}

.dropzone-filename.is-visible {
  display: inline-flex;
}

.divider {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin: 1.25rem 0;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

textarea.code-input {
  font-family: var(--mono);
  font-size: 0.84rem;
}

.result-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.result-chip {
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.result-chip span {
  display: block;
  font-size: 0.78rem;
  color: var(--text-3);
}

.result-chip strong {
  font-size: 1.4rem;
  font-variant-numeric: tabular-nums;
}

.result-chip.ok {
  background: var(--success-soft);
  border-color: var(--success-border);
}

.result-chip.ok strong {
  color: var(--success-text);
}

.result-chip.skip {
  background: var(--warning-soft);
  border-color: var(--warning-border);
}

.result-chip.skip strong {
  color: var(--warning-text);
}

.error-list {
  max-height: 12rem;
  overflow-y: auto;
  padding: 0.75rem 1rem 0.75rem 2rem;
  margin-bottom: 1.25rem;
  font-size: 0.82rem;
  color: var(--danger-text);
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  border-radius: var(--radius);
}

.error-list li + li {
  margin-top: 0.2rem;
}

/* ---------- Error page ---------- */

.error-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 3px);
  padding: 2rem 1rem;
  text-align: center;
}

.error-card {
  width: 100%;
  max-width: 440px;
  padding: 2.25rem 2rem;
}

.error-code {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.25rem;
  height: 3.25rem;
  margin-bottom: 1rem;
  color: var(--danger-text);
  background: var(--danger-soft);
  border-radius: 50%;
}

.error-code .icon {
  width: 1.5rem;
  height: 1.5rem;
}

.error-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.error-message {
  margin: 0.5rem 0 1.5rem;
  color: var(--text-2);
}

/* ---------- Theme toggle ---------- */

.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.375rem;
  height: 2.375rem;
  color: var(--text-2);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease);
}

.theme-toggle-btn:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.theme-toggle-btn.is-floating {
  background: var(--surface);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.theme-toggle-btn svg {
  width: 1.1rem;
  height: 1.1rem;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .hide-md {
    display: none;
  }

  .user-chip-text {
    display: none;
  }
}

@media (max-width: 760px) {
  .topbar-inner {
    gap: 0.75rem;
    padding: 0 1rem;
  }

  .brand-name,
  .user-chip-text,
  .nav a span {
    display: none;
  }

  .nav a {
    padding: 0 0.6rem;
  }

  .nav a[aria-current="page"]::after {
    left: 0.4rem;
    right: 0.4rem;
  }

  .user-chip {
    padding-left: 0.5rem;
  }

  .page {
    padding: 1.5rem 1rem 3rem;
  }

  .page-actions {
    width: 100%;
  }

  .page-actions > * {
    flex: 1 1 auto;
  }

  .page-actions .btn,
  .page-actions .dropdown > summary {
    width: 100%;
  }

  .details-row {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  .card-footer {
    flex-direction: column-reverse;
  }

  .card-footer .btn {
    width: 100%;
  }

  .hide-sm {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}

/* ==========================================================================
   Roles, regions, account page
   ========================================================================== */

select.form-control {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2.25rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235f6f86' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1rem;
  cursor: pointer;
}

[data-theme="dark"] select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238d9bb2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

.form-control:disabled {
  color: var(--text-2);
  background-color: var(--surface-2);
  cursor: not-allowed;
}

.badge-regional {
  background: var(--surface);
  border-color: var(--brand-soft-border);
  color: var(--brand-text);
}

.badge-system {
  height: 1.25rem;
  padding: 0 0.45rem;
  font-size: 0.68rem;
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-3);
}

.badge-system::before {
  display: none;
}

/* Avatars with photos */
img.avatar-photo {
  display: inline-block;
  object-fit: cover;
  padding: 0;
  background: var(--surface-2);
}

.avatar-xl {
  width: 6rem;
  height: 6rem;
  font-size: 1.9rem;
}

/* Topbar user chip is a link to the account page */
a.user-chip {
  color: inherit;
  border-radius: var(--radius);
  padding-top: 0.3rem;
  padding-bottom: 0.3rem;
  transition: background-color 0.15s var(--ease);
}

a.user-chip:hover {
  text-decoration: none;
  background: var(--surface-hover);
}

a.user-chip[aria-current="page"] .avatar {
  box-shadow: 0 0 0 2px var(--brand);
}

.profile-actions {
  margin-top: 1rem;
}

/* Directory toolbar filters */
.toolbar-filters {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.toolbar-filters select.form-control {
  width: auto;
  min-width: 10.5rem;
  height: 2.375rem;
  font-size: 0.875rem;
}

.cell-place {
  font-size: 0.875rem;
  color: var(--text);
}

.cell-place small {
  display: block;
  font-size: 0.8rem;
  color: var(--text-3);
}

.locked-note {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0 0.5rem;
  font-size: 0.8rem;
  color: var(--text-3);
}

.locked-note .icon {
  width: 0.95rem;
  height: 0.95rem;
}

/* Roles table */
.cell-role {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 200px;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  height: 1.5rem;
  padding: 0 0.55rem;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}

/* Role form */
.option-stack {
  display: grid;
  gap: 0.6rem;
}

.check-card input[type="radio"] {
  width: 1.125rem;
  height: 1.125rem;
  margin-top: 0.1rem;
  accent-color: var(--brand);
  cursor: inherit;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.5rem;
}

.check-pill {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.8rem;
  font-size: 0.875rem;
  font-weight: 500;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease);
}

.check-pill:hover {
  border-color: var(--border-strong);
}

.check-pill:has(input:checked) {
  background: var(--brand-soft);
  border-color: var(--brand-soft-border);
  color: var(--brand-text);
}

.check-pill input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--brand);
}

/* CSV import reference */
.reference-list {
  display: grid;
  gap: 0.4rem;
  margin: -0.25rem 0 1.25rem;
  font-size: 0.82rem;
}

.reference-list div {
  display: grid;
  grid-template-columns: 11rem 1fr;
  gap: 0.75rem;
}

.reference-list dt {
  color: var(--text-3);
}

.reference-list dd {
  color: var(--text);
}

/* Account page */
.photo-editor {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.5rem;
}

.photo-preview .avatar {
  box-shadow: 0 0 0 1px var(--border), var(--shadow-sm);
}

.photo-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.75rem;
}

.photo-actions form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.visually-hidden-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.photo-actions label.btn:has(+ .visually-hidden-input:focus-visible) {
  box-shadow: 0 0 0 3px var(--brand-ring);
}

.photo-filename {
  font-size: 0.82rem;
  color: var(--text-2);
  word-break: break-all;
}

.static-value {
  padding: 0.6rem 0.875rem;
  font-size: 0.9375rem;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  word-break: break-all;
}

@media (max-width: 760px) {
  .toolbar-filters > * {
    flex: 1 1 100%;
  }

  .toolbar-filters select.form-control {
    width: 100%;
  }

  .table-toolbar .input-icon {
    max-width: none;
  }

  .reference-list div {
    grid-template-columns: 1fr;
    gap: 0.1rem;
  }
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: auto;
}

.btn-ghost:disabled:hover,
.btn-danger-ghost:disabled:hover {
  background: transparent;
}
