:root {
  --bg: #eef1f6;
  --bg-accent: #e8ecf4;
  --ink: #0f172a;
  --muted: #64748b;
  --paper: #ffffff;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --secondary: #0f172a;
  --secondary-hover: #1e293b;
  --ok: #059669;
  --ok-bg: #ecfdf5;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --info: #0369a1;
  --info-bg: #eff6ff;
  --bad: #dc2626;
  --bad-bg: #fef2f2;
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.1);
  --font-ui: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --topbar-h: 64px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(ellipse 120% 80% at 50% -20%, #c7d2fe55, transparent 50%),
    linear-gradient(180deg, var(--bg-accent) 0%, var(--bg) 40%, var(--bg) 100%);
}

h1,
h2 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
}

h1 {
  font-size: 1.35rem;
}

h2 {
  font-size: 1.05rem;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.lead,
.hint {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

/* —— Top bar —— */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: var(--topbar-h);
  padding: 12px max(20px, env(safe-area-inset-right)) 12px max(20px, env(safe-area-inset-left));
  background: rgba(255, 255, 255, 0.82);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.topbar h1 {
  font-size: 1.15rem;
}

.topbar .eyebrow {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 10px;
}

.topbar .btn.ghost {
  color: var(--muted);
  border-color: var(--line);
}

.topbar .btn.ghost:hover {
  color: var(--ink);
  background: var(--bg);
  border-color: var(--line-strong);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.view-switch {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
}

.view-tab {
  appearance: none;
  border: 0;
  border-radius: 8px;
  padding: 7px 14px;
  min-height: 32px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.view-tab.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.view {
  display: grid;
  gap: 20px;
}

.view[hidden] {
  display: none;
}

.result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 22px 0;
}

.poll-hint {
  margin: 8px 0 0;
  color: var(--info);
  font-size: 12px;
  font-weight: 500;
}

/* —— Layout —— */
.layout {
  width: min(720px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 56px;
  display: grid;
  gap: 20px;
}

/* —— Panels —— */
.panel,
.auth-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 20px 22px 0;
}

.panel-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 15px;
  font-weight: 700;
}

.panel-header-text {
  flex: 1;
  min-width: 0;
}

.panel-header-text h2 {
  margin-bottom: 6px;
}

.panel-body {
  padding: 18px 22px 22px;
  display: grid;
  gap: 16px;
}

.panel-body > label {
  margin-top: -4px;
}

/* —— Auth —— */
.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(400px, 100%);
  padding: 32px 28px 28px;
}

.auth-card h1 {
  margin-bottom: 8px;
  font-size: 1.5rem;
}

.auth-card .lead {
  margin-bottom: 24px;
}

.auth-card .banner {
  margin-bottom: 20px;
}

.stack {
  display: grid;
  gap: 18px;
}

/* —— Forms —— */
label {
  display: grid;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
}

label .label-hint {
  font-weight: 400;
  color: var(--muted);
}

input,
textarea {
  width: 100%;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
  background: #fafbfc;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

textarea {
  min-height: 160px;
  resize: vertical;
}

input[type="email"],
input[type="text"],
input[type="password"] {
  font-family: var(--font-ui);
  font-size: 15px;
}

input::placeholder,
textarea::placeholder {
  color: #94a3b8;
}

input:hover,
textarea:hover {
  border-color: var(--line-strong);
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.inline-field {
  display: grid;
  gap: 16px;
}

@media (min-width: 520px) {
  .inline-field {
    grid-template-columns: 1fr auto;
    align-items: end;
  }

  .inline-field .btn {
    min-width: 140px;
  }
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 4px;
}

/* —— Buttons —— */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 11px 20px;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn.primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(79, 70, 229, 0.25);
}

.btn.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn.secondary {
  background: var(--secondary);
  color: #fff;
}

.btn.secondary:hover:not(:disabled) {
  background: var(--secondary-hover);
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
  min-height: 38px;
  padding: 8px 16px;
  font-size: 13px;
}

.btn.tiny {
  min-height: 36px;
  padding: 8px 14px;
  font-size: 13px;
  background: var(--bg);
  color: var(--ink);
  border-color: var(--line);
}

.btn.tiny:hover:not(:disabled) {
  background: var(--primary-soft);
  border-color: #c7d2fe;
  color: var(--primary);
}

.btn.block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* —— Messages —— */
.banner,
.msg {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.45;
}

.banner.error,
.msg.error {
  background: var(--bad-bg);
  color: var(--bad);
  border: 1px solid #fecaca;
}

.msg.ok {
  background: var(--ok-bg);
  color: var(--ok);
  border: 1px solid #a7f3d0;
}

/* —— Results —— */
.result-head h2 {
  margin-bottom: 4px;
}

.result-head .hint {
  font-size: 13px;
}

#live-result-panel .order-list,
#query-result-panel .order-list {
  padding: 16px 22px 22px;
}

.order-list {
  display: grid;
  gap: 12px;
}

.order-list > .empty-hint {
  text-align: center;
  padding: 24px 16px;
  color: var(--muted);
  font-size: 14px;
}

.order-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  background: #fafbfc;
  transition: box-shadow 0.15s, border-color 0.15s;
}

.order-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}

.order-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.email {
  font-weight: 600;
  font-size: 15px;
  word-break: break-all;
  line-height: 1.4;
}

.badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  border-radius: 6px;
  padding: 4px 8px;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.badge.pending {
  background: var(--warn-bg);
  color: var(--warn);
}

.badge.processing {
  background: var(--info-bg);
  color: var(--info);
}

.badge.completed {
  background: var(--ok-bg);
  color: var(--ok);
}

.badge.failed {
  background: var(--bad-bg);
  color: var(--bad);
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 16px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.meta-item {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.meta-item.full {
  grid-column: 1 / -1;
}

.meta-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
}

.meta-value {
  font-size: 13px;
  color: var(--ink);
  word-break: break-all;
}

.meta-value.muted {
  color: var(--muted);
}

.order-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

details {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}

details summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--primary);
  user-select: none;
}

details summary:hover {
  color: var(--primary-hover);
}

details pre {
  margin-top: 10px;
}

pre {
  overflow: auto;
  max-height: 200px;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
}

@media (max-width: 480px) {
  .layout {
    width: calc(100% - 24px);
    padding-top: 16px;
    gap: 16px;
  }

  .panel-header,
  .panel-body,
  .result-head,
  #live-result-panel .order-list,
  #query-result-panel .order-list {
    padding-left: 16px;
    padding-right: 16px;
  }

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

  .form-actions .btn.block,
  .inline-field .btn {
    width: 100%;
  }

  .topbar {
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .topbar-actions {
    flex-shrink: 0;
  }

  .result-head {
    flex-direction: column;
  }

  .result-head .btn {
    width: 100%;
  }
}
