:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --sidebar: #20242a;
  --sidebar-line: #343b45;
  --line: #d7dce2;
  --ink: #1e242c;
  --muted: #66717f;
  --green: #168557;
  --blue: #1d6fb8;
  --red: #b5413b;
  --amber: #a76705;
  --purple: #7a4db3;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

button,
.button,
input,
select,
textarea {
  font: inherit;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

button:hover,
.button:hover {
  border-color: #9ba8b5;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button.primary,
.button.primary {
  border-color: #176345;
  background: #176345;
  color: #fff;
}

button.ghost,
.button.ghost {
  background: transparent;
}

button.danger,
.button.danger {
  border-color: rgba(181, 65, 59, 0.45);
  color: var(--red);
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  width: 256px;
  padding: 18px;
  background: var(--sidebar);
  color: #f7fafc;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 52px;
  margin-bottom: 22px;
}

.brand img {
  width: 42px;
  height: 42px;
  object-fit: contain;
}

.brand div,
.connection {
  display: grid;
  gap: 3px;
}

.brand span,
.connection span,
.connection small {
  color: #aeb8c4;
}

nav {
  display: grid;
  gap: 4px;
}

nav a {
  padding: 10px 11px;
  border-radius: 7px;
  color: #dbe3ec;
  text-decoration: none;
}

nav a:hover,
nav a.active {
  background: #303740;
  color: #fff;
  text-decoration: none;
}

.connection {
  margin-top: auto;
  padding: 13px;
  border: 1px solid var(--sidebar-line);
  border-radius: 7px;
  background: #292f37;
}

.auth-box {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 13px;
  border: 1px solid var(--sidebar-line);
  border-radius: 7px;
  background: #292f37;
}

.auth-box div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.auth-box small {
  overflow: hidden;
  color: #aeb8c4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-box button {
  width: 100%;
  background: transparent;
  color: #f7fafc;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-panel {
  display: grid;
  gap: 18px;
  width: min(100%, 420px);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: 0 18px 42px rgba(25, 32, 40, 0.12);
}

.login-brand {
  margin-bottom: 0;
  color: var(--ink);
}

.login-brand span {
  color: var(--muted);
}

.workspace {
  margin-left: 256px;
  padding: 24px;
}

body[data-page="task-new"] {
  overflow: hidden;
}

body[data-page="task-new"] .workspace {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100vh;
  min-height: 0;
  padding: 18px 20px 92px;
  overflow: hidden;
}

body[data-page="task-new"] .topbar,
body[data-page="task-new"] .wizard-steps {
  flex: 0 0 auto;
  margin-bottom: 0;
}

body[data-page="task-new"] #newTaskForm {
  display: grid;
  flex: 1 1 auto;
  min-height: 0;
}

body[data-page="task-new"] .wizard-panel.active {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

body[data-page="task-new"] .wizard-panel > .table-wrap,
body[data-page="task-new"] .columns-editor {
  min-height: 0;
  overflow: hidden;
}

body[data-page="task-new"] .columns-editor .table-wrap {
  flex: 1 1 auto;
  max-height: calc(100vh - 306px);
  border: 1px solid var(--line);
  border-radius: 7px;
}

body[data-page="task-new"] .columns-editor .table-wrap table {
  min-width: 1180px;
}

body[data-page="task-new"] .columns-editor th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel-soft);
}

body[data-page="task-new"] .code-area {
  flex: 1 1 auto;
  min-height: 0;
  resize: none;
}

body[data-page="task-new"] .wizard-run-grid {
  flex: 1 1 auto;
}

body[data-page="task-new"] .result-area {
  flex: 1 1 auto;
}

body[data-page="task-new"] .wizard-footer {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 256px;
  z-index: 20;
  min-height: 64px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  background: rgba(244, 246, 248, 0.96);
  backdrop-filter: blur(8px);
}

.topbar,
.panel-header,
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar {
  margin-bottom: 18px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 1.65rem;
  line-height: 1.15;
}

h2 {
  font-size: 1rem;
}

.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.kpis,
.grid,
.form-grid {
  display: grid;
  gap: 14px;
}

.kpis {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 14px;
}

.kpis.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.grid.two,
.form-grid {
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.8fr);
  margin-bottom: 14px;
}

.span-wide {
  grid-column: 1 / -1;
}

.compact-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.kpis article,
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: 0 10px 28px rgba(25, 32, 40, 0.06);
}

.kpis article {
  display: grid;
  gap: 7px;
  padding: 15px;
}

.kpis article span,
small {
  color: var(--muted);
}

.kpis strong {
  font-size: 1.65rem;
}

.panel {
  padding: 15px;
}

.panel-header {
  margin-bottom: 12px;
}

.wizard-steps {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.wizard-steps button {
  justify-content: flex-start;
  background: #eef2f6;
  color: var(--muted);
}

.wizard-steps button.active {
  border-color: var(--blue);
  background: rgba(29, 111, 184, 0.12);
  color: var(--blue);
}

.wizard-steps button:disabled {
  opacity: 0.45;
}

.wizard-panel {
  display: none;
}

.wizard-panel.active {
  display: block;
}

.columns-editor input,
.columns-editor select {
  min-width: 180px;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow: auto;
  scrollbar-gutter: stable;
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

tr:hover td {
  background: #fbfcfd;
}

label,
.stacked-form {
  display: grid;
  gap: 7px;
}

.stacked-form {
  gap: 11px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}

textarea {
  padding: 10px;
  resize: vertical;
}

.code-area,
.json-box,
.logs-box {
  font-family: "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  font-size: 0.84rem;
}

.code-area {
  min-height: 300px;
  background: #111820;
  color: #edf5ff;
  border-color: #283544;
}

.json-box,
.logs-box {
  max-height: 380px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border-radius: 7px;
  background: #111820;
  color: #edf5ff;
}

.logs-box p {
  margin: 3px 0;
}

.log-row {
  margin-bottom: 10px;
  padding-bottom: 9px;
  border-bottom: 1px solid #263342;
}

.log-row span {
  color: #9be2c2;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: #e8edf2;
  color: #44505d;
  font-size: 0.76rem;
  font-weight: 700;
}

.badge.succeeded,
.badge.valid,
.badge.enabled {
  background: rgba(22, 133, 87, 0.12);
  color: var(--green);
}

.badge.running,
.badge.queued,
.badge.untested {
  background: rgba(29, 111, 184, 0.12);
  color: var(--blue);
}

.badge.failed,
.badge.invalid {
  background: rgba(181, 65, 59, 0.12);
  color: var(--red);
}

.badge.disabled,
.badge.never {
  background: #e8edf2;
  color: var(--muted);
}

.event-list,
.dataset-list,
.dataset-grid {
  display: grid;
  gap: 10px;
}

.dataset-grid {
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.event-item,
.dataset-card,
.dataset-item {
  display: grid;
  gap: 5px;
  width: 100%;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
  color: var(--ink);
  text-align: left;
  text-decoration: none;
}

.event-item:hover,
.dataset-card:hover,
.dataset-item:hover {
  border-color: #9ba8b5;
  text-decoration: none;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.script-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  min-width: 0;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  width: auto;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}

.upload-button:hover {
  border-color: #9ba8b5;
}

.file-name {
  max-width: 260px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.86rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-field {
  max-width: 120px;
  color: var(--muted);
  font-size: 0.82rem;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.check-row input {
  width: auto;
  min-height: auto;
}

.field-label {
  display: block;
  margin-bottom: 7px;
}

.role-options {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
}

.role-options .check-row {
  align-items: flex-start;
  justify-content: space-between;
  padding: 8px;
  border-radius: 7px;
  background: #fff;
}

.inline-message {
  min-height: 22px;
  color: var(--muted);
}

.wizard-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.wizard-run-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(380px, 0.95fr);
  gap: 14px;
  min-height: 0;
}

.script-editor-pane,
.run-output-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.run-output-pane {
  gap: 10px;
}

.run-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.run-summary span {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
}

.run-summary strong {
  font-size: 1.15rem;
}

.execution-console {
  min-height: 118px;
  max-height: 170px;
  overflow: auto;
  padding: 10px;
  border-radius: 7px;
  background: #111820;
  color: #edf5ff;
  font-family: "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
}

.console-line {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 8px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.console-line span {
  color: #9be2c2;
  font-weight: 700;
}

.console-line.error span {
  color: #ffafa8;
}

.console-line.warning span {
  color: #ffd88a;
}

.console-line p,
.console-line small {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.console-line small {
  grid-column: 2;
  color: #91a0b1;
}

.result-area {
  min-height: 0;
  overflow: hidden;
}

.data-preview-wrap {
  max-height: min(310px, 34vh);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.sample-value {
  display: inline-block;
  max-width: 320px;
  overflow: hidden;
  color: #394555;
  text-overflow: ellipsis;
  vertical-align: bottom;
  white-space: nowrap;
}

.panel-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 12px;
}

.split-output {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.8fr);
  gap: 12px;
}

.data-table-empty,
.fatal-error {
  padding: 13px;
  border: 1px dashed var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
  color: var(--muted);
}

.fatal-error {
  margin-bottom: 14px;
  border-color: rgba(181, 65, 59, 0.35);
  color: var(--red);
}

hr {
  width: 100%;
  border: 0;
  border-top: 1px solid var(--line);
  margin: 14px 0;
}

@media (max-width: 1060px) {
  .sidebar {
    position: static;
    width: auto;
  }

  .workspace {
    margin-left: 0;
  }

  body[data-page="task-new"] .workspace {
    margin-left: 0;
  }

  body[data-page="task-new"] .wizard-footer {
    left: 0;
  }

  .connection {
    margin-top: 18px;
  }

  .kpis,
  .kpis.compact,
  .grid.two,
  .form-grid,
  .compact-grid,
  .split-output {
    grid-template-columns: 1fr 1fr;
  }

  .wizard-run-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  body[data-page="task-new"] {
    overflow: auto;
  }

  body[data-page="task-new"] .workspace {
    height: auto;
    min-height: 100vh;
    overflow: visible;
    padding: 16px 16px 132px;
  }

  body[data-page="task-new"] .wizard-panel.active {
    overflow: visible;
  }

  body[data-page="task-new"] .columns-editor .table-wrap,
  .data-preview-wrap {
    max-height: 52vh;
  }

  .workspace {
    padding: 16px;
  }

  .topbar,
  .panel-header,
  .actions,
  .script-toolbar,
  .row-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .file-name {
    max-width: 100%;
  }

  .kpis,
  .kpis.compact,
  .grid.two,
  .form-grid,
  .compact-grid,
  .split-output,
  .dataset-grid,
  .wizard-steps {
    grid-template-columns: 1fr;
  }

  .code-area {
    min-height: 240px;
  }

  body[data-page="task-new"] .code-area {
    min-height: 260px;
  }

  .panel-actions {
    align-items: stretch;
    flex-direction: column;
  }

  body[data-page="task-new"] .wizard-footer {
    align-items: center;
    flex-direction: row;
    flex-wrap: wrap;
  }

  body[data-page="task-new"] .wizard-footer > * {
    flex: 1 1 100px;
  }
}
