/* MigoPro L4 Unified Delivery Portal Styles */
:root {
  --l4-bg: #f1f4f9;
  --l4-surface: #ffffff;
  --l4-surface-2: #f8fafc;
  --l4-navy: #0b1324;
  --l4-navy-2: #15223c;
  --l4-ink: #0f172a;
  --l4-ink-2: #334155;
  --l4-muted: #64748b;
  --l4-border: #dbe2ee;
  --l4-border-strong: #cbd5e1;
  --l4-brand: #1754d6;
  --l4-brand-soft: #eff6ff;
  --l4-amber: #f59e0b;
  --l4-amber-bright: #ffb020;
  --l4-emerald: #059669;
  --l4-danger: #dc2626;
  --l4-radius: 12px;
  --l4-font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --l4-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--l4-bg);
  color: var(--l4-ink);
  font: 13.5px/1.55 var(--l4-font);
  -webkit-font-smoothing: antialiased;
}

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

.l4-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ==================== Top Command Bar ==================== */
.l4-topbar {
  flex: none;
  min-height: 54px;
  padding: 6px 16px;
  background: linear-gradient(90deg, #0b1324 0%, #13213c 60%, #0e1a30 100%);
  color: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.l4-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.l4-logo {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(180deg, #ffc857 0%, #f59e0b 100%);
  color: #0b1324;
  font-weight: 800;
  font-size: 14px;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 10px rgba(245, 158, 11, 0.35);
  flex: none;
}

.l4-brand-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
}
.l4-brand-meta strong { font-size: 14px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }
.l4-brand-meta small { font-size: 11.5px; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.l4-view-switch {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.08);
  padding: 3px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  gap: 4px;
}

.l4-view-tab {
  border: 0;
  background: transparent;
  color: #cbd5e1;
  padding: 6px 14px;
  border-radius: 7px;
  font: 600 13px/1.2 var(--l4-font);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}
.l4-view-tab:hover { color: #ffffff; background: rgba(255, 255, 255, 0.07); }
.l4-view-tab.is-active {
  background: #ffffff;
  color: #0b1324;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.l4-view-tab .tab-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #64748b;
}
.l4-view-tab.is-active .tab-dot { background: #1754d6; }
.l4-view-tab .tab-pill {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: inherit;
}
.l4-view-tab.is-active .tab-pill {
  background: #e0e7ff;
  color: #1e40af;
}

.l4-top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.l4-ghost-link, .l4-ghost-btn {
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 7px;
  padding: 5px 10px;
  font: 600 12px/1.2 var(--l4-font);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.l4-ghost-link:hover, .l4-ghost-btn:hover { background: rgba(255, 255, 255, 0.16); color: #ffffff; }

/* ==================== Views & Toolbars ==================== */
.l4-view {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.l4-view[hidden] { display: none !important; }

.l4-proto-toolbar, .l4-srs-toolbar {
  flex: none;
  background: var(--l4-surface);
  border-bottom: 1px solid var(--l4-border);
  padding: 7px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.l4-toolbar-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  position: relative;
}
.l4-toolbar-right { margin-left: auto; }

.l4-plat-btn {
  border: 1px solid var(--l4-border);
  background: var(--l4-surface-2);
  color: var(--l4-ink-2);
  padding: 5px 10px;
  border-radius: 7px;
  font: 600 12.5px/1.2 var(--l4-font);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.l4-plat-btn .cnt {
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155;
}
.l4-plat-btn.is-active {
  background: #1754d6;
  border-color: #1754d6;
  color: #ffffff;
}
.l4-plat-btn.is-active .cnt {
  background: rgba(255, 255, 255, 0.22);
  color: #ffffff;
}

.l4-select-wrap {
  display: inline-flex;
  align-items: center;
  background: var(--l4-surface-2);
  border: 1px solid var(--l4-border);
  border-radius: 7px;
  overflow: hidden;
}
.l4-ctrl-tag {
  padding: 5px 8px;
  font-size: 11.5px;
  font-weight: 700;
  background: #eef2ff;
  color: #1e40af;
  border-right: 1px solid var(--l4-border);
  white-space: nowrap;
}
.l4-ctrl-tag.is-exc {
  background: #fff7ed;
  color: #b45309;
}
.l4-ctrl-tag.is-role {
  background: #ecfdf5;
  color: #047857;
}

.l4-select-wrap select, #h5-viewport-select {
  border: 0;
  background: transparent;
  color: var(--l4-ink);
  font: 600 12.5px/1.3 var(--l4-font);
  padding: 5px 8px;
  max-width: 260px;
  outline: none;
  cursor: pointer;
}
#h5-viewport-select {
  border: 1px solid var(--l4-border);
  border-radius: 7px;
  background: var(--l4-surface-2);
}

.l4-mini-search {
  border: 1px solid var(--l4-border);
  border-radius: 7px;
  padding: 5px 9px;
  font: 12.5px/1.3 var(--l4-font);
  width: 190px;
  background: #ffffff;
}
.l4-mini-search:focus {
  outline: 2px solid rgba(23, 84, 214, 0.25);
  border-color: var(--l4-brand);
}

.l4-filter-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: min(460px, 90vw);
  max-height: 360px;
  overflow-y: auto;
  background: #ffffff;
  border: 1px solid var(--l4-border-strong);
  border-radius: 10px;
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.18);
  z-index: 200;
  padding: 6px;
}
.l4-filter-item {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 7px 10px;
  border-radius: 7px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.l4-filter-item:hover { background: #eff6ff; }
.l4-filter-item strong { font-size: 12.5px; color: var(--l4-ink); }
.l4-filter-item small { font-size: 11px; color: var(--l4-muted); font-family: var(--l4-mono); }

.l4-mini-btn {
  border: 1px solid var(--l4-border);
  background: #ffffff;
  color: var(--l4-ink-2);
  border-radius: 7px;
  padding: 5px 10px;
  font: 600 12px/1.2 var(--l4-font);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.l4-mini-btn:hover:not(:disabled) { border-color: var(--l4-brand); color: var(--l4-brand); }
.l4-mini-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.l4-mini-btn.is-primary { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }

/* Flow bar & Subroute bar */
.l4-flow-bar, .l4-subroute-bar {
  flex: none;
  padding: 6px 14px;
  background: #f8fafc;
  border-bottom: 1px solid var(--l4-border);
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
}
.l4-flow-bar[hidden], .l4-subroute-bar[hidden] { display: none !important; }
.l4-flow-step {
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #334155;
  padding: 4px 10px;
  border-radius: 999px;
  font: 600 12px/1.2 var(--l4-font);
  cursor: pointer;
  white-space: nowrap;
}
.l4-flow-step.is-active {
  background: #0b1324;
  border-color: #0b1324;
  color: #ffb020;
}
.l4-flow-arrow { color: #94a3b8; font-size: 12px; }

/* ==================== Prototype Split Workspace ==================== */
.l4-proto-workspace {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 410px;
  overflow: hidden;
}
.l4-proto-workspace.is-rail-collapsed {
  grid-template-columns: minmax(0, 1fr);
}
.l4-proto-workspace.is-rail-collapsed .l4-spec-rail {
  display: none;
}

.l4-canvas-stage {
  min-width: 0;
  min-height: 0;
  background: radial-gradient(circle at top, #e8eef7 0%, #dde5f0 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 14px;
}
.l4-canvas-stage.is-desktop {
  padding: 0;
  background: #ffffff;
}

.l4-frame-shell {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #ffffff;
}
.l4-frame-shell.is-h5 {
  width: 360px;
  height: min(832px, calc(100% - 4px));
  border-radius: 28px;
  border: 6px solid #162033;
  box-shadow: 0 22px 52px rgba(11, 19, 36, 0.24);
  overflow: hidden;
  flex: none;
}
.l4-frame-shell.is-desktop .l4-phone-notch { display: none; }

.l4-phone-notch {
  flex: none;
  height: 28px;
  padding: 0 14px;
  background: #0f172a;
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.phone-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34d399;
}

#proto-iframe {
  flex: 1 1 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #ffffff;
}

/* ==================== Right 4D Quick-Glance Spec Rail ==================== */
.l4-spec-rail {
  background: var(--l4-surface);
  border-left: 1px solid var(--l4-border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.l4-rail-header {
  flex: none;
  padding: 14px 16px 12px;
  background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
  border-bottom: 1px solid var(--l4-border);
}

.l4-rail-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 6px;
}
.l4-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.l4-badge.is-plat { background: #0b1324; color: #ffb020; }
.l4-badge.is-group { background: #eff6ff; color: #1d4ed8; }
.l4-badge.is-perm { background: #ecfdf5; color: #047857; font-family: var(--l4-mono); }

.l4-rail-header h1 {
  margin: 0 0 4px;
  font-size: 15.5px;
  line-height: 1.35;
  color: var(--l4-ink);
}
.l4-rail-path {
  margin: 0 0 10px;
  font-size: 11.5px;
  color: var(--l4-muted);
  font-family: var(--l4-mono);
  word-break: break-all;
}

.l4-jump-srs-btn {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #1754d6;
  background: #1754d6;
  color: #ffffff;
  font: 700 12.5px/1.3 var(--l4-font);
  cursor: pointer;
  transition: background 0.15s ease;
}
.l4-jump-srs-btn:hover { background: #1e40af; }

.l4-rail-body {
  flex: 1 1 0;
  overflow-y: auto;
  padding: 12px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.l4-dim-card {
  border: 1px solid var(--l4-border);
  border-radius: 10px;
  background: #ffffff;
  padding: 10px 12px;
}
.l4-dim-card h2 {
  margin: 0 0 7px;
  font-size: 12.5px;
  font-weight: 750;
  color: #1e3a8a;
  display: flex;
  align-items: center;
  gap: 6px;
}
.l4-dim-card h2 .dim-idx {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: #dbeafe;
  color: #1e40af;
  font-size: 11px;
  display: inline-grid;
  place-items: center;
}
.l4-dim-card ul {
  margin: 0;
  padding-left: 17px;
  color: var(--l4-ink-2);
  font-size: 12.5px;
  line-height: 1.58;
}
.l4-dim-card li + li { margin-top: 5px; }
.l4-dim-card code {
  font-family: var(--l4-mono);
  font-size: 11.5px;
  background: #f1f5f9;
  padding: 1px 4px;
  border-radius: 4px;
  color: #0f172a;
}

/* ==================== Full SRS Reader View ==================== */
.l4-srs-search-box {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 360px;
  max-width: 620px;
}
#srs-search-input {
  flex: 1;
  min-width: 180px;
  border: 1px solid var(--l4-border-strong);
  border-radius: 8px;
  padding: 6px 11px;
  font: 13px/1.3 var(--l4-font);
}
#srs-search-input:focus {
  outline: 2px solid rgba(23, 84, 214, 0.22);
  border-color: var(--l4-brand);
}
.l4-search-count {
  font-size: 12px;
  color: var(--l4-muted);
  white-space: nowrap;
}

.l4-srs-chapter-pills {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.l4-srs-workspace {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  overflow: hidden;
}

.l4-srs-toc {
  background: #f8fafc;
  border-right: 1px solid var(--l4-border);
  overflow-y: auto;
  padding: 12px 10px 32px;
}
.toc-chapter { margin-bottom: 8px; }
.toc-chapter > summary {
  cursor: pointer;
  padding: 7px 8px;
  border-radius: 7px;
  font-weight: 750;
  font-size: 13px;
  color: #0f172a;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.toc-chapter > summary:hover { background: #e2e8f0; }
.toc-chapter[open] > summary { background: #eef2ff; color: #1e3a8a; }
.toc-list {
  margin: 4px 0 6px 8px;
  padding-left: 8px;
  border-left: 2px solid #e2e8f0;
  list-style: none;
}
.toc-link {
  display: block;
  padding: 4px 8px;
  border-radius: 6px;
  color: #475569;
  text-decoration: none;
  font-size: 12.2px;
  line-height: 1.4;
  margin-bottom: 2px;
}
.toc-link:hover { background: #e2e8f0; color: #0f172a; }
.toc-link.is-active {
  background: #1754d6;
  color: #ffffff;
  font-weight: 650;
}
.toc-link.is-sub {
  padding-left: 18px;
  font-size: 11.8px;
}

.l4-srs-reader {
  overflow-y: auto;
  padding: 28px 40px 80px;
  background: #ffffff;
  scroll-behavior: smooth;
}

.srs-doc-container {
  max-width: 1080px;
  margin: 0 auto;
}

.srs-hero-banner {
  background: linear-gradient(135deg, #0b1324 0%, #172a4a 100%);
  color: #f8fafc;
  padding: 26px 30px;
  border-radius: 16px;
  margin-bottom: 28px;
}
.srs-hero-banner h1 { margin: 0 0 8px; font-size: 24px; letter-spacing: -0.02em; }
.srs-hero-banner p { margin: 0; color: #cbd5e1; font-size: 13.5px; line-height: 1.65; }
.srs-hero-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 16px;
}
.srs-kpi {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 10px 12px;
}
.srs-kpi strong { display: block; font-size: 18px; color: #ffb020; }
.srs-kpi span { font-size: 11.5px; color: #cbd5e1; }

.srs-chapter-block {
  margin-bottom: 44px;
  padding-top: 8px;
  border-top: 2px solid #0f172a;
}
.srs-chapter-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.srs-chapter-head h2 {
  margin: 0;
  font-size: 22px;
  color: #0b1324;
}

.srs-section-card {
  margin: 0 0 26px;
  padding: 20px 24px;
  border: 1px solid var(--l4-border);
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.03);
}
.srs-section-card.is-highlight-target {
  border-color: #1754d6;
  box-shadow: 0 0 0 3px rgba(23, 84, 214, 0.18);
}

.srs-sec-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid #e2e8f0;
}
.srs-sec-top h3, .srs-sec-top h4 {
  margin: 0;
  font-size: 17px;
  color: #0f172a;
}
.srs-proto-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.srs-open-proto-btn {
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
  border-radius: 7px;
  padding: 5px 11px;
  font: 700 12px/1.25 var(--l4-font);
  cursor: pointer;
}
.srs-open-proto-btn:hover {
  background: #1754d6;
  border-color: #1754d6;
  color: #ffffff;
}

/* Markdown Typography & Tables */
.srs-md h3 { font-size: 16px; margin: 18px 0 8px; color: #0f172a; }
.srs-md h4 { font-size: 14.5px; margin: 16px 0 7px; color: #1e3a8a; }
.srs-md h5 { font-size: 13.5px; margin: 12px 0 6px; color: #334155; }
.srs-md p { margin: 0 0 10px; color: #1e293b; line-height: 1.68; }
.srs-md ul, .srs-md ol { margin: 0 0 12px; padding-left: 20px; color: #1e293b; line-height: 1.65; }
.srs-md li + li { margin-top: 4px; }
.srs-md code {
  font-family: var(--l4-mono);
  font-size: 12px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  padding: 1px 5px;
  border-radius: 4px;
  color: #0f172a;
}
.srs-md pre:not(.mm-source) {
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px 14px;
  border-radius: 9px;
  overflow-x: auto;
  font: 12px/1.55 var(--l4-mono);
}
.srs-md pre code { background: transparent; border: 0; color: inherit; padding: 0; }
.srs-md blockquote {
  margin: 10px 0 14px;
  padding: 10px 14px;
  border-left: 4px solid #1754d6;
  background: #f8fafc;
  border-radius: 0 8px 8px 0;
  color: #334155;
}
.srs-table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 10px 0 16px;
}
.srs-md table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  line-height: 1.52;
}
.srs-md th, .srs-md td {
  border: 1px solid #cbd5e1;
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.srs-md th {
  background: #f1f5f9;
  color: #0f172a;
  font-weight: 700;
}
.srs-md tr:nth-child(even) td { background: #fafcff; }

/* Mermaid Diagram Container */
.mermaid {
  margin: 14px 0 18px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  background: #f8fafc;
  overflow: hidden;
}
.mm-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: #f1f5f9;
  border-bottom: 1px solid #e2e8f0;
  font-size: 11.5px;
}
.mm-tag { font-weight: 700; color: #475569; }
.mm-actions { display: flex; gap: 5px; }
.mm-btn {
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #334155;
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}
.mm-stage {
  padding: 16px;
  overflow: auto;
  background: #ffffff;
}
.mm-source {
  margin: 0;
  padding: 12px 14px;
  background: #0f172a;
  color: #e2e8f0;
  font: 12px/1.5 var(--l4-mono);
  overflow-x: auto;
}

mark.l4-hit {
  background: #fde047;
  color: #0f172a;
  padding: 0 2px;
  border-radius: 3px;
}
mark.l4-hit.is-current {
  background: #f97316;
  color: #ffffff;
}

/* Responsive & Print */
@media (max-width: 1100px) {
  .l4-proto-workspace { grid-template-columns: minmax(0, 1fr) 340px; }
  .l4-srs-workspace { grid-template-columns: 240px minmax(0, 1fr); }
  .l4-srs-reader { padding: 20px; }
}

@media (max-width: 820px) {
  .l4-proto-workspace { grid-template-columns: 1fr; grid-template-rows: minmax(420px, 1fr) auto; overflow-y: auto; }
  .l4-spec-rail { border-left: 0; border-top: 1px solid var(--l4-border); }
  .l4-srs-workspace { grid-template-columns: 1fr; }
  .l4-srs-toc { display: none; }
}

@media print {
  .l4-topbar, .l4-proto-toolbar, .l4-srs-toolbar, .l4-srs-toc, #view-proto, .mm-toolbar, .srs-proto-btns {
    display: none !important;
  }
  .l4-shell, #view-srs, .l4-srs-workspace, .l4-srs-reader {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
  }
  .srs-section-card { break-inside: avoid; box-shadow: none; }
}
