:root {
  --navy: #1d3557;
  --blue: #457b9d;
  --light: #f1faee;
  --accent: #2a9d8f;
  --red: #e63946;
  --amber: #e9a825;
  --gray-100: #f7f8fa;
  --gray-200: #e9ecef;
  --gray-400: #adb5bd;
  --gray-700: #495057;
  --gray-900: #212529;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--gray-100);
  color: var(--gray-900);
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--navy);
  color: white;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 32px;
  min-height: 60px;
}

.topbar .brand {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  color: white;
  text-decoration: none;
  flex-shrink: 0;
}
.topbar .brand:hover { text-decoration: none; color: white; }
.topbar .brand span { color: var(--accent); }

.topbar nav { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 10px; }

/* Direct children only (nav > a) -- deliberately not just "nav a", so this
   doesn't also catch the account-menu dropdown's links (Change Password,
   Two-Factor Authentication), which are nested inside nav via the
   <details class="account-menu"> element and already have their own
   distinct (plain-list-item) styling below. */
.topbar nav > a {
  color: #d8e2ef;
  padding: 7px 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.2;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.topbar nav > a:hover {
  color: white;
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.32);
  text-decoration: none;
}
.topbar nav > a:active { background: rgba(255, 255, 255, 0.28); }

.topbar .user-pill {
  background: rgba(255,255,255,0.12);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 0.85rem;
}

/* Account menu -- the "Name · role" pill in the top nav, now a dropdown
   holding Change Password / Log out (and a home for future account-level
   items) instead of both sitting inline in the nav bar. Built with a plain
   <details>/<summary> element rather than a JS component library, matching
   the rest of this app's no-build-step approach -- the small script in
   base.html just adds click-away-to-close for polish. */
.topbar .account-menu { position: relative; }
.topbar .account-menu summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.topbar .account-menu summary::-webkit-details-marker { display: none; }
.topbar .account-menu summary::after {
  content: "\25BE";
  margin-left: 6px;
  font-size: 0.7em;
  opacity: 0.8;
}
.topbar .account-menu[open] summary { background: rgba(255,255,255,0.22); }

.account-menu-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  padding: 6px;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 60;
}
.account-menu-dropdown a,
.account-menu-dropdown button.linklike {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border-radius: 6px;
  font-size: 0.9rem;
}
.topbar .account-menu-dropdown a { color: var(--gray-900); }
.topbar .account-menu-dropdown button.linklike { color: var(--gray-900); }
.account-menu-dropdown a:hover,
.account-menu-dropdown button.linklike:hover {
  background: var(--gray-100);
  text-decoration: none;
}

.topbar form { margin: 0; }
.topbar button.linklike {
  background: none; border: none; color: #d8e2ef; cursor: pointer; font: inherit; padding: 0;
}
.topbar button.linklike:hover { color: white; text-decoration: underline; }

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.2rem; }
.subtitle { color: var(--gray-700); margin: 0 0 24px; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.btn {
  display: inline-block;
  background: var(--blue);
  color: white;
  border: none;
  padding: 9px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 600;
}
.btn:hover { background: var(--navy); text-decoration: none; color: white; }
.btn-secondary { background: white; color: var(--gray-900); border: 1px solid var(--gray-400); }
.btn-secondary:hover { background: var(--gray-200); color: var(--gray-900); }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #b8202b; }
.btn-sm { padding: 5px 10px; font-size: 0.82rem; }

.card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-box {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  padding: 16px 18px;
}
.stat-box .num { font-size: 1.6rem; font-weight: 700; }
.stat-box .label { color: var(--gray-700); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-box.overdue .num { color: var(--red); }
.stat-box.approved .num { color: var(--accent); }

table { width: 100%; border-collapse: collapse; background: white; }
table.styled th, table.styled td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-200);
  font-size: 0.9rem;
}
table.styled th { background: var(--gray-100); color: var(--gray-700); font-weight: 600; }
table.styled tr:hover { background: #fafbfc; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 600;
}
.badge-approved { background: #d8f3ee; color: #146b5e; }
.badge-conditional { background: #fdf0d5; color: #93650f; }
.badge-pending { background: #e9ecef; color: var(--gray-700); }
.badge-disapproved { background: #fbdcdf; color: #99202b; }
.badge-overdue { background: #fbdcdf; color: #99202b; }

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}
.toolbar input[type=text], .toolbar select {
  padding: 8px 10px;
  border: 1px solid var(--gray-400);
  border-radius: 6px;
  font-size: 0.9rem;
}

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 0.9rem; }
.flash-success { background: #d8f3ee; color: #146b5e; }
.flash-error { background: #fbdcdf; color: #99202b; }

.impersonation-banner {
  background: #fff3cd;
  color: #7a5c00;
  padding: 10px 24px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  border-bottom: 1px solid #f0dca0;
}
.impersonation-banner form { margin: 0; }
.impersonation-banner button.linklike {
  background: none; border: none; padding: 0; font: inherit;
  color: #7a5c00; text-decoration: underline; cursor: pointer;
}

form.stacked label { display: block; font-weight: 600; font-size: 0.85rem; margin: 14px 0 5px; }
form.stacked input[type=text], form.stacked input[type=email], form.stacked input[type=date],
form.stacked input[type=password], form.stacked select, form.stacked textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--gray-400);
  border-radius: 6px;
  font-size: 0.92rem;
  font-family: inherit;
}
form.stacked textarea { min-height: 80px; resize: vertical; }
form.stacked .row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
form.stacked .actions { margin-top: 22px; display: flex; gap: 10px; }

.password-field-wrap { position: relative; }
.password-field-wrap input[type=password],
.password-field-wrap input[type=text] { padding-right: 40px !important; }
.password-toggle-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: var(--gray-700);
  padding: 0;
}
.password-toggle-btn:hover { background: var(--gray-200); color: var(--navy); }
.password-toggle-btn svg { width: 19px; height: 19px; }
.password-toggle-btn .icon-eye-off { display: none; }
.password-toggle-btn.is-visible .icon-eye { display: none; }
.password-toggle-btn.is-visible .icon-eye-off { display: block; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy), var(--blue));
}
.login-card {
  background: white;
  padding: 36px 38px;
  border-radius: 12px;
  width: 360px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.login-card h1 { color: var(--navy); }
.login-card .subtitle { font-size: 0.85rem; }
.demo-creds {
  margin-top: 18px;
  font-size: 0.78rem;
  color: var(--gray-700);
  background: var(--gray-100);
  padding: 10px 12px;
  border-radius: 6px;
  line-height: 1.5;
}

.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--gray-700);
}

.org-card-list { display: flex; flex-direction: column; gap: 10px; }
.org-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  padding: 16px 20px;
}
.org-row-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.org-row .org-name { font-weight: 700; font-size: 1.02rem; display: flex; align-items: center; gap: 8px; }

/* Per-module status chips on the platform admin's Clients Overview --
   condensed replacement for the old wall of raw counts: each chip just says
   whether that module is current or flagged, and by how much. */
.module-chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.module-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid transparent;
}
.module-chip.ok { background: #d8f3ee; color: #146b5e; border-color: #bfe9e0; }
.module-chip.attention { background: #fbdcdf; color: #99202b; border-color: #f3c0c5; }
/* A module the client has turned off from their own Settings -> Dashboard
   Modules -- deliberately neutral gray rather than the ok/attention
   green/red, since "not used" isn't a status judgment (it's not late,
   overdue, or a problem) and shouldn't read as either good or bad news. */
.module-chip.disabled { background: #eef0f2; color: var(--gray-700); border-color: #dfe3e6; }
.module-chip .chip-status-text { font-weight: 700; margin-left: 2px; }

.muted { color: var(--gray-700); font-size: 0.85rem; }

/* Explanatory copy that sits right below a form field, heading, or stat
   row (e.g. "Category" and its helper text on the Nonconformance form).
   These used to rely on one-off negative margin-top overrides to fight the
   browser's default <p> spacing, which left several of them crammed right
   up against the element above -- this gives every one of them the same
   comfortable, consistent gap instead. */
p.muted { margin: 10px 0 16px; }
.section-title { margin-top: 32px; margin-bottom: 12px; }
.back-link { display: inline-block; margin-bottom: 14px; font-size: 0.88rem; }

/* ---------------------------------------------------- console dashboard -- */
/* Client home dashboard: a console/hub feel (think game-console home
   screen) for a quick "is everything okay" glance, distinct from the
   document-style module pages it links out to. */

.console-hero {
  background: linear-gradient(135deg, var(--navy) 0%, var(--blue) 60%, var(--accent) 130%);
  border-radius: 16px;
  padding: 32px 34px;
  color: white;
  margin-bottom: 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 18px;
  box-shadow: 0 12px 32px rgba(29, 53, 87, 0.28);
}
.console-hero h1 { color: white; font-size: 1.7rem; margin: 0 0 6px; }
.console-hero .subtitle { color: rgba(255,255,255,0.82); margin: 0; }

.console-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.28);
  border-radius: 999px;
  padding: 10px 20px;
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
}
.console-status-pill .dot {
  width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0;
}

.status-dot {
  display: inline-block;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.ok {
  background: #3ddc84;
  box-shadow: 0 0 0 4px rgba(61, 220, 132, 0.22), 0 0 14px rgba(61, 220, 132, 0.65);
  animation: pulse-green 2.4s ease-in-out infinite;
}
.status-dot.attention {
  background: #ff4d5e;
  box-shadow: 0 0 0 4px rgba(255, 77, 94, 0.22), 0 0 14px rgba(255, 77, 94, 0.75);
  animation: pulse-red 1.4s ease-in-out infinite;
}
/* Plain, non-pulsing gray for a module the client has turned off -- see
   .module-chip.disabled above. No glow/animation on purpose: this isn't a
   live status that needs a glance, it's just "off". */
.status-dot.disabled {
  background: #adb5bd;
}
@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 0 4px rgba(61, 220, 132, 0.22), 0 0 14px rgba(61, 220, 132, 0.65); }
  50% { box-shadow: 0 0 0 7px rgba(61, 220, 132, 0.12), 0 0 20px rgba(61, 220, 132, 0.85); }
}
@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 4px rgba(255, 77, 94, 0.22), 0 0 14px rgba(255, 77, 94, 0.75); }
  50% { box-shadow: 0 0 0 8px rgba(255, 77, 94, 0.1), 0 0 22px rgba(255, 77, 94, 1); }
}

.console-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}

.console-tile {
  position: relative;
  display: block;
  background: linear-gradient(160deg, #1d3557 0%, #14233c 100%);
  border-radius: 16px;
  padding: 26px 22px 22px;
  color: white;
  text-decoration: none;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.06);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
  box-shadow: 0 6px 18px rgba(10, 20, 40, 0.28);
}
.console-tile:hover {
  transform: translateY(-4px) scale(1.015);
  box-shadow: 0 16px 32px rgba(10, 20, 40, 0.4);
  text-decoration: none;
}
.console-tile.attention {
  background: linear-gradient(160deg, #4a1d29 0%, #2c1015 100%);
}
.console-tile .tile-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
}
.console-tile .tile-icon {
  font-size: 2.1rem;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.35));
}
.console-tile .tile-label {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0 0 4px;
}
.console-tile .tile-tagline {
  font-size: 0.82rem;
  color: rgba(255,255,255,0.65);
  margin: 0 0 16px;
}
.console-tile .tile-status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
}
.console-tile .tile-status-row.ok { color: #7ef2b0; }
.console-tile .tile-status-row.attention { color: #ff9aa4; }
.console-tile .tile-count {
  color: rgba(255,255,255,0.5);
  font-size: 0.78rem;
  margin-top: 10px;
}

/* ---- Set-up & Maintenance Instructions ---- */
.help-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
}
.help-tile {
  display: block;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  padding: 20px;
  text-decoration: none;
  color: inherit;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}
.help-tile:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 22px rgba(20, 30, 50, 0.1);
  text-decoration: none;
}
.help-tile .tile-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}
.help-tile .tile-icon { font-size: 1.9rem; line-height: 1; }
.help-tile .tile-label { font-size: 1rem; font-weight: 700; margin: 0 0 4px; color: var(--navy); }
.help-tile .tile-overview {
  font-size: 0.82rem;
  color: var(--gray-700);
  margin: 0;
  line-height: 1.4;
}
.as9100-chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.76rem;
  font-weight: 600;
  background: #e7edf6;
  color: var(--navy);
  margin: 0 6px 6px 0;
}
.instructions-steps {
  margin: 0;
  padding-left: 22px;
}
.instructions-steps li {
  margin-bottom: 12px;
  line-height: 1.5;
  font-size: 0.93rem;
}
.instructions-tips {
  margin: 0;
  padding-left: 20px;
}
.instructions-tips li {
  margin-bottom: 8px;
  line-height: 1.45;
  font-size: 0.88rem;
  color: var(--gray-700);
}
