:root {
  --bg: #f5f7fb;
  --panel: #fff;
  --text: #172033;
  --muted: #667085;
  --line: #d9e0ea;
  --blue: #2563eb;
  --green: #14a44d;
  --orange: #f59e0b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Microsoft YaHei", Arial, sans-serif;
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

body.logged-out {
  display: block;
}

body.logged-out .sidebar,
body.logged-out main {
  display: none;
}

.login-screen {
  display: none;
  min-height: 100vh;
  place-items: center;
  background: #f5f7fb;
  padding: 24px;
}

.login-screen.active {
  display: grid;
}

.login-card {
  width: min(420px, 100%);
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px;
  box-shadow: 0 16px 50px rgba(15, 23, 42, 0.08);
  display: grid;
  gap: 12px;
}

.login-card .logo {
  margin-bottom: 4px;
}

.login-card h2 {
  font-size: 24px;
}

.login-card p {
  color: var(--muted);
  margin-bottom: 8px;
}

.login-error {
  min-height: 20px;
  color: #dc2626;
}

.sidebar {
  background: #111827;
  color: white;
  padding: 18px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 22px;
}

.logo {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--blue);
  display: grid;
  place-items: center;
  font-weight: 800;
}

h1, h2, h3, p { margin: 0; }
.brand h1 { font-size: 18px; }
.brand p { color: #b6c0d1; font-size: 12px; }

.nav {
  width: 100%;
  border: 0;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
}

.nav.active, .nav:hover {
  background: #243044;
  color: white;
}

.nav.logout {
  margin-top: 18px;
  color: #fecaca;
}

main { padding: 24px; }
header {
  margin-bottom: 18px;
}
header h2 { font-size: 24px; margin-bottom: 6px; }
header p { color: var(--muted); }

.view { display: none; }
.view.active { display: block; }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.metrics div, .panel, .card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}
.metrics strong { font-size: 28px; display: block; }
.metrics span { color: var(--muted); }

.plain { margin: 8px 0 0; padding-left: 18px; }
.plain li { margin: 6px 0; }
.muted { color: var(--muted); margin-top: 10px; }
.section-title { margin: 22px 0 12px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.card h3 { margin-bottom: 8px; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eaf1ff;
  color: var(--blue);
  font-size: 12px;
  margin: 4px 6px 0 0;
}
.badge.green { background: #e8f7ee; color: var(--green); }
.badge.orange { background: #fff4df; color: var(--orange); }

.split {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 14px;
  min-height: 560px;
}
.list, textarea, input, select {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
}
.list { padding: 10px; }
.list button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 8px;
  background: #f8fafc;
  padding: 10px;
  margin-bottom: 8px;
  cursor: pointer;
}
.list button.active { background: #eaf1ff; color: var(--blue); }

textarea {
  min-height: 360px;
  padding: 12px;
  resize: vertical;
  font-family: Consolas, "Microsoft YaHei", monospace;
}
input, select {
  height: 40px;
  padding: 8px 10px;
}
button {
  border: 0;
  background: var(--blue);
  color: white;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
}

.tester {
  display: grid;
  gap: 10px;
  max-width: 920px;
  margin-bottom: 16px;
}
.workbench {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(420px, 1.1fr);
  gap: 16px;
}
.workbench .panel {
  display: grid;
  gap: 10px;
  align-content: start;
}
.workbench textarea {
  min-height: 180px;
  font-size: 15px;
}
#wb-reply {
  min-height: 320px;
  font-size: 17px;
  line-height: 1.7;
}
.quick-row,
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.quick-row button {
  background: #eef4ff;
  color: var(--blue);
}
button.secondary {
  background: #e5e7eb;
  color: #111827;
}
#test-reply { min-height: 140px; font-size: 16px; }
#history .item {
  border-top: 1px solid var(--line);
  padding: 10px 0;
}
#history .item:first-child { border-top: 0; }
#history b { display: block; }
.plan strong {
  display: block;
  font-size: 24px;
  margin: 8px 0;
}

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .metrics, .split, .workbench { grid-template-columns: 1fr; }
}
