:root {
  --canvas: #f4f6f5;
  --surface: #ffffff;
  --surface-subtle: #f8faf9;
  --text: #17211d;
  --text-soft: #5f6d67;
  --text-faint: #87918d;
  --line: #dce3df;
  --line-strong: #c6d0cb;
  --green: #12735d;
  --green-dark: #0b5545;
  --green-soft: #e8f3ef;
  --amber: #9a5a0a;
  --amber-soft: #fff7e8;
  --red: #b42318;
  --red-soft: #fff2f0;
  --blue: #315f86;
  --shadow: 0 12px 34px rgba(25, 42, 35, 0.07);
  font-family: -apple-system, "SF Pro Text", "PingFang SC", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--text);
  letter-spacing: 0;
}
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, summary, label, select { -webkit-tap-highlight-color: transparent; }

.masthead {
  height: 64px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand, .service-state, .pane-heading, .label-row, .plan-heading, .result-heading,
.result-actions, .task-topline, .task-state, .task-controls, .task-meta, .form-actions {
  display: flex;
  align-items: center;
}
.brand { gap: 11px; }
.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: var(--text);
  color: white;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 800;
}
.brand > div { display: grid; gap: 1px; }
.brand strong { font-size: 14px; }
.brand span:last-child { color: var(--text-soft); font-size: 11px; }
.service-state { gap: 8px; color: var(--text-soft); font-size: 12px; }
.service-state { min-width: 0; }
.service-state span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.state-dot, .task-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  flex: 0 0 auto;
}
.service-state.online .state-dot { background: #1b8c68; box-shadow: 0 0 0 4px var(--green-soft); }
.service-state.warning .state-dot { background: var(--amber); box-shadow: 0 0 0 4px var(--amber-soft); }

.workspace {
  width: min(1540px, 100%);
  min-height: calc(100vh - 64px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
}
.query-pane {
  padding: 26px 24px 34px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.result-pane { min-width: 0; padding: 26px 28px 40px; }
.pane-heading { justify-content: space-between; align-items: flex-start; margin-bottom: 22px; }
.eyebrow { margin: 0 0 5px; color: var(--text-faint); font-size: 10px; font-weight: 800; }
h1, h2 { margin: 0; font-size: 21px; line-height: 1.3; }
.mode-badge, .risk-badge {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 5px;
  background: var(--green-soft);
  color: var(--green-dark);
  font-size: 11px;
  font-weight: 750;
}

form { display: grid; gap: 17px; }
.field-block { display: grid; gap: 8px; color: var(--text-soft); font-size: 13px; font-weight: 650; }
.label-row { justify-content: space-between; gap: 12px; color: var(--text); font-size: 13px; font-weight: 700; }
.label-row > span:last-child, .selection-note { color: var(--text-faint); font-size: 11px; font-weight: 600; }
.label-actions { display: flex; align-items: center; gap: 10px; }
.label-actions > span { color: var(--text-faint); font-size: 11px; font-weight: 600; }
textarea, input, select, .picker > summary {
  width: 100%;
  min-height: 42px;
  padding: 10px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}
textarea { min-height: 108px; resize: vertical; line-height: 1.65; }
textarea:focus, input:focus, select:focus, .picker[open] > summary {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(18, 115, 93, 0.11);
}
input::placeholder, textarea::placeholder { color: #9aa49f; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.secondary-input { min-height: 38px; background: var(--surface-subtle); border-color: var(--line); }
.inline-command {
  justify-self: start;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--green);
  font-size: 11px;
  font-weight: 650;
  cursor: pointer;
}

.picker { position: relative; }
.picker > summary {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-weight: 550;
}
.picker > summary::-webkit-details-marker { display: none; }
.chevron { color: var(--text-faint); font-size: 16px; transition: transform .18s ease; }
.picker[open] .chevron { transform: rotate(180deg); }
.picker-panel {
  position: absolute;
  z-index: 12;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.option-grid { display: grid; gap: 7px; }
.option-grid-country { grid-template-columns: repeat(3, minmax(0, 1fr)); max-height: 240px; overflow: auto; }
.time-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.choice { position: relative; min-width: 0; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice span {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 7px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 650;
  cursor: pointer;
  text-align: center;
}
.choice input:checked + span { border-color: var(--green); background: var(--green-soft); color: var(--green-dark); }
.choice span:hover { border-color: var(--line-strong); }
.compact-field { display: block; margin: 13px 0 6px; color: var(--text-soft); font-size: 11px; }
.picker-panel input { min-height: 38px; }

.advanced { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.advanced > summary {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  list-style: none;
  cursor: pointer;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}
.advanced > summary::-webkit-details-marker { display: none; }
.advanced > summary span { color: var(--text-faint); font-size: 11px; font-weight: 500; }
.advanced-content { display: grid; gap: 12px; padding: 3px 0 14px; }
.toggle-row { display: flex; align-items: center; gap: 9px; color: var(--text-soft); font-size: 12px; font-weight: 500; }
.toggle-row input { width: 16px; min-height: 16px; height: 16px; accent-color: var(--green); }

.query-plan { padding: 13px 14px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-subtle); }
.plan-heading { justify-content: space-between; font-size: 12px; }
.risk-medium { background: var(--amber-soft); color: var(--amber); }
.risk-high { background: var(--red-soft); color: var(--red); }
.plan-metrics { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 12px; }
.plan-metrics > div { display: grid; gap: 2px; border-right: 1px solid var(--line); text-align: center; }
.plan-metrics > div:last-child { border-right: 0; }
.plan-metrics strong { color: var(--text); font-size: 17px; }
.plan-metrics span { color: var(--text-faint); font-size: 10px; font-weight: 500; }
.query-plan p { margin: 10px 0 0; color: var(--text-soft); font-size: 11px; line-height: 1.6; }

.form-actions { gap: 9px; }
.primary-button, .secondary-button, .export-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 15px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
}
.primary-button { flex: 1; background: var(--green); color: white; }
.primary-button:hover { background: var(--green-dark); }
.primary-button:disabled { background: #8da9a1; cursor: wait; }
.secondary-button { background: var(--surface); border-color: var(--line-strong); color: var(--text-soft); }
.text-button { padding: 2px; border: 0; background: transparent; color: var(--green); font-size: 11px; cursor: pointer; }
.danger-text { color: var(--red); }
.form-error { display: none; color: var(--red); font-size: 12px; line-height: 1.5; }
.form-error.active { display: block; }
.protection-note { margin: 15px 0 0; color: var(--text-faint); font-size: 10px; line-height: 1.6; }

.result-heading { justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 18px; }
.result-heading h2 { font-size: 21px; }
.result-heading p:last-child { margin: 4px 0 0; color: var(--text-soft); font-size: 12px; }
.result-actions { flex-wrap: wrap; justify-content: flex-end; gap: 9px; }
.result-filter { display: flex; align-items: center; gap: 7px; color: var(--text-faint); font-size: 11px; }
.result-filter input { width: 190px; min-height: 38px; background: var(--surface); }
.export-button { min-height: 38px; background: var(--text); color: white; }
.export-button.disabled { opacity: .38; pointer-events: none; }

.notice { margin-bottom: 12px; padding: 11px 13px; border-radius: 6px; font-size: 12px; line-height: 1.55; }
.notice-warning { background: var(--amber-soft); border: 1px solid #edd7aa; color: #7a4708; }
.notice-extension { background: #edf4fa; border: 1px solid #c8d9e8; color: #294f70; }
.notice-error { background: var(--red-soft); border: 1px solid #f2c8c3; color: #8f1d14; }
.hidden { display: none !important; }

.task-panel {
  margin-bottom: 13px;
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.task-topline { justify-content: space-between; gap: 16px; }
.task-state { align-items: flex-start; gap: 11px; }
.task-indicator { margin-top: 5px; background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }
.task-panel.rate-limited .task-indicator, .task-panel.failed .task-indicator { background: var(--red); box-shadow: 0 0 0 4px var(--red-soft); }
.task-panel.complete .task-indicator { background: var(--blue); box-shadow: 0 0 0 4px #eaf1f7; }
.task-state > div { display: grid; gap: 3px; }
.task-state strong { font-size: 13px; }
.task-state span { color: var(--text-soft); font-size: 11px; }
.task-controls { gap: 12px; color: var(--text-faint); font-size: 11px; }
.progress-track { height: 6px; margin: 13px 0 9px; overflow: hidden; border-radius: 5px; background: #e6ebe8; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--green); transition: width .3s ease; }
.task-meta { justify-content: space-between; gap: 12px; color: var(--text-faint); font-size: 10px; }

.table-shell {
  min-height: 460px;
  max-height: calc(100vh - 190px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.empty-state { min-height: 455px; display: grid; place-content: center; justify-items: center; gap: 7px; color: var(--text-faint); text-align: center; }
.table-empty { min-height: 380px; }
.empty-state strong { color: var(--text-soft); font-size: 14px; }
.empty-state span { font-size: 11px; }
.empty-mark { width: 42px; height: 42px; display: grid; place-items: center; margin-bottom: 4px; border: 1px solid var(--line); border-radius: 50%; color: var(--green); font-size: 21px; }
table { width: 100%; min-width: 760px; border-collapse: collapse; font-size: 12px; }
th, td { padding: 10px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; z-index: 2; background: var(--surface-subtle); color: var(--text-faint); font-size: 10px; font-weight: 750; }
td { color: var(--text-soft); }
.th-filter {
  display: grid;
  gap: 5px;
  min-width: 92px;
}
.th-filter-compact {
  min-width: 68px;
}
.th-filter span {
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 750;
}
.th-filter select {
  width: 100%;
  min-height: 28px;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  outline: none;
  background: var(--surface);
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 600;
}
.th-filter select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(18, 115, 93, 0.1);
}
td.query-cell { color: var(--text); font-size: 13px; font-weight: 700; min-width: 230px; }
.action-cell { width: 72px; }
.growth { display: inline-flex; min-width: 54px; justify-content: center; padding: 4px 6px; border-radius: 4px; background: var(--green-soft); color: var(--green-dark); font-weight: 750; }
.compare-button {
  min-width: 48px;
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid var(--green);
  border-radius: 5px;
  background: var(--surface);
  color: var(--green-dark);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.compare-button:hover { background: var(--green-soft); }
.compare-button:disabled { border-color: var(--line); color: var(--text-faint); cursor: not-allowed; }
.request-log { margin-top: 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.request-log summary { padding: 10px 12px; cursor: pointer; color: var(--text-soft); font-size: 11px; font-weight: 650; }
.request-log summary span { margin-left: 5px; color: var(--text-faint); }
.request-log pre { max-height: 190px; margin: 0; padding: 12px; overflow: auto; border-top: 1px solid var(--line); background: #15201c; color: #bfcec7; font: 11px/1.7 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; }

@media (max-width: 1040px) {
  .workspace { grid-template-columns: 370px minmax(0, 1fr); }
  .query-pane { padding-left: 18px; padding-right: 18px; }
  .result-pane { padding-left: 20px; padding-right: 20px; }
  .time-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 780px) {
  .masthead { height: 58px; padding: 0 16px; }
  .brand span:last-child { display: none; }
  .workspace { display: block; }
  .query-pane { border-right: 0; border-bottom: 1px solid var(--line); padding: 22px 16px 26px; }
  .result-pane { padding: 22px 16px 30px; }
  .result-heading { align-items: flex-start; flex-direction: column; }
  .result-actions { width: 100%; }
  .result-filter { flex: 1; }
  .result-filter input { width: 100%; }
  .table-shell { min-height: 380px; max-height: none; }
  .empty-state { min-height: 375px; }
}
@media (max-width: 440px) {
  .service-state { max-width: 145px; }
  .field-grid { grid-template-columns: 1fr; }
  .option-grid-country { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-actions { align-items: stretch; flex-direction: column; }
  .export-button { width: 100%; }
  .task-topline { align-items: flex-start; }
  .task-controls { flex-direction: column; align-items: flex-end; gap: 4px; }
}
