:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --text: #172033;
  --muted: #667085;
  --line: #d8dee8;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #0f9f6e;
  --red: #c24135;
  --amber: #bd7b00;
  --shadow: 0 24px 70px rgba(24, 38, 64, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(37, 99, 235, 0.08), transparent 260px),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

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

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

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

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.05;
}

h2 {
  font-size: 22px;
}

.status-pill,
.job-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  padding: 0 14px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(189, 123, 0, 0.12);
}

.status-pill.is-ok .status-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(15, 159, 110, 0.12);
}

.status-pill.is-error .status-dot {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(194, 65, 53, 0.12);
}

.is-hidden {
  display: none !important;
}

.auth-panel {
  display: grid;
  grid-template-columns: minmax(220px, 0.55fr) minmax(280px, 0.45fr);
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  padding: 18px;
}

.auth-copy p:not(.eyebrow) {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-panel .message-box {
  grid-column: 1 / -1;
  min-height: auto;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.admin-metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric,
.tool-panel,
.result-panel {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.metric {
  min-height: 118px;
  border-radius: 8px;
  padding: 18px;
}

.metric span,
label span,
dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 30px;
  line-height: 1;
}

.metric small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
}

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

.tool-panel,
.result-panel {
  border-radius: 8px;
}

.tool-panel {
  padding: 18px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 0;
}

.panel-toolbar,
.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.panel-heading {
  align-items: center;
}

.tab {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  padding: 0 14px;
  color: var(--muted);
  font-weight: 800;
}

.tab.is-active {
  border-color: #b9c8e9;
  background: #e9f0ff;
  color: var(--blue-dark);
}

.pane {
  display: none;
}

.pane.is-active {
  display: block;
}

form.pane {
  display: none;
}

form.pane.is-active {
  display: grid;
  gap: 15px;
}

label {
  display: grid;
  gap: 7px;
}

input,
select {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
  color: var(--text);
  padding: 0 13px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.form-grid {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 12px;
}

.primary-action,
.secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 46px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 16px;
  font-weight: 850;
}

.primary-action {
  width: 100%;
  margin-top: 4px;
  background: var(--blue);
  color: white;
}

.primary-action:hover {
  background: var(--blue-dark);
}

.primary-action:disabled {
  cursor: wait;
  opacity: 0.65;
}

.secondary-action {
  width: fit-content;
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--text);
}

.ghost-action {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 0 14px;
  font-weight: 800;
}

.button-icon {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
}

.result-panel {
  position: sticky;
  top: 18px;
  padding: 20px;
}

.result-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.job-badge {
  border-radius: 8px;
  align-self: start;
}

.progress-track {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4e9f2;
}

.progress-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 220ms ease;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.status-grid div {
  min-height: 76px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
  padding: 12px;
}

.status-grid dd {
  margin: 8px 0 0;
  font-size: 18px;
  font-weight: 850;
  word-break: break-word;
}

.message-box {
  min-height: 84px;
  border-left: 4px solid var(--blue);
  background: #f1f5ff;
  border-radius: 8px;
  padding: 14px;
  color: #253452;
  line-height: 1.55;
  word-break: break-word;
}

.message-box.is-error {
  border-left-color: var(--red);
  background: #fff1ee;
}

.message-box.is-success {
  border-left-color: var(--green);
  background: #edfdf6;
}

.result-link {
  display: none;
  margin-top: 14px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--green);
  color: white;
  font-weight: 850;
  text-decoration: none;
}

.result-link.is-visible {
  display: flex;
}

.history-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

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

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
  padding: 12px;
}

.history-item strong,
.history-item small {
  display: block;
  overflow-wrap: anywhere;
}

.history-item small {
  margin-top: 4px;
  color: var(--muted);
}

.history-item a {
  color: var(--blue-dark);
  font-weight: 850;
  text-decoration: none;
}

.nav-link {
  text-decoration: none;
}

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

.admin-form {
  display: grid;
  gap: 14px;
}

.admin-form + .admin-form {
  margin-top: 24px;
  border-top: 1px solid var(--line);
  padding-top: 20px;
}

.admin-form.is-disabled {
  opacity: 0.55;
  pointer-events: none;
}

.admin-main {
  position: static;
}

.keys-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.key-item {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(220px, 0.7fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
  padding: 12px;
}

.key-main strong,
.key-main small {
  display: block;
  overflow-wrap: anywhere;
}

.key-main small {
  margin-top: 5px;
  color: var(--muted);
}

.key-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.key-stats span {
  border-radius: 999px;
  background: var(--surface-2);
  padding: 6px 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.key-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.key-actions button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  padding: 0 10px;
  font-weight: 800;
}

@media (max-width: 900px) {
  .workspace,
  .admin-layout,
  .metrics,
  .admin-metrics,
  .auth-panel {
    grid-template-columns: 1fr;
  }

  .result-panel {
    position: static;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

  .topbar,
  .result-header,
  .panel-toolbar,
  .panel-heading,
  .history-item,
  .key-item {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .form-grid,
  .status-grid {
    grid-template-columns: 1fr;
  }

  .tabs {
    overflow-x: auto;
  }

  .tab {
    flex: 1;
  }
}
