/* ── OCIM EIS — Shared base + SADT viewer styles ──────────────────────────── */

:root {
  --bg:        #0d0f18;
  --surface:   #151825;
  --surface2:  #1c2030;
  --border:    #252a3d;
  --accent:    #4f6ef7;
  --accent-d:  #3a55d4;
  --text:      #dde1f5;
  --muted:     #6b7299;
  --c-input:   #34d399;
  --c-output:  #fb923c;
  --c-ctrl:    #facc15;
  --c-mech:    #a78bfa;
  --c-warn:    #f87171;
  --c-badge-draft:    #2a1e06;
  --c-badge-complete: #052a15;
  --c-badge-review:   #06142a;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.logo {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--accent);
}
.header-sep { color: var(--border); }
.header-sub { font-size: 12px; color: var(--muted); }

/* ── SADT breadcrumb nav (class used by both viewer.html and index.html) ─── */
.sadt-nav-bc {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  min-height: 40px;
}
.bc-item {
  color: var(--accent);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background .15s;
}
.bc-item:hover { background: var(--surface2); }
.bc-current { color: var(--text); cursor: default; padding: 2px 6px; }
.bc-sep { color: var(--border); user-select: none; }

/* ── SADT app container (class used by both viewer.html and index.html) ───── */
.sadt-app {
  padding: 28px 24px;
  max-width: 1320px;
  margin: 0 auto;
}

/* ── IDEF0 grid ──────────────────────────────────────────────────────────── */
.idef0 {
  display: grid;
  grid-template-columns: 200px 1fr 200px;
  grid-template-rows: auto auto auto;
  gap: 0;
  margin-bottom: 28px;
}

.idef0-controls { grid-column: 2; grid-row: 1; padding: 0 12px 10px; }
.idef0-inputs   {
  grid-column: 1; grid-row: 2;
  display: flex; flex-direction: column; gap: 8px;
  justify-content: center; align-self: center;
  padding-right: 12px;
}
.idef0-box {
  grid-column: 2; grid-row: 2;
  background: var(--surface);
  border: 1.5px solid var(--accent);
  border-radius: 10px;
  padding: 24px 28px;
  display: flex; flex-direction: column; gap: 10px;
}
.idef0-outputs {
  grid-column: 3; grid-row: 2;
  display: flex; flex-direction: column; gap: 8px;
  justify-content: center; align-self: center;
  padding-left: 12px;
}
.idef0-mechs { grid-column: 2; grid-row: 3; padding: 10px 12px 0; }

/* Function box content */
.box-id {
  font-size: 10px; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--accent);
}
.box-name { font-size: 18px; font-weight: 600; color: #fff; }
.box-desc { font-size: 12px; color: var(--muted); line-height: 1.65; }
.box-meta { display: flex; gap: 6px; flex-wrap: wrap; }

.box-divider { height: 1px; background: var(--border); margin: 6px 0; }
.box-inner-title {
  font-size: 10px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 10px;
}

/* Badges */
.badge {
  font-size: 10px; font-weight: 600;
  padding: 2px 7px; border-radius: 4px;
}
.badge-draft    { background: var(--c-badge-draft);    color: var(--c-ctrl); }
.badge-complete { background: var(--c-badge-complete); color: var(--c-input); }
.badge-review   { background: var(--c-badge-review);   color: var(--accent); }
.badge-meta     { background: var(--surface2); color: var(--muted); }

/* Section labels */
.sec-label {
  font-size: 10px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  margin-bottom: 8px;
}
.sec-label.input    { color: var(--c-input); }
.sec-label.output   { color: var(--c-output); }
.sec-label.control  { color: var(--c-ctrl); }
.sec-label.mech     { color: var(--c-mech); }
.idef0-controls .sec-label,
.idef0-mechs    .sec-label { text-align: center; }

/* Pills */
.pill {
  display: flex; align-items: flex-start; gap: 6px;
  padding: 7px 10px; border-radius: 6px;
  font-size: 11px; font-weight: 500;
  position: relative;
  cursor: default;
}
.pill:hover .pill-tip { opacity: 1; pointer-events: auto; }
.pill.input   { background: #051a0e; border: 1px solid var(--c-input);  color: var(--c-input);  }
.pill.output  { background: #1a0e05; border: 1px solid var(--c-output); color: var(--c-output); }
.pill.control { background: #1a1305; border: 1px solid var(--c-ctrl);   color: var(--c-ctrl);   }
.pill.mech    { background: #110d1a; border: 1px solid var(--c-mech);   color: var(--c-mech);   }

.pill-arrow { flex-shrink: 0; opacity: .7; }
.pill-body  { flex: 1; min-width: 0; }
.pill-name  { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill-sub   { font-size: 10px; opacity: .65; margin-top: 1px; }

/* Tooltip */
.pill-tip {
  opacity: 0;
  pointer-events: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%; transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 11px;
  color: var(--text);
  white-space: normal;
  min-width: 160px; max-width: 260px;
  z-index: 20;
  line-height: 1.5;
  transition: opacity .12s;
}

.pills-row {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
}
.pills-row .pill { flex: 0 1 auto; max-width: 180px; }

/* Connector lines */
.idef0-inputs .pill::after,
.idef0-outputs .pill::before {
  content: '';
  position: absolute;
  top: 50%; width: 12px; height: 1px;
  background: var(--border);
}
.idef0-inputs .pill::after   { right: -12px; }
.idef0-outputs .pill::before { left:  -12px; }

/* Physical flow (dashed) */
.pill.physical { border-style: dashed; opacity: .85; }

/* Process flow — clickable dotted */
.pill.proc-link {
  border-style: dotted;
  cursor: pointer;
  transition: opacity .15s, border-color .15s;
}
.pill.proc-link:hover { opacity: 1; border-style: solid; }

/* Type badge inside pill */
.pill-type-tag {
  display: inline-block;
  font-size: 8px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
  padding: 1px 4px; border-radius: 3px;
  vertical-align: middle; margin-left: 4px;
  opacity: .8;
}
.type-data  { background: #0f1a3a; color: #818cf8; border: 1px solid #3730a3; }
.type-phys  { background: #052a10; color: #34d399; border: 1px solid #065f2a; }
.type-proc  { background: #2a1a05; color: #fbbf24; border: 1px solid #78350f; }

/* Flow group labels */
.flow-group-label {
  font-size: 9px; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted);
  padding: 2px 4px;
  margin-top: 6px;
}
.flow-group-label:first-child { margin-top: 0; }
.flow-group-divider { height: 1px; background: var(--border); margin: 8px 0 6px; }

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 20px;
}
.panel-title {
  font-size: 10px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 14px;
}
.panel-title.warn { color: #fb923c; }

/* Children cards */
.children-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
.child-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
  user-select: none;
}
.child-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}
.child-card:active { transform: translateY(0); }
.child-id    { font-size: 10px; font-weight: 700; color: var(--accent); letter-spacing: .1em; margin-bottom: 5px; }
.child-name  { font-size: 13px; font-weight: 600; color: #fff; margin-bottom: 5px; }
.child-desc  {
  font-size: 11px; color: var(--muted); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.child-status { margin-top: 8px; }
.child-drill  { margin-top: 8px; font-size: 10px; color: var(--accent); }

/* Steps */
.steps-list { display: flex; flex-direction: column; gap: 14px; }
.step { display: flex; gap: 10px; }
.step-num {
  flex-shrink: 0; width: 22px; height: 22px;
  background: var(--accent-d); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: #fff;
  margin-top: 1px;
}
.step-name   { font-size: 13px; font-weight: 600; color: #fff; margin-bottom: 3px; }
.step-action { font-size: 12px; color: var(--muted); line-height: 1.55; margin-bottom: 5px; }
.step-tags   { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.step-tag    {
  font-size: 10px; padding: 2px 6px; border-radius: 4px;
  background: var(--surface2); border: 1px solid var(--border); color: var(--muted);
}
.step-data { font-size: 10px; color: var(--muted); margin-bottom: 4px; }
.step-gap  { font-size: 11px; color: var(--c-warn); }

/* Actors */
.actors-row { display: flex; gap: 10px; flex-wrap: wrap; }
.actor-card {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 14px; font-size: 12px;
}
.actor-name { font-weight: 600; color: #fff; margin-bottom: 3px; }
.actor-role { color: var(--muted); }

/* Open questions */
.questions-list { display: flex; flex-direction: column; gap: 8px; }
.question {
  display: flex; gap: 8px; align-items: flex-start;
  font-size: 12px; color: #fbbf75; line-height: 1.5;
}
.q-icon {
  flex-shrink: 0; width: 16px; height: 16px;
  background: #2a1505; border: 1px solid #fbbf75;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 700; margin-top: 2px;
}

/* Key systems */
.systems-list { display: flex; flex-direction: column; gap: 8px; }
.system-row   { display: flex; gap: 10px; font-size: 12px; }
.system-name  { flex-shrink: 0; font-weight: 600; color: var(--c-mech); min-width: 100px; }
.system-desc  { color: var(--muted); }

/* States */
.loading {
  display: flex; align-items: center; justify-content: center;
  height: 300px; color: var(--muted); gap: 10px; font-size: 14px;
}
.error-box {
  border: 1px solid var(--c-warn); border-radius: 8px;
  padding: 20px 24px; color: var(--c-warn); font-size: 13px; line-height: 1.7;
}
.error-box code {
  background: var(--surface2); padding: 2px 6px; border-radius: 4px; font-family: monospace;
}
.empty   { color: var(--muted); font-size: 12px; font-style: italic; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* Doc-ref pill variant */
.pill.has-doc-ref { cursor: pointer; }
.pill.has-doc-ref:hover { opacity: .85; }
.pill-doc-badge { flex-shrink: 0; font-size: 11px; opacity: .75; margin-left: 2px; }

/* ── Markdown modal ──────────────────────────────────────────────────────── */
.md-modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.75);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.md-modal-overlay.open { display: flex; }
.md-modal-box {
  position: relative;
  width: 92vw; height: 90vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: md-fadein .18s ease;
}
@keyframes md-fadein {
  from { opacity: 0; transform: scale(.97); }
  to   { opacity: 1; transform: scale(1); }
}
.md-modal-close {
  position: absolute; top: 14px; right: 18px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
  padding: 4px 10px;
  cursor: pointer;
  z-index: 1;
  transition: color .12s, border-color .12s;
}
.md-modal-close:hover { color: var(--text); border-color: var(--accent); }
.md-modal-content {
  flex: 1; overflow-y: auto;
  padding: 36px 48px 48px;
  font-size: 13px; line-height: 1.7;
  color: var(--text);
}
.md-modal-content h1 { font-size: 22px; font-weight: 700; color: #fff; margin: 0 0 20px; }
.md-modal-content h2 { font-size: 16px; font-weight: 700; color: #fff; margin: 28px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.md-modal-content h3 { font-size: 14px; font-weight: 600; color: var(--text); margin: 20px 0 8px; }
.md-modal-content p  { margin: 0 0 12px; }
.md-modal-content ul,
.md-modal-content ol { padding-left: 22px; margin: 0 0 12px; }
.md-modal-content li { margin-bottom: 4px; }
.md-modal-content blockquote {
  border-left: 3px solid var(--accent);
  margin: 16px 0; padding: 10px 16px;
  background: var(--surface2);
  border-radius: 0 6px 6px 0;
  color: var(--muted);
}
.md-modal-content code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  background: var(--surface2);
  padding: 1px 5px; border-radius: 4px;
  font-size: 12px; color: var(--c-mech);
}
.md-modal-content pre {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 18px;
  overflow-x: auto;
  margin: 0 0 14px;
}
.md-modal-content pre code { background: none; padding: 0; color: var(--text); }
.md-modal-content table {
  width: 100%; border-collapse: collapse;
  margin: 14px 0; font-size: 12px;
}
.md-modal-content th {
  text-align: left; padding: 7px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted); font-size: 10px;
  text-transform: uppercase; letter-spacing: .08em;
}
.md-modal-content td {
  padding: 7px 12px;
  border: 1px solid var(--border);
  vertical-align: top;
}
.md-modal-content tr:nth-child(even) td { background: var(--surface2); }
.md-modal-content a { color: var(--accent); text-decoration: none; }
.md-modal-content a:hover { text-decoration: underline; }
.md-modal-content hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.md-modal-content > pre:first-child { display: none; }
