:root {
  --ink: #18212f;
  --muted: #64748b;
  --line: #d8e0ea;
  --bg: #f6f7f9;
  --paper: #ffffff;
  --blue: #2563eb;
  --teal: #0f766e;
  --amber: #b45309;
  --red: #be123c;
  --green: #15803d;
  --shadow: 0 16px 36px rgba(24, 33, 47, .10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  background: var(--bg);
}

body.viewer-locked main,
body.viewer-locked .tabs {
  visibility: hidden;
}

.boot-screen {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg);
  color: var(--muted);
  font-size: 14px;
}

.boot-screen[hidden] {
  display: none;
}

.boot-indicator {
  width: 22px;
  height: 22px;
  border: 2px solid #cbd5e1;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: boot-spin .7s linear infinite;
}

@keyframes boot-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .boot-indicator { animation: none; }
}

button, input, select, textarea {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  padding: 8px 13px;
}

button:hover { border-color: #94a3b8; }

.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
}

.danger {
  border-color: #fecdd3;
  background: #fff1f2;
  color: var(--red);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 28px;
  background: rgba(255,255,255,.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #0f172a;
  color: white;
  font-weight: 800;
}

h1, h2, h3, p { margin: 0; }

.brand h1 {
  font-size: 20px;
  line-height: 1.2;
}

.brand p,
.hero p,
.metric p,
.admin-sidebar p {
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 8px;
}

.tab.active {
  border-color: #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
}

main {
  width: min(1480px, calc(100% - 40px));
  margin: 0 auto 40px;
}

.hero {
  min-height: 330px;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, .9fr);
  gap: 28px;
  align-items: center;
  padding: 28px 0;
}

.hero-copy h2 {
  max-width: 760px;
  margin: 10px 0 14px;
  font-size: clamp(32px, 5vw, 58px);
  line-height: 1.08;
  letter-spacing: 0;
}

.eyebrow {
  color: var(--teal);
  font-weight: 700;
  text-transform: uppercase;
}

.hero-panel {
  min-height: 270px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, #ffffff 0%, #edf7f4 52%, #fff7ed 100%);
  box-shadow: var(--shadow);
  padding: 22px;
}

.flow {
  display: grid;
  grid-template-columns: 1fr 24px 1fr 24px 1fr 24px 1fr;
  align-items: center;
  gap: 8px;
}

.flow span {
  min-height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: rgba(255,255,255,.86);
  font-weight: 700;
  text-align: center;
}

.flow i {
  height: 2px;
  background: #64748b;
  position: relative;
}

.flow i::after {
  content: "";
  position: absolute;
  right: -1px;
  top: -4px;
  border-left: 8px solid #64748b;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
}

.device-visual {
  height: 170px;
  margin-top: 28px;
  display: grid;
  place-items: center;
}

.screen {
  width: min(310px, 80%);
  aspect-ratio: 16 / 9;
  border: 10px solid #111827;
  border-radius: 8px;
  background: #e8eef5;
  position: relative;
  overflow: hidden;
}

.screen::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 6px;
  background: #f8fafc;
}

.face {
  position: absolute;
  left: 28px;
  top: 28px;
  width: 72px;
  height: 88px;
  border-radius: 45% 45% 48% 48%;
  background: #f5c2b8;
  box-shadow: inset 0 -18px 0 rgba(190,18,60,.13);
}

.face::before, .face::after {
  content: "";
  position: absolute;
  top: 35px;
  width: 9px;
  height: 4px;
  border-radius: 8px;
  background: #334155;
}

.face::before { left: 19px; }
.face::after { right: 19px; }

.bars {
  position: absolute;
  left: 126px;
  right: 24px;
  top: 34px;
  display: grid;
  gap: 12px;
}

.bars b {
  height: 12px;
  border-radius: 6px;
  background: #93c5fd;
}

.bars b:nth-child(2) { width: 78%; background: #5eead4; }
.bars b:nth-child(3) { width: 92%; background: #fed7aa; }
.bars b:nth-child(4) { width: 64%; background: #fda4af; }

.stand {
  width: 92px;
  height: 16px;
  background: #111827;
  border-radius: 0 0 8px 8px;
}

.view { display: none; }
.view.active { display: block; }

.toolbar {
  display: grid;
  grid-template-columns: 42px minmax(260px, 1fr) 210px 170px;
  gap: 14px;
  align-items: end;
  margin-bottom: 18px;
}

.directory-toggle {
  width: 42px;
  height: 42px;
  min-height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  align-self: end;
}

.directory-toggle svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.directory-toggle.is-collapsed .toggle-arrow {
  transform: rotate(180deg);
  transform-origin: center;
}

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

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.content-grid {
  display: grid;
  grid-template-columns: 390px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.content-grid.directory-collapsed {
  grid-template-columns: minmax(0, 1fr);
}

.content-grid.directory-collapsed .list-panel {
  display: none;
}

.list-panel,
.detail-panel,
.sop-map,
.gallery-section,
.admin-sidebar,
.editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 8px 20px rgba(24, 33, 47, .04);
}

.list-panel {
  max-height: calc(100vh - 168px);
  overflow: hidden;
  position: sticky;
  top: 86px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head span { color: var(--muted); }

.procedure-list {
  max-height: calc(100vh - 222px);
  overflow: auto;
  padding: 8px;
}

.procedure-item {
  width: 100%;
  display: grid;
  gap: 5px;
  margin-bottom: 8px;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.procedure-item.active {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.procedure-item small,
.badges,
.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  color: #334155;
  background: #f1f5f9;
  font-size: 12px;
}

.badge.critical { background: #ffe4e6; color: #be123c; }
.badge.high { background: #ffedd5; color: #c2410c; }
.badge.medium { background: #dbeafe; color: #1d4ed8; }
.badge.low { background: #dcfce7; color: #15803d; }

.detail-panel {
  min-height: 560px;
  padding: 24px;
}

.detail-title {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
}

.detail-title h3 {
  font-size: 30px;
  line-height: 1.2;
  letter-spacing: 0;
}

.detail-section {
  margin-top: 22px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  padding-bottom: 4px;
}

.detail-actions button {
  min-height: 34px;
  padding: 6px 11px;
  font-size: 14px;
}

.detail-actions button:first-child {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
}

.share-page-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 650;
}

.share-page-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.detail-actions button:disabled {
  cursor: default;
  opacity: .72;
}

.detail-section h4 {
  margin: 0 0 10px;
  font-size: 17px;
}

.answer-box,
.escalation-box {
  border-left: 4px solid var(--teal);
  border-radius: 8px;
  background: #f0fdfa;
  padding: 14px 16px;
  line-height: 1.75;
}

.escalation-box {
  border-left-color: var(--amber);
  background: #fffbeb;
}

.steps {
  display: grid;
  gap: 10px;
  counter-reset: step;
}

.steps li {
  list-style: none;
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 12px;
  align-items: start;
  line-height: 1.7;
}

.steps li::before {
  counter-increment: step;
  content: counter(step);
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #e0f2fe;
  color: #0369a1;
  font-weight: 800;
}

.check-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  padding: 0;
}

.check-list li {
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: #fbfdff;
  line-height: 1.55;
}

.attachments {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.attachments a,
.media-gallery a {
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  color: var(--ink);
  text-decoration: none;
}

.attachments img,
.media-gallery img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  background: #f1f5f9;
}

.attachments span,
.media-gallery span {
  display: block;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 12px;
}

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

.video-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.video-card video {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #0f172a;
  object-fit: contain;
}

.video-card-info {
  padding: 10px 12px;
}

.video-card-info strong,
.video-card-info small {
  display: block;
}

.video-card-info small {
  margin-top: 3px;
  color: var(--muted);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 18px;
}

.metric span {
  display: block;
  font-size: 34px;
  font-weight: 800;
}

.sop-map,
.gallery-section {
  margin-bottom: 18px;
  padding: 20px;
}

.timeline {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.timeline div {
  min-height: 164px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdff;
}

.timeline b {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #0f172a;
  color: white;
}

.timeline strong {
  display: block;
  margin: 12px 0 8px;
}

.timeline p {
  color: var(--muted);
  line-height: 1.6;
}

.media-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.admin-layout {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 18px;
}

.admin-sidebar,
.editor {
  padding: 16px;
}

.admin-sidebar {
  display: grid;
  align-content: start;
  gap: 10px;
}

.file-btn {
  display: grid;
  place-items: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  cursor: pointer;
}

.file-btn input { display: none; }

.admin-list {
  display: grid;
  gap: 6px;
  max-height: 520px;
  overflow: auto;
  margin-top: 8px;
}

.admin-list button {
  text-align: left;
  white-space: normal;
  height: auto;
}

.admin-list button.active {
  border-color: #bfdbfe;
  background: #eff6ff;
}

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

.form-row {
  display: grid;
  gap: 14px;
}

.form-row.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

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

.resource-editor {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdff;
}

.resource-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.resource-editor-head h3 {
  font-size: 16px;
}

.resource-editor-head p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.video-editor-rows {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.video-resource-row {
  display: grid;
  grid-template-columns: minmax(140px, .8fr) minmax(180px, 1fr) minmax(180px, 1fr) 38px;
  gap: 10px;
  align-items: end;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.video-resource-row label {
  min-width: 0;
}

.video-resource-row .remove-video {
  width: 38px;
  min-width: 38px;
  padding: 0;
  color: var(--red);
}

.empty {
  display: grid;
  place-items: center;
  min-height: 360px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 1050px) {
  .hero,
  .content-grid,
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .list-panel {
    position: static;
    max-height: none;
  }

  .procedure-list {
    max-height: 360px;
  }

  .timeline,
  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 12px 16px;
  }

  main {
    width: min(100% - 24px, 1480px);
  }

  .tabs,
  .toolbar,
  .form-row.two,
  .form-row.three,
  .timeline,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
  }

  .hero {
    min-height: auto;
    padding: 18px 0;
  }

  .hero-panel {
    min-height: 240px;
    padding: 14px;
  }

  .flow {
    grid-template-columns: 1fr;
  }

  .flow i {
    height: 18px;
    width: 2px;
    justify-self: center;
  }

  .flow i::after {
    top: auto;
    right: -4px;
    bottom: -1px;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 8px solid #64748b;
    border-bottom: 0;
  }

  .detail-title {
    flex-direction: column;
  }

  .detail-title h3 {
    font-size: 24px;
  }

  .video-resource-row {
    grid-template-columns: 1fr;
  }

  .video-resource-row .remove-video {
    width: 100%;
  }
}

/* Compact hero tuning for the customized SOP index page. */
.hero {
  min-height: 165px;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, .8fr);
  gap: 20px;
  padding: 10px 0 12px;
}

.hero-copy h2 {
  margin: 6px 0 8px;
  font-size: clamp(27px, 3.3vw, 40px);
  line-height: 1.12;
}

.hero-copy > p:last-child {
  font-size: 14px;
  line-height: 1.5;
}

.eyebrow {
  font-size: 12px;
  font-weight: 650;
}

.hero-panel {
  min-height: 115px;
  padding: 10px 12px;
}

.flow span {
  min-height: 28px;
  font-size: 13px;
  font-weight: 600;
}

.device-visual {
  height: 56px;
  margin-top: 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.screen {
  width: min(240px, 76%);
  height: 50px;
  aspect-ratio: auto;
  border-width: 4px;
}

.screen::before {
  inset: 4px;
}

.face {
  left: 18px;
  top: 8px;
  width: 28px;
  height: 32px;
  box-shadow: inset 0 -7px 0 rgba(190,18,60,.12);
}

.face::before,
.face::after {
  top: 13px;
  width: 4px;
  height: 2px;
}

.face::before { left: 8px; }
.face::after { right: 8px; }

.bars {
  left: 78px;
  right: 18px;
  top: 9px;
  gap: 4px;
}

.bars b {
  height: 4px;
}

.stand {
  width: 54px;
  height: 6px;
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, .45);
}

.auth-modal[hidden] {
  display: none;
}

.auth-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: 22px;
}

.auth-card h3 {
  font-size: 22px;
}

.auth-card p {
  color: var(--muted);
  line-height: 1.6;
}

.auth-error {
  min-height: 20px;
  color: var(--red);
  font-size: 14px;
}

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

@media (max-width: 1050px) {
  .hero {
    grid-template-columns: minmax(0, 1fr) minmax(300px, .85fr);
  }
}

@media (max-width: 720px) {
  .hero {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 10px 0 12px;
  }

  .hero-panel {
    min-height: 50px;
    padding: 9px 10px;
  }

  .device-visual {
    display: none;
  }

  .flow {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: thin;
    padding-bottom: 2px;
  }

  .flow span {
    min-width: 92px;
    min-height: 30px;
    flex: 1 0 92px;
    font-size: 12px;
  }

  .flow i {
    display: block;
    width: auto;
    height: 2px;
    flex: 0 0 12px;
    align-self: center;
  }

  .flow i::after {
    top: -4px;
    right: -1px;
    bottom: auto;
    border-left: 7px solid #64748b;
    border-right: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
  }
}
