/* =============================================================
   Volvo Forming Quality App — Shared Components
   Drop in at: frontend/static/css/components.css
   Linked AFTER tokens.css.
   ============================================================= */

/* ── Layout primitives ──────────────────────────── */
.container       { max-width: 1280px; margin: 0 auto; padding: 0 var(--sp-4); }
.container--md   { max-width: 960px; }
.container--sm   { max-width: 700px; }

.stack > * + *   { margin-top: var(--sp-4); }
.stack-sm > * + *{ margin-top: var(--sp-2); }
.row             { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }
.row--end        { justify-content: flex-end; }
.row--between    { justify-content: space-between; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap-grid); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap-grid); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap-grid); }
@media (max-width: 800px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ── Topbar ─────────────────────────────────────── */
.topbar {
  background: var(--volvo-navy);
  color: #fff;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: 0 var(--sp-4);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-1);
}
.topbar__brand { display: flex; align-items: center; gap: var(--sp-3); }
.topbar__logo {
  background: var(--volvo-blue);
  font-weight: 800;
  font-size: var(--fs-md);
  padding: 4px 12px;
  border-radius: 4px;
  letter-spacing: 2px;
}
.topbar__app-name { font-weight: 600; font-size: var(--fs-md); }
.topbar__part {
  background: rgba(255,255,255,.1);
  border-radius: 4px;
  padding: 2px 10px;
  font-size: var(--fs-xs);
}
.topbar__actions { display: flex; align-items: center; gap: var(--sp-2); }
.topbar__user { font-size: var(--fs-sm); opacity: .85; }
.topbar__role-badge {
  background: var(--volvo-blue);
  border-radius: 3px;
  padding: 2px 10px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .5px;
}
.topbar__role-badge--opr { background: #2E7D32; }
.topbar__role-badge--tst { background: var(--volvo-blue); }
.topbar__role-badge--tec,
.topbar__role-badge--eng { background: var(--volvo-blue); }

/* topbar buttons (icon + label) */
.topbar__btn {
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.2);
  color: #fff;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: var(--fs-sm);
  font-family: inherit;
  cursor: pointer;
  height: 40px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background var(--dur-1) var(--ease-out);
}
.topbar__btn:hover { background: rgba(255,255,255,.2); }
.topbar__btn--icon { padding: 7px 12px; font-size: 19px; line-height: 1; position: relative; }

/* role switcher select inside topbar */
.topbar select {
  background: var(--volvo-navy-soft);
  border: 1px solid rgba(255,255,255,.4);
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: var(--fs-md);
  font-family: inherit;
  cursor: pointer;
  height: 40px;
  color-scheme: light;
}
.topbar select option { color: var(--ink); background: #fff; }

/* notification dot */
.notif-dot {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--bad);
  color: #fff;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 13px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  display: none;
}
.notif-dot[data-count]:not([data-count="0"]) { display: block; }

/* notification panel */
.notif-panel {
  display: none;
  position: absolute;
  top: 48px;
  right: 0;
  width: 360px;
  max-height: 420px;
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop);
  z-index: 999;
  overflow: hidden;
}
.notif-panel__head {
  background: var(--volvo-navy);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.notif-panel__title { font-weight: 700; font-size: var(--fs-md); }
.notif-panel__list { overflow-y: auto; max-height: 360px; padding: 6px 0; }
.notif-item {
  padding: 10px 16px;
  border-left: 3px solid transparent;
  font-size: var(--fs-sm);
  color: var(--ink);
}
.notif-item--unread { border-left-color: var(--volvo-blue); background: var(--volvo-blue-tint); }
.notif-item__time { font-size: var(--fs-xs); color: var(--muted); margin-top: 2px; }

/* ── Nav tabs ───────────────────────────────────── */
.navtabs {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 var(--sp-4);
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.navtab {
  padding: 14px 18px;
  border: none;
  cursor: pointer;
  background: transparent;
  font-size: var(--fs-md);
  font-weight: 500;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  font-family: inherit;
  transition: color var(--dur-1) var(--ease-out), border-color var(--dur-1) var(--ease-out);
  min-height: 48px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.navtab:hover { color: var(--ink); }
.navtab[aria-current="page"],
.navtab.active {
  color: var(--volvo-navy);
  font-weight: 700;
  border-bottom-color: var(--volvo-navy);
}
[data-theme="dark"] .navtab[aria-current="page"],
[data-theme="dark"] .navtab.active {
  color: var(--volvo-blue);
  border-bottom-color: var(--volvo-blue);
}

/* ── Page intro ─────────────────────────────────── */
.page-intro { padding: var(--sp-5) 0 var(--sp-3); }
.page-intro h1 {
  color: var(--volvo-navy);
  font-size: var(--fs-2xl);
  font-weight: 700;
  margin: 0;
  letter-spacing: -.01em;
}
.page-intro p {
  color: var(--muted);
  font-size: var(--fs-md);
  margin: 4px 0 0;
}
[data-theme="dark"] .page-intro h1 { color: var(--volvo-blue); }

/* ── Panel (the main card) ──────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel__head {
  padding: 14px 18px;
  font-weight: 700;
  color: var(--volvo-navy);
  font-size: var(--fs-md);
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}
[data-theme="dark"] .panel__head { color: var(--ink); }
.panel__head h2,
.panel__head .panel__title { font-size: var(--fs-md); font-weight: 700; margin: 0; }
.panel__body { padding: var(--pad-card); flex: 1; min-height: 0; }

/* ── Form ───────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label,
label.field__label,
label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--muted);
}
.input, .select, .textarea,
input[type=text], input[type=number], input[type=email], input[type=password], input[type=search],
select, textarea {
  width: 100%;
  padding: var(--pad-input) 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-input);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--fs-lg);
  font-family: inherit;
  outline: none;
  min-height: 44px;
  transition: border-color var(--dur-1) var(--ease-out), box-shadow var(--dur-1) var(--ease-out);
}
.input:focus, .select:focus, .textarea:focus,
input:focus, select:focus, textarea:focus { border-color: var(--volvo-blue); }
textarea { min-height: 80px; resize: vertical; }

/* ── Buttons ────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border: none;
  border-radius: var(--radius-input);
  font-family: inherit;
  font-size: var(--fs-md);
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
  transition: background var(--dur-1) var(--ease-out), transform var(--dur-1) var(--ease-out);
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn--primary { background: var(--volvo-navy); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--volvo-blue); }
[data-theme="dark"] .btn--primary { background: var(--volvo-blue); color: #fff; }

.btn--secondary {
  background: var(--surface);
  color: var(--volvo-navy);
  border: 1.5px solid var(--line);
}
.btn--secondary:hover:not(:disabled) { border-color: var(--volvo-blue); color: var(--volvo-blue); }
[data-theme="dark"] .btn--secondary { background: var(--surface-tint); color: var(--ink); }

.btn--ghost   { background: transparent; color: var(--muted); }
.btn--ghost:hover { color: var(--volvo-navy); }
.btn--success { background: var(--ok); color: #fff; }
.btn--danger  { background: var(--bad); color: #fff; }

.btn--lg { padding: 16px 22px; font-size: var(--fs-lg); min-height: 54px; }
.btn--xl { padding: 20px 28px; font-size: var(--fs-xl); min-height: 64px; }
.btn--block { width: 100%; }

/* ── Status verdict (the answer to "Is the process good?") ── */
.verdict {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--sp-4);
  padding: 18px 22px;
  border-radius: var(--radius-card);
  border: 1.5px solid;
  position: relative;
  overflow: hidden;
}
.verdict__lamp {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  position: relative;
}
.verdict__lamp::before {
  content: '';
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 6px color-mix(in srgb, currentColor 25%, transparent);
}
.verdict__copy { display: flex; flex-direction: column; gap: 2px; }
.verdict__headline {
  font-size: var(--fs-2xl);
  font-weight: 800;
  letter-spacing: -.01em;
  line-height: var(--lh-tight);
}
.verdict__detail { font-size: var(--fs-md); color: var(--muted); }
.verdict__cta {
  background: var(--volvo-navy);
  color: #fff;
  border: none;
  border-radius: var(--radius-input);
  padding: 12px 20px;
  font-weight: 700;
  font-size: var(--fs-md);
  cursor: pointer;
  white-space: nowrap;
  min-height: 44px;
}
.verdict__cta:hover { background: var(--volvo-blue); }

.verdict[data-status="green"]  { background: var(--ok-bg);   border-color: var(--ok-line);   color: var(--ok); }
.verdict[data-status="yellow"] { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.verdict[data-status="red"]    { background: var(--bad-bg);  border-color: var(--bad-line);  color: var(--bad); }

.verdict[data-status="green"]  .verdict__cta { display: none; }

/* ── KPI tile ───────────────────────────────────── */
.kpi {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border-radius: var(--radius-input);
  border: 1px solid var(--line);
  background: var(--surface);
  border-left: 4px solid var(--line);
}
.kpi__label {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.kpi__value {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-2xl);
  font-weight: 700;
  color: var(--ink);
  line-height: var(--lh-tight);
}
.kpi__delta { font-size: var(--fs-xs); color: var(--muted); }

.kpi[data-status="green"]  { background: var(--ok-bg);   border-left-color: var(--ok); }
.kpi[data-status="green"]  .kpi__value { color: var(--ok); }
.kpi[data-status="yellow"] { background: var(--warn-bg); border-left-color: var(--warn); }
.kpi[data-status="yellow"] .kpi__value { color: var(--warn); }
.kpi[data-status="red"]    { background: var(--bad-bg);  border-left-color: var(--bad); }
.kpi[data-status="red"]    .kpi__value { color: var(--bad); }

/* ── Industrial slider ──────────────────────────── */
.islider { display: flex; flex-direction: column; gap: 4px; }
.islider__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
}
.islider__head label { font-size: var(--fs-md); font-weight: 600; color: var(--muted); }
.islider__head output {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: var(--fs-xl);
  color: var(--volvo-navy);
}
[data-theme="dark"] .islider__head output { color: var(--volvo-blue); }
.islider__track { display: flex; align-items: center; gap: 6px; }
.islider__step {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--volvo-navy);
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-family: inherit;
  line-height: 1;
  padding: 0;
  transition: background var(--dur-1), border-color var(--dur-1);
}
.islider__step:hover { background: var(--volvo-blue-tint); border-color: var(--volvo-blue); }
.islider__step:active { background: var(--volvo-blue); color: #fff; border-color: var(--volvo-blue); }

.islider input[type=range] {
  flex: 1;
  height: 28px;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}
.islider input[type=range]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--volvo-blue) var(--filled, 0%), var(--line-soft) var(--filled, 0%));
}
.islider input[type=range]::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: var(--line-soft);
}
.islider input[type=range]::-moz-range-progress {
  height: 6px;
  border-radius: 3px;
  background: var(--volvo-blue);
}
.islider input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--volvo-blue);
  border: 3px solid #fff;
  box-shadow: var(--shadow-2);
  margin-top: -8px;
  cursor: pointer;
}
.islider input[type=range]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--volvo-blue);
  border: 3px solid #fff;
  box-shadow: var(--shadow-2);
  cursor: pointer;
}
.islider__range {
  display: flex;
  justify-content: space-between;
  font-size: var(--fs-xs);
  color: var(--muted-2);
  margin-top: 2px;
  font-family: var(--font-num);
}

/* ── SHAP row ───────────────────────────────────── */
.shap {
  display: grid;
  grid-template-columns: 100px 1fr;
  align-items: center;
  gap: var(--sp-3);
  padding: 8px 0;
}
.shap__name {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink);
}
.shap__bars { display: flex; flex-direction: column; gap: 4px; }
.shap__bar-row {
  display: grid;
  grid-template-columns: 30px 1fr 60px;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-xs);
}
.shap__legend { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.shap__track {
  position: relative;
  height: 10px;
  background: var(--line-soft);
  border-radius: 5px;
  overflow: hidden;
}
.shap__track::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--muted-2);
}
.shap__fill {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 5px;
  transition: width var(--dur-3) var(--ease-out);
}
.shap__fill--pos { left: 50%; background: var(--bad); }
.shap__fill--neg { right: 50%; background: var(--ok); }
.shap__value {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-xs);
  text-align: right;
  color: var(--ink);
}

/* ── Banners / alerts ───────────────────────────── */
.banner {
  display: flex;
  gap: var(--sp-3);
  align-items: flex-start;
  padding: 12px 16px;
  border-radius: var(--radius-input);
  border: 1px solid;
  font-size: var(--fs-sm);
}
.banner--info { background: var(--info-bg); border-color: var(--info-line); color: var(--info); }
.banner--warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.banner--ok   { background: var(--ok-bg);   border-color: var(--ok-line);   color: var(--ok); }
.banner--bad  { background: var(--bad-bg);  border-color: var(--bad-line);  color: var(--bad); }
.banner strong { font-weight: 700; }

/* ── Chip ───────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: var(--radius-chip);
  font-size: var(--fs-xs);
  font-weight: 600;
  background: var(--surface-alt);
  color: var(--muted);
  border: 1px solid var(--line);
}
.chip--ok    { background: var(--ok-bg);   color: var(--ok);   border-color: var(--ok-line); }
.chip--warn  { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.chip--bad   { background: var(--bad-bg);  color: var(--bad);  border-color: var(--bad-line); }
.chip--blue  { background: var(--volvo-blue-tint); color: var(--volvo-blue); border-color: var(--info-line); }
.chip__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ── Locked / disabled note ─────────────────────── */
.lock-note {
  background: var(--surface-tint);
  border: 1px dashed var(--line);
  border-radius: var(--radius-input);
  padding: 12px 16px;
  font-size: var(--fs-xs);
  color: var(--muted);
}
.lock-note__title {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.lock-tag {
  display: inline-block;
  background: var(--surface-alt);
  color: var(--muted);
  padding: 4px 10px;
  border-radius: var(--radius-chip);
  font-size: 13px;
  font-weight: 600;
  margin: 2px;
  border: 1px solid var(--line);
}

/* ── Modal ──────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 999;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay[data-open="true"],
.modal-overlay.is-open { display: flex; }
.modal-box {
  background: var(--surface);
  color: var(--ink);
  border-radius: 16px;
  width: min(420px, 100%);
  max-height: 92vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-pop);
}
.modal-box--md { width: min(620px, 100%); }
.modal-head {
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line-soft);
}
.modal-title {
  font-weight: 700;
  font-size: var(--fs-lg);
  color: var(--volvo-navy);
}
[data-theme="dark"] .modal-title { color: var(--volvo-blue); }
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 26px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
}
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 16px 20px;
  display: flex;
  gap: var(--sp-2);
  justify-content: flex-end;
  border-top: 1px solid var(--line-soft);
}

/* ── Recent rows / list ─────────────────────────── */
.list { display: flex; flex-direction: column; }
.list__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: var(--fs-sm);
  flex-wrap: wrap;
  gap: 6px;
}
.list__row:last-child { border-bottom: none; }
.list__time { color: var(--muted); font-family: var(--font-num); font-size: var(--fs-xs); }
.list__id { font-weight: 600; color: var(--ink); }

/* ── Empty state ────────────────────────────────── */
.empty {
  text-align: center;
  padding: 28px 16px;
  color: var(--muted);
}
.empty__glyph { font-size: 34px; opacity: .55; margin-bottom: 6px; }
.empty__msg { font-size: var(--fs-sm); }

/* ── Toast ──────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ok);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius-input);
  font-size: var(--fs-md);
  font-weight: 600;
  z-index: 9999;
  box-shadow: var(--shadow-pop);
  animation: toastIn var(--dur-2) var(--ease-out);
}
.toast--bad { background: var(--bad); }
.toast--warn { background: var(--warn); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Spinner ────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2.5px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
}
.spinner--dark { border-color: rgba(0,48,87,.2); border-top-color: var(--volvo-navy); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Theme toggle (placed in topbar) ─────────────── */
.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.2);
  color: #fff;
  cursor: pointer;
  font-size: 19px;
  display: grid;
  place-items: center;
}
.theme-toggle:hover { background: rgba(255,255,255,.2); }

/* ── Utility ────────────────────────────────────── */
.hidden { display: none !important; }
.muted { color: var(--muted); }
.text-num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.flex-1 { flex: 1; }

/* ── Print (PDF report friendliness) ─────────────── */
@media print {
  .topbar, .navtabs, .modal-overlay { display: none !important; }
  body { background: #fff; }
  .panel { box-shadow: none; border-color: #ccc; }
}
