:root {
  --bg: radial-gradient(1200px 600px at 0% 0%, #eef4fb 0%, #e4ebf4 52%, #dfe7f0 100%);
  --panel: #ffffff;
  --panel-soft: #f7f9fc;
  --line: #d3dbe7;
  --line-soft: #e8edf4;
  --ink: #162030;
  --muted: #607185;
  --accent: #2468c7;
  --accent-soft: rgba(36, 104, 199, 0.12);
  --success: #1f7a54;
  --success-soft: rgba(31, 122, 84, 0.12);
  --danger: #b64f43;
  --danger-soft: rgba(182, 79, 67, 0.13);
  --brand-grad: linear-gradient(180deg, #2f79d8 0%, #225aa7 100%);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --motion-fast: 140ms cubic-bezier(.22,.61,.36,1);
  --motion-normal: 220ms cubic-bezier(.22,.61,.36,1);
  --shadow: 0 14px 34px rgba(19, 35, 52, 0.09);
  --shadow-strong: 0 20px 42px rgba(15, 29, 47, 0.17);
  --mono: "SFMono-Regular", "Menlo", "Monaco", "Consolas", monospace;
  --sans: "Avenir Next", "SF Pro Text", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --drawer-width: 420px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
}

button,
input,
textarea {
  font: inherit;
}

body {
  min-height: 100vh;
}

.app-shell {
  position: relative;
  height: 100vh;
  overflow: hidden;
}

.workspace-shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
  padding: 12px 14px;
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

.tab-strip {
  display: flex;
  gap: 8px;
  align-items: end;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 8px 11px;
  font-size: 0.98rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  position: relative;
  cursor: pointer;
  transition: color var(--motion-fast), transform var(--motion-fast);
}

.toolbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.tab.active,
.tab.admin-launch {
  color: var(--ink);
}

.tab.active::after,
.tab.admin-launch::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 0;
  height: 3px;
  border-radius: 999px;
}

.tab.active::after {
  background: var(--accent);
}

.tab.admin-launch::after {
  background: rgba(47, 118, 209, 0.34);
}

.tab.admin-launch {
  border: 1px solid rgba(36, 104, 199, 0.3);
  border-radius: 12px;
  padding: 7px 11px 9px;
  background: linear-gradient(180deg, #ffffff 0%, #edf4ff 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.92), 0 8px 20px rgba(30, 73, 129, 0.13);
  font-weight: 600;
}

.tab.admin-launch:hover {
  transform: translateY(-1px);
}

.endpoint-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 8px 10px;
  border-radius: 12px;
}

.endpoint-input {
  border: 0;
  outline: none;
  background: transparent;
  min-width: 0;
  font-size: 1rem;
}

.icon-button,
.icon-action,
.chip,
.drawer-close,
.audit-event {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: all var(--motion-fast);
}

.summary-cta,
.query-ghost {
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.summary-cta {
  background: var(--brand-grad);
  color: #fff;
  border-color: #1e4f92;
  box-shadow: 0 10px 24px rgba(34, 90, 167, 0.33);
}

.summary-cta:hover {
  filter: brightness(1.04);
  transform: translateY(-1px);
}

.summary-cta-icon {
  font-size: 1.05rem;
  opacity: 0.95;
}

.summary-cta:disabled,
.query-ghost:disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

.query-ghost {
  background: #f3f5f8;
  color: #7b8695;
  border-color: #d8dee8;
  min-width: 108px;
}

.query-ghost:not(:disabled):hover {
  transform: translateY(-1px);
  border-color: #bbc8da;
}

.mini-tool,
.mini-select {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 6px 9px;
  border-radius: 8px;
  font-size: 0.85rem;
}

.mini-tool {
  cursor: pointer;
}

.mini-tool:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(180deg, #ffffff 0%, #f2f5fa 100%);
}

.icon-button:hover {
  border-color: #b7c3d4;
  transform: translateY(-1px);
}

.icon-action {
  width: 44px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  background: linear-gradient(180deg, #4f5a66 0%, #3f4955 100%);
  color: #fff;
  border-color: #3f4955;
  font-size: 1.15rem;
  border-radius: 10px;
}

.icon-action.secondary {
  background: linear-gradient(180deg, #637282 0%, #55626f 100%);
  border-color: #515f6d;
}

.icon-button:disabled,
.icon-action:disabled {
  opacity: 0.6;
  cursor: wait;
}

.workbench {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 48%) minmax(0, 52%);
  gap: 12px;
}

.editor-frame,
.results-shell {
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.editor-status,
.panel-toolbar,
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.drawer-header {
  background: linear-gradient(180deg, #ffffff 0%, #f2f6fc 100%);
  border-top-right-radius: var(--radius-lg);
  box-shadow: inset 0 -1px 0 rgba(212, 221, 232, 0.8);
}

.drawer-header strong {
  letter-spacing: 0.01em;
}

.status-meta {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 2px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 7px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.88rem;
  background: var(--accent-soft);
  color: var(--accent);
}

.status-pill.ready {
  background: var(--success-soft);
  color: var(--success);
}

.status-pill.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.status-pill.busy {
  background: var(--accent-soft);
  color: var(--accent);
}

.text-editor {
  min-height: 0;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
}

.line-gutter {
  background: #f8f9fb;
  border-right: 1px solid var(--line);
  color: #9aa5b3;
  font-family: var(--mono);
  font-size: 0.92rem;
  line-height: 1.65;
  padding: 12px 8px 12px 0;
  text-align: right;
  overflow: hidden;
  user-select: none;
}

.line-gutter div {
  height: 1.65em;
}

textarea {
  border: 0;
  outline: none;
  resize: none;
  width: 100%;
  height: 100%;
  padding: 12px 14px;
  background: #fff;
  font-family: var(--mono);
  font-size: 0.95rem;
  line-height: 1.65;
  color: #3c146e;
  white-space: pre;
  overflow: auto;
}

.tabs-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
}

.chip {
  padding: 7px 10px;
  background: linear-gradient(180deg, #ffffff 0%, #f4f7fb 100%);
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  font-weight: 600;
  color: #4e6075;
  transition: all 120ms ease;
}

.chip.active {
  border-color: rgba(36, 104, 199, 0.34);
  background: var(--accent-soft);
  color: #1f4f94;
}

.chip:hover {
  transform: translateY(-1px);
  border-color: #bfcbdb;
}

.chip-response.active,
.chip-jarLog.active {
  background: rgba(41, 84, 132, 0.12);
  border-color: rgba(41, 84, 132, 0.35);
}

.chip-legacy.active,
.chip-rewritten.active {
  background: rgba(36, 78, 161, 0.12);
  border-color: rgba(36, 78, 161, 0.35);
}

.chip-summaryResults.active,
.chip-storedSummary.active,
.chip-table.active {
  background: rgba(26, 122, 84, 0.11);
  border-color: rgba(26, 122, 84, 0.35);
}

.panel,
.admin-panel {
  min-height: 0;
  display: none;
  flex: 1 1 auto;
  overflow: hidden;
}

.panel.active,
.admin-panel.active {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  animation: panel-in var(--motion-normal);
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-meta {
  color: var(--muted);
  font-size: 0.88rem;
}

#tableFilter {
  width: 240px;
  max-width: 100%;
  border: 1px solid var(--line);
  padding: 8px 10px;
  background: #fff;
}

.table-wrap,
.code-view,
.drawer-scroll {
  min-height: 0;
  overflow: auto;
}

.table-wrap {
  flex: 1 1 auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

thead th {
  position: sticky;
  top: 0;
  background: #fafbfc;
  z-index: 1;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: top;
}

td {
  word-break: break-word;
}

.empty {
  color: var(--muted);
}

.code-mode {
  color: var(--muted);
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.code-view {
  background: #fcfcfd;
  flex: 1 1 auto;
}

.code-view.compact {
  min-height: 0;
  overflow: auto;
}

.code-grid {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
}

.code-line-no {
  padding: 2px 8px 2px 0;
  text-align: right;
  color: #9aa5b3;
  border-right: 1px solid var(--line-soft);
  font-family: var(--mono);
  font-size: 0.9rem;
  line-height: 1.6;
  user-select: none;
}

.code-line-text {
  padding: 2px 14px;
  font-family: var(--mono);
  font-size: 0.9rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.tok-keyword {
  color: #6e2db8;
  font-weight: 600;
}

.tok-iri {
  color: #0e7a4f;
}

.tok-var {
  color: #1e53be;
}

.tok-string {
  color: #b46512;
}

.tok-key {
  color: #1452b8;
  font-weight: 600;
}

.tok-number {
  color: #9f4f06;
}

.tok-qname {
  color: #6d2dac;
}

.tok-punct {
  color: #4b5765;
}

.tok-comment {
  color: #7a8796;
  font-style: italic;
}

.admin-drawer {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 40;
  width: min(var(--drawer-width), calc(100vw - 24px));
  height: 100%;
  background: linear-gradient(180deg, #fdfefe 0%, #f7f9fc 100%);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow-strong);
  border-top-right-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
  transform: translateX(calc(-100% - 12px));
  transition: transform var(--motion-normal);
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.admin-drawer.open {
  transform: translateX(0);
}

.drawer-resizer {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 5;
}

.drawer-resizer:hover {
  background: rgba(36, 104, 199, 0.2);
}

.drawer-close {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  font-size: 1.4rem;
  line-height: 1;
  border-radius: 10px;
  background: #eef3f9;
  border-color: #d6deea;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  z-index: 30;
  border: 0;
  background: rgba(21, 31, 45, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.drawer-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

.drawer-body {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: #f8fafd;
}

.drawer-section {
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

#adminTabs {
  background: linear-gradient(180deg, #f2f6fb 0%, #edf2f8 100%);
  border-bottom: 1px solid #d9e2ef;
  padding: 8px;
  gap: 6px;
}

.admin-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
}

#adminTabs .chip {
  border-radius: 12px;
  padding: 8px 10px;
  background: #ffffff;
  border-color: #d4dce8;
  color: #4f6073;
  font-weight: 600;
  min-height: 36px;
}

#adminTabs .chip.active {
  background: var(--brand-grad);
  border-color: #225394;
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(34, 90, 167, 0.3);
  transform: translateY(-1px);
}

.admin-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  letter-spacing: 0.01em;
}

.admin-chip-icon {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.74rem;
  background: rgba(37, 62, 92, 0.08);
  color: #4a5f77;
}

#adminTabs .chip.active .admin-chip-icon {
  background: rgba(255, 255, 255, 0.24);
  color: #ffffff;
}

.admin-chip-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#rawPanel {
  height: 100%;
  min-height: 0;
  display: none;
  flex-direction: column;
}

#rawPanel.active {
  display: grid;
  grid-template-rows: minmax(0, 58%) minmax(0, 42%);
}

.raw-editor {
  min-height: 0;
}

.graph-canvas {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-height: 320px;
  background: linear-gradient(180deg, #fbfcfd 0%, #f5f7fa 100%);
}

#graphPanel.graph-fullscreen {
  position: fixed;
  inset: 16px;
  z-index: 120;
  background: #ffffff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-strong);
}

#metadataPanel.active,
#graphPanel.active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.graph-placeholder {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.92rem;
  padding: 20px;
  text-align: center;
}

.capabilities {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 12px 0;
}

.cap {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.82rem;
  background: var(--danger-soft);
  color: var(--danger);
}

.cap.ok {
  background: var(--success-soft);
  color: var(--success);
}

.suggestion-block {
  padding: 12px;
  border-top: 1px solid var(--line-soft);
}

.suggestion-block strong {
  display: block;
  margin-bottom: 6px;
}

.suggestion-block ul {
  margin: 0;
  padding-left: 16px;
  color: var(--muted);
  font-size: 0.88rem;
}

.suggestion-block li {
  margin-bottom: 4px;
}

.diag {
  margin: 12px 12px 0;
  padding: 7px 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.86rem;
}

.audit-layout {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 34%) minmax(0, 33%) minmax(0, 33%);
}

.audit-timeline-wrap {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.audit-timeline {
  min-height: 0;
  overflow: auto;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.audit-pane {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.audit-event {
  text-align: left;
  padding: 10px;
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  border-color: #d4deeb;
}

.audit-event.selected {
  border-color: rgba(47, 118, 209, 0.4);
  background: var(--accent-soft);
}

.audit-event.rejected {
  border-color: rgba(182, 79, 67, 0.28);
}

.audit-event.accepted,
.audit-event.generated,
.audit-event.compiled,
.audit-event.ok {
  border-color: rgba(31, 122, 84, 0.25);
}

.audit-event-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.audit-event-body {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.88rem;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 12px;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 10px;
  border-top: 1px solid var(--line-soft);
  background: #f8fbfe;
}

.metadata-view {
  min-height: 0;
  height: 100%;
  flex: 1 1 auto;
  overflow: auto;
}

#metadataCode .code-grid {
  min-width: max-content;
}

body.resizing,
body.resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

@media (max-width: 980px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .endpoint-row {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
  }

  .workspace-shell {
    padding: 10px;
  }
}
