:root {
  color-scheme: light;
  --bg: #f4f6fb;
  --surface: rgba(255, 255, 255, 0.88);
  --surface-solid: #ffffff;
  --surface-soft: #f8f9fd;
  --text: #151926;
  --muted: #697086;
  --border: rgba(30, 38, 61, 0.12);
  --primary: #6557e8;
  --primary-strong: #5142d6;
  --accent: #12a594;
  --danger: #d93f5f;
  --warning: #b67400;
  --shadow: 0 24px 70px rgba(31, 38, 71, 0.13);
  --radius: 20px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 8%, rgba(101, 87, 232, 0.17), transparent 34rem),
    radial-gradient(circle at 88% 20%, rgba(18, 165, 148, 0.12), transparent 30rem),
    var(--bg);
  overflow-x: hidden;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: 0.62; }
[hidden] { display: none !important; }

.ambient {
  position: fixed;
  z-index: -1;
  border-radius: 999px;
  filter: blur(20px);
  pointer-events: none;
}
.ambient-a { width: 24rem; height: 24rem; left: -9rem; top: 42%; background: rgba(101, 87, 232, 0.12); }
.ambient-b { width: 20rem; height: 20rem; right: -7rem; bottom: -5rem; background: rgba(18, 165, 148, 0.1); }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(440px, 100%);
  padding: 36px;
  border: 1px solid var(--border);
  border-radius: 26px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}
.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  color: white;
  font-weight: 800;
  letter-spacing: -0.04em;
  background: linear-gradient(135deg, var(--primary), #8b66ff 68%, var(--accent));
  box-shadow: 0 14px 28px rgba(101, 87, 232, 0.28);
}
.brand-mark.small { width: 40px; height: 40px; border-radius: 12px; font-size: 0.9rem; }
.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(1.7rem, 3vw, 2.35rem); letter-spacing: -0.045em; }
h2 { margin-bottom: 0; font-size: 1.02rem; }
.muted, small { color: var(--muted); }
.muted { line-height: 1.65; }
.stack { display: grid; gap: 18px; margin-top: 26px; }
.field { display: grid; gap: 8px; }
.field > span { font-size: 0.82rem; font-weight: 700; color: #343a4d; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-solid);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input, select { min-height: 43px; padding: 0 12px; }
textarea { padding: 12px; resize: vertical; line-height: 1.6; }
input:focus, textarea:focus, select:focus {
  border-color: rgba(101, 87, 232, 0.65);
  box-shadow: 0 0 0 4px rgba(101, 87, 232, 0.12);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-solid);
  color: var(--text);
  font-weight: 700;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.button:hover:not(:disabled) { transform: translateY(-1px); border-color: rgba(101, 87, 232, 0.35); }
.button.primary { border-color: transparent; color: white; background: linear-gradient(135deg, var(--primary), #7a61f1); box-shadow: 0 12px 24px rgba(101, 87, 232, 0.22); }
.button.ghost { background: transparent; }
.button.small { min-height: 32px; padding-inline: 10px; font-size: 0.78rem; }
.button.wide { width: 100%; min-height: 46px; }
.error-text { min-height: 1.25em; margin: 0; color: var(--danger); font-size: 0.84rem; }
.status-text { min-height: 1.25em; margin: 12px 0 0; color: var(--muted); font-size: 0.86rem; }

.app-shell { min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto minmax(90px, 1fr);
  align-items: center;
  gap: 18px;
  padding: 14px clamp(18px, 4vw, 56px);
  border-bottom: 1px solid var(--border);
  background: rgba(244, 246, 251, 0.82);
  backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand > div:last-child { display: grid; gap: 2px; }
.brand strong { font-size: 0.98rem; letter-spacing: -0.02em; }
.brand span { color: var(--muted); font-size: 0.72rem; }
.nav-tabs { display: flex; gap: 5px; padding: 4px; border: 1px solid var(--border); border-radius: 13px; background: rgba(255, 255, 255, 0.7); }
.nav-tab { min-height: 34px; padding: 0 16px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 750; }
.nav-tab.active { color: var(--text); background: white; box-shadow: 0 5px 15px rgba(31, 38, 71, 0.08); }
.topbar > .button { justify-self: end; }

.content { width: min(1440px, 100%); margin: 0 auto; padding: 38px clamp(18px, 4vw, 56px) 64px; }
.view { display: none; }
.view.active { display: block; animation: reveal 0.22s ease both; }
@keyframes reveal { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.heading-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.panel {
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 12px 38px rgba(31, 38, 71, 0.06);
  backdrop-filter: blur(18px);
}
.panel-title-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.metric-card { padding: 18px; border: 1px solid var(--border); border-radius: 16px; background: rgba(255, 255, 255, 0.72); }
.metric-card span { display: block; color: var(--muted); font-size: 0.76rem; }
.metric-card strong { display: block; margin-top: 8px; font-size: 1.45rem; letter-spacing: -0.04em; }
.table-panel { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 860px; }
th, td { padding: 15px 18px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { color: var(--muted); background: var(--surface-soft); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
.account-identity { display: grid; gap: 3px; }
.account-identity strong { font-size: 0.9rem; }
.account-identity small { font-size: 0.72rem; }
.badge { display: inline-flex; align-items: center; gap: 5px; min-height: 25px; padding: 0 9px; border-radius: 999px; font-size: 0.72rem; font-weight: 800; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ready { color: #087c6e; background: rgba(18, 165, 148, 0.12); }
.badge.cooldown { color: var(--warning); background: rgba(182, 116, 0, 0.12); }
.badge.invalid, .badge.disabled { color: var(--danger); background: rgba(217, 63, 95, 0.1); }
.concurrency-input { width: 72px; min-height: 34px; padding-inline: 8px; }
.row-actions { display: flex; gap: 7px; }
.icon-button { border: 1px solid var(--border); border-radius: 9px; min-height: 32px; padding: 0 10px; background: white; color: var(--text); font-weight: 700; font-size: 0.76rem; }
.icon-button.danger { color: var(--danger); }
.empty-state { display: grid; place-items: center; gap: 6px; padding: 64px 24px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--text); }
.empty-state.compact { padding: 44px 18px; }

.studio-grid { display: grid; grid-template-columns: minmax(320px, 0.85fr) minmax(0, 1.4fr); gap: 18px; align-items: start; }
.studio-form { display: grid; gap: 18px; position: sticky; top: 98px; }
.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.results-panel { min-height: 480px; }
.result-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.result-card { overflow: hidden; border: 1px solid var(--border); border-radius: 15px; background: var(--surface-solid); }
.result-card img { display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: contain; background: #eef0f6; }
.result-card footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; }
.result-card small { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.download-link { color: var(--primary); text-decoration: none; font-size: 0.76rem; font-weight: 800; }

.settings-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr); gap: 18px; align-items: start; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 22px; padding: 16px 0 22px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.switch-row span { display: grid; gap: 4px; }
.switch-row input { width: 48px; min-height: 28px; accent-color: var(--primary); }
.inline-form { display: grid; grid-template-columns: 1fr 128px auto; gap: 8px; }
.secret-box { margin-top: 13px; padding: 13px; border: 1px solid rgba(18, 165, 148, 0.25); border-radius: 12px; background: rgba(18, 165, 148, 0.07); }
.secret-box span { display: block; margin-bottom: 8px; color: #087c6e; font-size: 0.76rem; font-weight: 800; }
.secret-box code { display: block; overflow-wrap: anywhere; margin-bottom: 8px; font-size: 0.78rem; }
.key-list { display: grid; gap: 9px; margin-top: 16px; }
.key-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; }
.key-row div { display: grid; gap: 3px; }
.key-row small { font-size: 0.72rem; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 100; transform: translate(-50%, 20px); padding: 11px 16px; border-radius: 11px; color: white; background: #202437; opacity: 0; pointer-events: none; transition: 0.2s ease; box-shadow: 0 12px 40px rgba(20, 24, 40, 0.28); }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

@media (max-width: 980px) {
  .topbar { grid-template-columns: 1fr auto; }
  .nav-tabs { grid-column: 1 / -1; grid-row: 2; justify-self: center; }
  .topbar > .button { grid-column: 2; grid-row: 1; }
  .studio-grid, .settings-grid { grid-template-columns: 1fr; }
  .studio-form { position: static; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .login-card { padding: 26px 22px; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .heading-actions { width: 100%; }
  .heading-actions .button { flex: 1; }
  .form-grid.two, .result-grid { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .inline-form { grid-template-columns: 1fr; }
  .topbar { padding-inline: 14px; }
  .content { padding-inline: 14px; }
}
