:root {
  --bg-page: #020b1f;
  --bg-elevated: #0a1c3d;
  --bg-soft: #102a54;
  --bg-soft-2: #0d2247;
  --text-primary: #eaf2ff;
  --text-secondary: #b8c9e8;
  --text-muted: #8ea7cf;
  --primary: #4b8dff;
  --primary-hover: #6aa3ff;
  --accent: #39d0ff;
  --success: #27d59b;
  --danger: #ff6b81;
  --warning: #f6b14f;
  --border: rgba(138, 169, 226, 0.3);
  --ring: rgba(75, 141, 255, 0.35);
  --shadow-card: 0 18px 40px rgba(2, 8, 22, 0.44);
  --shadow-button: 0 10px 24px rgba(39, 110, 255, 0.35);
  --page-radial-a: #123166;
  --page-radial-b: #173978;
  --page-gradient-start: #02091b;
  --page-gradient-mid: #071734;
  --page-gradient-end: #041127;
  --orb-a: #1d66ff;
  --orb-b: #1ab4d8;
  --panel-padding: 14px;
  --shell-gap: 10px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --workspace-form-width: 58%;
  --workspace-divider-size: 10px;
  --workspace-form-min: 380px;
  --workspace-result-min: 340px;
}

:root[data-style-preset="mission-console"] {
  --bg-page: #020b1f;
}

:root[data-style-preset="data-lab"] {
  --bg-page: #04140f;
  --bg-elevated: #0b281f;
  --bg-soft: #12382d;
  --bg-soft-2: #0d3029;
  --text-primary: #effff8;
  --text-secondary: #b8dfd1;
  --text-muted: #8fbdaa;
  --primary: #22c58b;
  --primary-hover: #42d7a1;
  --accent: #8ee6ff;
  --success: #55df9a;
  --border: rgba(139, 220, 190, 0.3);
  --ring: rgba(34, 197, 139, 0.34);
  --shadow-button: 0 10px 24px rgba(34, 197, 139, 0.28);
  --page-radial-a: #0e4b35;
  --page-radial-b: #0f5164;
  --page-gradient-start: #03110d;
  --page-gradient-mid: #07231d;
  --page-gradient-end: #041716;
  --orb-a: #19b883;
  --orb-b: #33c8df;
}

:root[data-style-preset="compact-industrial"] {
  --bg-page: #090d12;
  --bg-elevated: #111923;
  --bg-soft: #1a2633;
  --bg-soft-2: #141f2b;
  --text-primary: #f4f7fb;
  --text-secondary: #bdc9d8;
  --text-muted: #8795a7;
  --primary: #d5a449;
  --primary-hover: #e5b95f;
  --accent: #74d7ff;
  --border: rgba(174, 188, 204, 0.28);
  --ring: rgba(213, 164, 73, 0.34);
  --shadow-card: 0 12px 24px rgba(1, 5, 12, 0.46);
  --shadow-button: 0 8px 18px rgba(213, 164, 73, 0.22);
  --page-radial-a: #2b3543;
  --page-radial-b: #4d3819;
  --page-gradient-start: #070a0f;
  --page-gradient-mid: #101720;
  --page-gradient-end: #090d12;
  --orb-a: #9a762e;
  --orb-b: #30718a;
  --panel-padding: 10px;
  --shell-gap: 6px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
}

:root[data-style-preset="presentation"] {
  --bg-page: #071126;
  --bg-elevated: #101e3d;
  --bg-soft: #1c315b;
  --bg-soft-2: #16284d;
  --text-primary: #f4f8ff;
  --text-secondary: #c6d6f1;
  --text-muted: #9aadd0;
  --primary: #8c7dff;
  --primary-hover: #a69aff;
  --accent: #ffd36b;
  --border: rgba(176, 188, 247, 0.32);
  --ring: rgba(140, 125, 255, 0.36);
  --shadow-card: 0 24px 52px rgba(4, 12, 31, 0.5);
  --shadow-button: 0 12px 28px rgba(140, 125, 255, 0.32);
  --page-radial-a: #2e3f8d;
  --page-radial-b: #5d386f;
  --page-gradient-start: #061024;
  --page-gradient-mid: #111f42;
  --page-gradient-end: #07152e;
  --orb-a: #7568f5;
  --orb-b: #d0a246;
  --panel-padding: 18px;
  --radius-lg: 18px;
}

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

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  color: var(--text-primary);
  font-family: "IBM Plex Sans", "Noto Sans SC", sans-serif;
  background: radial-gradient(circle at 12% 10%, var(--page-radial-a) 0%, transparent 32%),
    radial-gradient(circle at 88% 84%, var(--page-radial-b) 0%, transparent 36%),
    linear-gradient(160deg, var(--page-gradient-start) 0%, var(--page-gradient-mid) 52%, var(--page-gradient-end) 100%);
  min-width: 360px;
  overflow: hidden;
}

.bg-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(60px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.35;
}

.orb-a {
  width: 360px;
  height: 360px;
  top: -120px;
  right: -80px;
  background: radial-gradient(circle at 35% 35%, var(--orb-a), transparent 70%);
}

.orb-b {
  width: 320px;
  height: 320px;
  bottom: -110px;
  left: -90px;
  background: radial-gradient(circle at 50% 50%, var(--orb-b), transparent 72%);
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1880px, calc(100vw - 24px));
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: 10px 12px 8px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: var(--shell-gap);
}

body.is-resizing {
  cursor: col-resize;
  user-select: none;
}

.card {
  background: linear-gradient(160deg, rgba(11, 31, 67, 0.88) 0%, rgba(7, 22, 50, 0.94) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  animation: enter-up 220ms ease-out;
  backdrop-filter: blur(2px);
}

.hero {
  padding: 14px 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 0 7px;
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.2;
  font-weight: 600;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.meta-tag {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(11, 39, 83, 0.8);
  color: var(--text-secondary);
  font-size: 12px;
  font-family: "JetBrains Mono", "SFMono-Regular", monospace;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(var(--workspace-form-min), var(--workspace-form-width)) var(
      --workspace-divider-size
    ) minmax(var(--workspace-result-min), 1fr);
  gap: 0;
  min-height: 0;
  overflow: hidden;
}

.panel {
  padding: var(--panel-padding);
  min-height: 0;
  overflow: hidden;
}

.form-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 8px;
}

.result-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 8px;
}

.workspace-splitter {
  position: relative;
  border-radius: 999px;
  margin: 8px 1px;
  background: linear-gradient(
    180deg,
    rgba(95, 136, 211, 0.16) 0%,
    rgba(48, 96, 182, 0.38) 48%,
    rgba(95, 136, 211, 0.16) 100%
  );
  cursor: col-resize;
  touch-action: none;
  transition: background-color 140ms ease;
}

.workspace-splitter::before {
  content: "";
  position: absolute;
  inset: 50% 2px auto;
  height: 42px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(91, 143, 255, 0.9) 0%, rgba(50, 196, 255, 0.82) 100%);
  box-shadow: 0 0 10px rgba(67, 144, 255, 0.45);
}

.workspace-splitter:hover,
.workspace-splitter:focus-visible,
body.is-resizing .workspace-splitter {
  background: linear-gradient(
    180deg,
    rgba(95, 136, 211, 0.24) 0%,
    rgba(69, 130, 241, 0.64) 48%,
    rgba(95, 136, 211, 0.24) 100%
  );
}

.workspace-splitter:focus-visible {
  outline: 2px solid rgba(82, 149, 255, 0.85);
  outline-offset: 1px;
}

h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.3;
  font-weight: 600;
}

h3 {
  margin: 0 0 8px;
  font-size: 16px;
  line-height: 1.3;
  font-weight: 600;
}

.panel-desc {
  margin: 0;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.5;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  align-content: start;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.field-item {
  display: grid;
  gap: 5px;
  align-content: start;
  background: rgba(15, 41, 85, 0.62);
  border: 1px solid rgba(123, 162, 230, 0.25);
  border-radius: var(--radius-md);
  padding: 10px;
}

.field-label {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
}

.field-help {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.35;
}

.field-input {
  width: 100%;
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(129, 164, 225, 0.4);
  background: #081a3b;
  color: var(--text-primary);
  font-size: 14px;
  padding: 0 11px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

textarea.field-input {
  min-height: 84px;
  max-height: 160px;
  padding: 10px 11px;
  resize: vertical;
}

.field-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--ring);
}

.field-error {
  color: #ff9cab;
  font-size: 12px;
  min-height: 16px;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid rgba(137, 169, 226, 0.24);
  padding-top: 10px;
}

.primary-btn {
  height: 42px;
  min-width: 126px;
  border: 0;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #3279ff 0%, #4a95ff 100%);
  color: #f8fbff;
  font-size: 15px;
  font-weight: 600;
  padding: 0 18px;
  cursor: pointer;
  transition: filter 160ms ease, transform 160ms ease, box-shadow 160ms ease;
  box-shadow: var(--shadow-button);
}

.primary-btn:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.primary-btn:disabled {
  background: #4b5f88;
  box-shadow: none;
  cursor: not-allowed;
}

.hint-text {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
  text-align: right;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  border: 1px solid transparent;
  width: fit-content;
}

.status-badge.idle {
  color: var(--text-secondary);
  background: rgba(84, 116, 177, 0.24);
  border-color: rgba(145, 177, 234, 0.3);
}

.status-badge.running {
  color: #d6e6ff;
  background: rgba(51, 111, 255, 0.34);
  border-color: rgba(115, 161, 255, 0.55);
}

.status-badge.success {
  color: #b6f7dc;
  background: rgba(29, 145, 104, 0.35);
  border-color: rgba(61, 219, 161, 0.45);
}

.status-badge.error {
  color: #ffd6dc;
  background: rgba(175, 40, 80, 0.34);
  border-color: rgba(255, 123, 153, 0.5);
}

.result-grid {
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  min-height: 0;
  overflow: hidden;
}

.result-block {
  border: 1px solid rgba(123, 157, 222, 0.24);
  border-radius: var(--radius-md);
  background: rgba(11, 33, 70, 0.7);
  padding: 10px;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
}

.result-kv {
  display: grid;
  gap: 7px;
  align-content: start;
  overflow: auto;
  min-height: 0;
}

.result-kv.empty {
  color: var(--text-muted);
  font-size: 14px;
}

.result-row {
  display: grid;
  grid-template-columns: minmax(110px, 34%) 1fr;
  gap: 8px;
  align-items: start;
}

.result-key {
  color: var(--text-secondary);
  font-size: 13px;
}

.result-value {
  color: var(--text-primary);
  font-size: 13px;
  font-family: "JetBrains Mono", "SFMono-Regular", monospace;
  word-break: break-word;
}

.code-block {
  margin: 0;
  border: 1px solid rgba(111, 149, 216, 0.3);
  border-radius: var(--radius-sm);
  background: #030f24;
  color: #cbe1ff;
  padding: 10px;
  font-size: 12px;
  line-height: 1.55;
  font-family: "JetBrains Mono", "SFMono-Regular", monospace;
  overflow: auto;
  min-height: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.usage-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  max-height: 160px;
}

.usage-list {
  margin: 0;
  padding-left: 20px;
  color: var(--text-secondary);
  line-height: 1.55;
  font-size: 13px;
  overflow: auto;
}

.usage-note {
  margin: 0;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: rgba(14, 48, 98, 0.75);
  border: 1px solid rgba(132, 170, 234, 0.3);
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.5;
}

.app-footer {
  text-align: center;
  color: #88a3cf;
  font-size: 12px;
  line-height: 1.3;
  padding-bottom: 2px;
}

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

@media (max-width: 1280px) {
  :root {
    --workspace-form-min: 340px;
    --workspace-result-min: 300px;
  }

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

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .app-shell {
    width: calc(100vw - 8px);
    height: auto;
    min-height: 100vh;
    grid-template-rows: auto auto auto auto;
    padding: 8px 4px 12px;
  }

  .hero {
    padding: 12px;
    flex-direction: column;
  }

  h1 {
    font-size: 24px;
  }

  .workspace {
    grid-template-columns: 1fr;
    gap: 8px;
    overflow: visible;
  }

  .form-panel,
  .result-panel,
  .usage-panel {
    max-height: none;
  }

  .field-grid {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .result-grid {
    grid-template-rows: auto auto;
  }

  .workspace-splitter {
    display: none;
  }

  .usage-list,
  .result-kv,
  .code-block {
    overflow: visible;
  }

  .actions {
    flex-direction: column;
    align-items: stretch;
  }

  .hint-text {
    text-align: left;
  }
}

/* ── Result Table ── */
.result-table-block {
  grid-column: 1 / -1;
}

.result-table-heading {
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.result-table thead th {
  color: var(--text-secondary);
  font-weight: 500;
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid rgba(138, 169, 226, 0.35);
  background: rgba(14, 42, 85, 0.6);
  position: sticky;
  top: 0;
}

.result-table tbody td {
  color: var(--text-primary);
  padding: 5px 10px;
  border-bottom: 1px solid rgba(138, 169, 226, 0.15);
  font-family: "JetBrains Mono", "SFMono-Regular", monospace;
  font-size: 11.5px;
}

.result-table tbody tr:hover {
  background: rgba(75, 141, 255, 0.08);
}

.result-table-wrapper {
  max-height: 300px;
  overflow: auto;
}
