:root {
  --bg: #0b1020;
  --text: #e9ecf1;
  --muted: #b6bfd2;
  --accent: #7aa2ff;
  --bad: #ff7a7a;
  --ok: #7affc7;
  --border: rgba(255, 255, 255, 0.12);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica,
    Arial, "Apple Color Emoji", "Segoe UI Emoji";

  /* Resizable layout defaults */
  --topH: 520px; /* height of top region */
  --leftW: 56%; /* width of left top card */
  --minTopH: 300px;
  --maxTopH: 720px;
  --minLeftW: 34%;
  --maxLeftW: 72%;
}

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background: radial-gradient(
      1200px 800px at 20% 10%,
      rgba(122, 162, 255, 0.2),
      transparent 60%
    ),
    radial-gradient(
      1000px 700px at 80% 0%,
      rgba(122, 255, 199, 0.12),
      transparent 60%
    ),
    var(--bg);
  min-height: 100vh;
}

/* Visual indicator for terms with tooltips */
.tooltip-term {
  border-bottom: 1px dotted rgba(122, 162, 255, 0.5);
  cursor: help;
  position: relative;
}

.tooltip-term:hover {
  border-bottom-color: rgba(122, 162, 255, 0.8);
}

/* JavaScript-based smart tooltips that escape overflow */
.smart-tooltip {
  position: fixed;
  left: -9999px !important;
  top: -9999px !important;
  padding: 10px 14px;
  background-color: rgba(15, 23, 42, 0.98);
  color: rgba(233, 236, 241, 1);
  border: 1px solid rgba(122, 162, 255, 0.3);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
  white-space: normal;
  max-width: 320px;
  pointer-events: none;
  z-index: 10000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  text-align: left;
}

.smart-tooltip.positioned {
  animation: tooltipFadeIn 0.5s ease;
  left: var(--tooltip-left) !important;
  top: var(--tooltip-top) !important;
}

@keyframes tooltipFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Wide content for landscape */
header,
.wrap,
.footer {
  width: 85vw;
  max-width: none;
  margin: 0 auto;
}
.footer a {
  color: var(--accent);
  text-decoration: none;
}
header {
  padding: 28px 18px 8px;
}
h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
p.sub {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.4;
  max-width: 92ch;
}

.wrap {
  padding: 14px 18px 34px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

@media (max-width: 980px) {
  header,
  .wrap,
  .footer {
    width: 92vw;
  }
  .wrap {
    grid-template-rows: auto auto;
  }
}

/* TOP: 2 cards + vertical handle */

/* Remove previous resizable top region; frames are stacked vertically */
.topRegion {
  display: none;
}

/* Vertical resize handle */
/* hide legacy resize handles (no longer used) */
.vHandle {
  cursor: col-resize;
  position: relative;
  display: none;
}
.vHandle:after {
  display: none;
}

/* Horizontal resize handle */
.hHandle {
  display: none;
}
.hHandle:after {
  display: none;
}

.card {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.04),
    rgba(255, 255, 255, 0.02)
  );
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Frame-specific styles: collapsed vs expanded */
.frame .hd {
  cursor: pointer;
}
.frame .bd {
  display: block;
  max-height: 600px;
  overflow-y: auto;
}
.frame.collapsed .bd {
  display: none;
}
.frame.collapsed {
  opacity: 0.98;
}
.frame.disabled {
  opacity: 0.6;
  filter: grayscale(10%);
}
.frame.disabled .hd {
  cursor: not-allowed;
}
.frame.disabled .bd {
  display: none;
}
.frame + .frame {
  margin-top: 2px;
}
.card .hd {
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.card .hd .title {
  font-weight: 650;
  font-size: 14px;
  letter-spacing: 0.3px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.pill {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.12);
}
.card .bd {
  padding: 16px;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
input[type="file"] {
  display: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(122, 162, 255, 0.12);
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: transform 0.06s ease, background 0.2s ease, border-color 0.2s ease;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}
.btn:hover {
  background: rgba(122, 162, 255, 0.18);
  border-color: rgba(122, 162, 255, 0.35);
}
.btn:active {
  transform: translateY(1px);
}
.btn.secondary {
  background: rgba(255, 255, 255, 0.06);
}
.btn.danger {
  background: rgba(255, 122, 122, 0.12);
}

.kv {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}
.kv .box {
  background: rgba(0, 0, 0, 0.14);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
}
.kv .k {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.kv .v {
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0.2px;
  word-break: break-word;
}

.note {
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
.warn {
  color: var(--bad);
  font-weight: 600;
}

.scroll {
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
}

table {
  width: auto;
  border-collapse: collapse;
  font-size: 13px;
  display: block;
  max-width: 100%;
}
th,
td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  color: var(--muted);
  font-weight: 650;
  font-size: 12px;
  letter-spacing: 0.25px;
  position: sticky;
  top: 0;
  background: rgba(15, 23, 50, 0.92);
  backdrop-filter: blur(6px);
  z-index: 2;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th .sort {
  margin-left: 6px;
  font-size: 11px;
  opacity: 0.85;
}
th:hover {
  color: #d3daea;
}
tr:hover td {
  background: rgba(122, 162, 255, 0.06);
}

.mono {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.2px;
  background: rgba(255, 255, 255, 0.06);
}
.badge.ok {
  border-color: rgba(122, 255, 199, 0.35);
  background: rgba(122, 255, 199, 0.1);
}
.badge.accent {
  border-color: rgba(122, 162, 255, 0.35);
  background: rgba(122, 162, 255, 0.1);
}

.tiny {
  font-size: 12px;
  color: var(--muted);
}

/* EFA variable list styling for better contrast */
#efaVarList {
  background: transparent; /* keep card background */
  color: var(--text);
  border-radius: 8px;
}
/* EFA variable grid layout */
#efaVarListContainer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
  align-content: flex-start;
}
.efa-var-row {
  color: var(--text);
  padding: 8px 12px !important;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: all 0.15s ease;
}
.efa-var-row:hover {
  background: rgba(122, 162, 255, 0.08);
  border-color: rgba(122, 162, 255, 0.2);
}
.efa-var-row.selected {
  background: rgba(122, 162, 255, 0.25) !important;
  border-color: rgba(122, 162, 255, 0.5) !important;
  color: var(--text) !important;
  font-weight: 600;
}
.search {
  flex: 1 1 260px;
  max-width: 420px;
  min-width: 220px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.12);
  color: var(--text);
  outline: none;
}
.search:focus {
  border-color: rgba(122, 162, 255, 0.55);
}

.footer {
  padding: 10px 18px 26px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

th.num,
td.num {
  text-align: right;
}
th.center,
td.center {
  text-align: center;
}
th.left,
td.left {
  text-align: left;
}

/* Dragging: prevent selection */
.dragging {
  user-select: none !important;
  cursor: grabbing !important;
}

/* Report panel: force an opaque, readable card on the right side */
.reportPanel {
  background: #0f1724 !important;
  border: 1px solid rgba(255, 255, 255, 0.06) !important;
  box-shadow: var(--shadow) !important;
}

/* EFA panel full-height layout when expanded */
.frame#efaCard {
  display: flex;
  flex-direction: column;
}

.frame#efaCard:not(.collapsed) .bd {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.frame#efaCard.collapsed .bd {
  display: none;
}

.frame#efaCard #efaVarList {
  flex: 1 1 auto;
  min-height: 250px;
  max-height: none;
  height: auto;
}
/* CFA panel styling */
.frame#cfaCard:not(.collapsed) .bd {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.frame#cfaCard.collapsed .bd {
  display: none;
}

.cfa-var-item {
  transition: all 0.15s ease;
}

.cfa-var-item:not([style*="pointer-events: none"]):hover {
  background: rgba(122, 180, 255, 0.8) !important;
  transform: translateX(2px);
}

#cfaCanvas {
  cursor: crosshair;
}

.cfa-delete-btn {
  cursor: pointer !important;
}

.cfa-delete-btn * {
  cursor: pointer !important;
}
