:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --panel: #ffffff;
  --text: #152033;
  --muted: #667085;
  --line: #dbe3ee;
  --blue: #2563eb;
  --blue-dark: #1e40af;
  --green: #138a5e;
  --amber: #a16207;
  --red: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

.shell {
  width: min(1160px, calc(100% - 36px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 32px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 18px;
  align-items: start;
}

.panel,
.preview-frame-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 14px 30px rgba(21, 32, 51, 0.06);
}

.control-panel,
.progress-panel {
  padding: 20px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.section-title span {
  color: var(--muted);
  font-size: 13px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 16px;
}

.field span {
  color: #344054;
  font-size: 14px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  height: 44px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
  font: inherit;
  background: #ffffff;
}

select {
  appearance: auto;
}

textarea {
  width: 100%;
  min-height: 78px;
  resize: vertical;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font: inherit;
  line-height: 1.5;
  background: #ffffff;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(37, 99, 235, 0.14);
  border-color: var(--blue);
}

.grid-two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.switch-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 4px 0 16px;
  background: #f8fafc;
}

.switch-row input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
}

.switch-row strong,
.switch-row small {
  display: block;
}

.switch-row small {
  color: var(--muted);
  margin-top: 3px;
}

.primary-button,
.secondary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 8px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.primary-button {
  width: 100%;
  border: 0;
  background: var(--blue);
  color: #ffffff;
  font-size: 15px;
}

.secondary-button {
  width: 100%;
  border: 1px solid #bfccda;
  background: #ffffff;
  color: var(--blue-dark);
  font-size: 15px;
  margin-top: 10px;
}

.primary-button:disabled {
  opacity: 0.58;
  cursor: wait;
}

.ghost-button {
  border: 1px solid #bfccda;
  color: var(--blue-dark);
  background: #ffffff;
  padding: 0 14px;
}

.ghost-button.disabled {
  pointer-events: none;
  color: #98a2b3;
  background: #f8fafc;
}

.full-width {
  width: 100%;
}

.hint {
  margin-top: 13px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.automation-note {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid #bfccda;
  border-radius: 8px;
  margin: 2px 0 16px;
  background: #f8fafc;
  color: #344054;
  line-height: 1.55;
}

.automation-note strong {
  color: var(--text);
  font-size: 14px;
}

.automation-note span {
  color: var(--muted);
  font-size: 13px;
}

.partition-filter-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin: 2px 0 16px;
  background: #ffffff;
}

.partition-filter-panel.is-disabled .field,
.partition-filter-panel.is-disabled .partition-group,
.partition-filter-panel.is-disabled .compact-switch:last-child {
  opacity: 0.62;
}

.compact-switch {
  margin: 0 0 12px;
}

.partition-group {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.partition-group.is-muted {
  opacity: 0.5;
}

.partition-group-title {
  color: #344054;
  font-size: 14px;
  font-weight: 800;
}

.partition-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.check-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  border: 1px solid #bfccda;
  border-radius: 999px;
  padding: 0 11px;
  background: #fbfdff;
  color: #344054;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.check-pill input {
  width: 15px;
  height: 15px;
  margin: 0;
}

.saved-query-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin: 2px 0 16px;
  background: #ffffff;
}

.saved-query-list {
  display: grid;
  gap: 10px;
}

.saved-query-item {
  display: grid;
  gap: 7px;
  border: 1px solid #d7e0eb;
  border-radius: 8px;
  padding: 12px;
  background: #fbfdff;
}

.saved-query-item.is-disabled {
  opacity: 0.68;
}

.saved-query-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.saved-query-head strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.saved-query-status {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 800;
}

.saved-query-status.on {
  color: var(--green);
  background: #edfdf4;
  border: 1px solid #9fd9bf;
}

.saved-query-status.off {
  color: var(--muted);
  background: #f2f4f7;
  border: 1px solid #d0d5dd;
}

.saved-query-item p {
  margin: 0;
  color: #475467;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.saved-query-empty {
  padding: 12px;
  color: var(--muted);
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.55;
  background: #fbfdff;
}

.text-button {
  justify-self: start;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--blue-dark);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.query-manager {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin: 2px 0 16px;
  background: #fbfdff;
}

.compact-title {
  margin-bottom: 12px;
}

.preset-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.preset-button {
  min-height: 34px;
  border: 1px solid #bfccda;
  border-radius: 999px;
  background: #ffffff;
  color: var(--blue-dark);
  padding: 0 11px;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.query-list {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.query-card {
  border: 1px solid #d7e0eb;
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
}

.query-card-header {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 9px;
  align-items: center;
  margin-bottom: 10px;
}

.query-card-header input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
}

.query-name-input {
  height: 38px;
  font-weight: 800;
}

.icon-button {
  min-width: 36px;
  height: 36px;
  border: 1px solid #d0d8e4;
  border-radius: 8px;
  background: #ffffff;
  color: #475467;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
}

.query-term {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

.status-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 11px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status-pill.ready {
  border-color: #9fd9bf;
  color: var(--green);
  background: #edfdf4;
}

.status-pill.warn {
  border-color: #f1d28a;
  color: var(--amber);
  background: #fff8e6;
}

.progress-track {
  height: 9px;
  border-radius: 999px;
  overflow: hidden;
  background: #e5eaf2;
  margin-bottom: 18px;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--blue);
  transition: width 220ms ease;
}

.log-list {
  min-height: 230px;
  max-height: 360px;
  overflow: auto;
  margin: 0;
  padding: 0 0 0 20px;
  color: #344054;
  line-height: 1.65;
  font-size: 14px;
}

.log-list li + li {
  margin-top: 8px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.preview-frame-wrap {
  margin-top: 18px;
  overflow: hidden;
}

.preview-title {
  padding: 16px 18px;
  margin: 0;
  border-bottom: 1px solid var(--line);
}

iframe {
  width: 100%;
  height: 760px;
  border: 0;
  background: #ffffff;
}

.error-text {
  color: var(--red);
  font-weight: 700;
}

@media (max-width: 860px) {
  .shell {
    width: min(100% - 22px, 1160px);
    padding: 18px 0 28px;
  }

  .topbar,
  .layout {
    display: block;
  }

  h1 {
    font-size: 28px;
  }

  .status-strip {
    justify-content: flex-start;
    margin-top: 16px;
  }

  .progress-panel {
    margin-top: 16px;
  }

  .grid-two {
    grid-template-columns: 1fr;
  }

  .control-panel,
  .progress-panel {
    padding: 16px;
  }

  .section-title {
    align-items: flex-start;
  }

  .query-card-header {
    grid-template-columns: 24px 1fr 36px;
  }

  .preset-button {
    flex: 1 1 auto;
  }

  iframe {
    height: 680px;
  }
}

@media (max-width: 460px) {
  .topbar {
    margin-bottom: 14px;
  }

  .status-pill {
    font-size: 12px;
    min-height: 28px;
    padding: 0 9px;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .ghost-button {
    width: 100%;
  }
}
