@import url('https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@400;500;600;700&family=Space+Grotesk:wght@500;600;700&display=swap');

:root {
  --bg: #0b111b;
  --bg-glow: #132035;
  --surface: #111a29;
  --card: #f8fafc;
  --ink: #0b0f18;
  --muted: #5b6678;
  --stroke: #e5e7eb;
  --brand: #f59e0b;
  --brand-deep: #f97316;
  --accent: #14b8a6;
  --danger: #dc2626;
  --ok: #22c55e;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
  --fs-title: 2rem;
  --fs-h2: 1.4rem;
  --fs-h3: 1.1rem;
  --fs-body: 1rem;
  --fs-small: 0.9rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Instrument Sans', system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at 20% 20%, rgba(245, 158, 11, 0.15), transparent 40%),
              radial-gradient(circle at 85% 15%, rgba(20, 184, 166, 0.12), transparent 45%),
              linear-gradient(160deg, #eef1f7, #f9fafb 45%, #eef2f7);
  color: var(--ink);
  min-height: 100vh;
  font-size: var(--fs-body);
}

h1, h2, h3 {
  font-family: 'Space Grotesk', system-ui, -apple-system, sans-serif;
  margin: 0;
}

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

.app-shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 18px 80px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(12, 17, 27, 0.9);
  color: #f8fafc;
  border-radius: 18px;
  padding: 16px 18px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.3);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 14px;
  z-index: 20;
}

.brand-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.brand-title {
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-size: 0.75rem;
  opacity: 0.7;
}

.brand-name {
  font-size: 1.35rem;
  font-weight: 700;
}

.header-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: right;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.6);
  font-size: 0.75rem;
  font-weight: 700;
}

.status-pill.online { color: #6ee7b7; }
.status-pill.offline { color: #fda4af; }

.page-title {
  font-size: var(--fs-title);
  letter-spacing: -0.02em;
  margin-top: 18px;
}

.page-subtitle {
  color: var(--muted);
  margin: 6px 0 20px;
  font-size: var(--fs-small);
}

.card {
  background: var(--card);
  border-radius: 18px;
  padding: 18px;
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  animation: floatIn 0.4s ease forwards;
}

.card.dark {
  background: #0f172a;
  color: #e2e8f0;
  border-color: rgba(255,255,255,0.08);
}

.grid {
  display: grid;
  gap: 14px;
}

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

.grid.three {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.section-title {
  font-size: var(--fs-h3);
  margin-bottom: 10px;
}

.sticky-actions {
  position: sticky;
  bottom: 12px;
  background: rgba(248, 250, 252, 0.94);
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 10px;
  box-shadow: var(--shadow);
  z-index: 30;
}

.section-note {
  color: var(--muted);
  margin-top: 6px;
}

.section-note.ok {
  color: var(--ok);
}

.section-note.warn {
  color: var(--danger);
}

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

.is-hidden {
  display: none;
}

.input, select, textarea {
  width: 100%;
  padding: 14px 14px;
  border-radius: 14px;
  border: 1px solid #d7dbe3;
  font-weight: 600;
  background: #fff;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand-deep);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.25);
}

label {
  font-weight: 700;
  margin-bottom: 6px;
  display: block;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid #d5d9e2;
  background: #fff;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.btn.primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-deep));
  border-color: var(--brand-deep);
  color: #111827;
}

.btn.ghost {
  background: rgba(255,255,255,0.08);
  color: #f8fafc;
  border-color: rgba(255,255,255,0.2);
}

.btn.danger {
  background: #dc2626;
  color: #fff;
  border-color: #dc2626;
}

.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; box-shadow: none; }

.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}

.action-card {
  background: #ffffff;
  border-radius: 16px;
  padding: 16px;
  border: 1px solid #e2e8f0;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 140px;
}

.action-card h3 { font-size: 1.05rem; }

.action-card p {
  margin: 0;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 0.78rem;
  font-weight: 700;
}

.badge.ok { background: #0f766e; }
.badge.warn { background: #b45309; }
.badge.danger { background: #b91c1c; }

.inline-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.inline-row.end { justify-content: flex-end; }

.run-card {
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 14px;
  background: #fff;
  display: grid;
  gap: 6px;
}

.run-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  font-size: 0.9rem;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid #d1d5db;
  font-weight: 700;
  background: #fff;
  cursor: pointer;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chip.active {
  background: #0ea5e9;
  border-color: #0ea5e9;
  color: #fff;
}

.stack {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.patient-card {
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  padding: 14px;
  background: #fff;
  display: grid;
  gap: 10px;
}

.patient-card .chip-row {
  margin-top: 6px;
}

.patient-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid #d1d5db;
  font-weight: 700;
  background: #fff;
  min-height: 42px;
}

.toggle.active {
  background: #0ea5e9;
  border-color: #0ea5e9;
  color: #fff;
}

.check-list {
  display: grid;
  gap: 12px;
}

.cupboard-check-list {
  display: grid;
  gap: 10px;
}

.check-card {
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  padding: 14px;
  background: #fff;
  display: grid;
  gap: 10px;
}

.check-card.defect {
  border-color: #ef4444;
  background: #fff1f2;
}

.stock-list {
  display: grid;
  gap: 14px;
}

.stock-item {
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  padding: 14px;
  background: #fff;
  display: grid;
  gap: 12px;
}

.stock-item.flagged {
  border-color: #f59e0b;
  background: #fffbeb;
}

.stock-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stock-item-name {
  font-weight: 700;
}

.stock-item-meta {
  font-size: 0.85rem;
  color: #64748b;
}

.stock-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.stock-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.input-error {
  border-color: #ef4444 !important;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

.check-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.check-btn {
  flex: 1;
  min-height: 46px;
  border-radius: 12px;
  border: 1px solid #d1d5db;
  background: #fff;
  font-weight: 700;
}

.check-btn.pass.active { background: #22c55e; color: #fff; border-color: #22c55e; }
.check-btn.defect.active { background: #ef4444; color: #fff; border-color: #ef4444; }

.vdi-list {
  display: grid;
  gap: 14px;
}

.vdi-list.fail {
  border: 2px solid #ef4444;
  border-radius: 18px;
  padding: 8px;
  background: rgba(239, 68, 68, 0.08);
}

.vdi-section {
  border: 1px solid #e2e8f0;
}

.vdi-section.fail {
  border-color: #ef4444;
  background: #fff1f2;
}

.vdi-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.vdi-items {
  display: grid;
  gap: 12px;
}

.vdi-item {
  border-radius: 14px;
  border: 1px solid #e2e8f0;
  padding: 12px;
  background: #fff;
  display: grid;
  gap: 10px;
}

.vdi-item-label {
  font-weight: 700;
}

.status-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.status-btn {
  flex: 1;
  min-height: 42px;
  border-radius: 12px;
  border: 1px solid #d1d5db;
  background: #fff;
  font-weight: 700;
}

.status-btn[data-status="pass"].active { background: #22c55e; color: #fff; border-color: #22c55e; }
.status-btn[data-status="fail"].active { background: #ef4444; color: #fff; border-color: #ef4444; }
.status-btn[data-status="na"].active { background: #64748b; color: #fff; border-color: #64748b; }

.ext-compliance-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.ext-compliance-item {
  border: 1px solid #cfd8e3;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  padding: 12px 14px;
  display: grid;
  gap: 10px;
}

.ext-compliance-item.warn {
  border-color: #f59e0b;
  background: linear-gradient(180deg, #ffffff, #fffbeb);
}

.ext-compliance-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.ext-compliance-index {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: #dbeafe;
  border: 1px solid #bfdbfe;
  color: #1e3a8a;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ext-compliance-code {
  color: #0f172a;
  font-weight: 700;
}

.ext-compliance-code.missing {
  color: #b45309;
}

.ext-compliance-meta {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.ext-meta-cell {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #fff;
  padding: 8px 10px;
  display: grid;
  gap: 4px;
}

.ext-meta-label {
  color: #64748b;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ext-meta-value {
  color: #0f172a;
  font-weight: 700;
}

.ext-meta-value.missing {
  color: #b45309;
}

.ext-type-pill {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
  font-size: 0.78rem;
  font-weight: 700;
}

.cupboard-card {
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  padding: 14px;
  background: #fff;
  display: grid;
  gap: 10px;
}

.cupboard-meta {
  display: grid;
  gap: 4px;
  font-size: 0.9rem;
  color: #475569;
}

.cupboard-verify {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.cupboard-status {
  font-weight: 700;
}

.cupboard-audit {
  border-top: 1px dashed #e2e8f0;
  padding-top: 12px;
  display: grid;
  gap: 10px;
}

.audit-grid {
  display: grid;
  gap: 8px;
}

.audit-row {
  display: grid;
  grid-template-columns: 1.6fr 0.7fr 0.9fr 0.9fr;
  gap: 8px;
  align-items: center;
}

.audit-row.header {
  font-weight: 700;
  font-size: 0.85rem;
  color: #475569;
}

.audit-row .input {
  width: 100%;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.banner {
  padding: 12px 14px;
  border-radius: 14px;
  font-weight: 700;
  display: none;
}

.banner.show { display: block; }
.banner.error { background: #fee2e2; color: #991b1b; }
.banner.warn { background: #fef3c7; color: #92400e; }
.banner.info { background: #e0f2fe; color: #075985; }

.text-warn { color: #b45309; }

.toast-wrap {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: grid;
  gap: 10px;
  z-index: 60;
}

.toast {
  padding: 12px 14px;
  border-radius: 12px;
  background: #0f172a;
  color: #e2e8f0;
  font-weight: 700;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.35);
}

.toast.ok { background: #15803d; }
.toast.warn { background: #b45309; }
.toast.error { background: #b91c1c; }

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

.damage-view {
  position: relative;
  border-radius: 16px;
  border: 1px solid #dbe2ea;
  background: #f8fafc;
  min-height: 180px;
  overflow: hidden;
  cursor: crosshair;
  padding: 10px;
  background-repeat: no-repeat;
  background-size: 200% 200%;
  background-image: url("/assets/renault master topology.png");
}

.damage-view.readonly { cursor: default; }

.damage-view[data-view="front"] { background-position: 0% 0%; }
.damage-view[data-view="rear"] { background-position: 100% 0%; }
.damage-view[data-view="left"] { background-position: 0% 100%; }
.damage-view[data-view="right"] { background-position: 100% 100%; }

.damage-view .view-label {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 3;
  background: rgba(15, 23, 42, 0.8);
  color: #f8fafc;
  font-weight: 700;
  font-size: 0.75rem;
  padding: 6px 10px;
  border-radius: 999px;
}

.damage-view svg {
  width: 100%;
  height: 100%;
  opacity: 0.9;
}

.damage-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.damage-marker {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ef4444;
  border: 2px solid #fff;
  box-shadow: 0 6px 12px rgba(15, 23, 42, 0.25);
  transform: translate(-50%, -50%);
}

.damage-list {
  display: grid;
  gap: 10px;
}

.damage-item {
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 12px;
  background: #fff;
  display: grid;
  gap: 8px;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}

.photo-thumb {
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  overflow: hidden;
  position: relative;
  background: #fff;
}

.photo-thumb img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
}

.photo-thumb button {
  position: absolute;
  top: 6px;
  right: 6px;
  min-height: 32px;
  padding: 4px 8px;
  border-radius: 999px;
}

@keyframes floatIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 820px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .header-meta { text-align: left; }
}

@media (max-width: 560px) {
  .app-shell { padding: 16px 14px 72px; }
  .page-title { font-size: 1.6rem; }
  .btn { width: 100%; }
  .inline-row.end { justify-content: stretch; }
  .audit-row { grid-template-columns: 1fr; }
  .audit-row.header { display: none; }
  .sticky-actions {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
  }
}
