:root {
  --bg: #eef1ee;
  --ink: #18211c;
  --muted: #657269;
  --line: #cbd3cc;
  --paper: #fbfcf8;
  --field: #ffffff;
  --rail: #14221d;
  --rail-soft: #20342d;
  --accent: #0f766e;
  --accent-dark: #0b5a55;
  --amber: #c67a18;
  --bad: #b42318;
  --good: #137a4a;
  --shadow: 0 18px 55px rgba(24, 33, 28, .12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(15,118,110,.08), transparent 45%),
    repeating-linear-gradient(0deg, rgba(20,34,29,.035) 0 1px, transparent 1px 28px),
    var(--bg);
  font-family: "Aptos", "Segoe UI", "Microsoft YaHei", sans-serif;
}

button, input, select, textarea { font: inherit; }

.hidden { display: none !important; }

.auth-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(20,34,29,.92), rgba(20,34,29,.72)),
    repeating-linear-gradient(90deg, rgba(255,255,255,.08) 0 1px, transparent 1px 54px);
}

.auth-panel {
  width: min(440px, 100%);
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 8px;
  background: #f7f3ea;
  box-shadow: 0 28px 80px rgba(0,0,0,.32);
  padding: 30px;
}

.auth-panel h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 0;
}

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

.auth-form, .stack {
  display: grid;
  gap: 12px;
}

.app {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 250px;
  padding: 24px 18px;
  background: var(--rail);
  color: #f6efe3;
}

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

.mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid rgba(255,255,255,.22);
  background: var(--rail-soft);
  color: #e8a63a;
  font-weight: 900;
}

.brand strong, .brand span { display: block; }
.brand span { color: #aebcb5; font-size: 12px; margin-top: 3px; }

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

.nav-link {
  display: block;
  padding: 11px 12px;
  border-radius: 6px;
  color: #d5ddd8;
  text-decoration: none;
}

.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,.1);
  color: #fff;
}

.shell {
  max-width: 1280px;
  margin-left: 250px;
  padding: 30px;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .12em;
}

h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 30px; }
h2 { font-size: 20px; }

.session-box, .form-actions, .row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.metric {
  min-height: 104px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(251,252,248,.86);
  box-shadow: var(--shadow);
  padding: 18px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 28px;
}

.panel {
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(251,252,248,.92);
  box-shadow: var(--shadow);
  padding: 22px;
}

.section-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.section-title span {
  color: var(--muted);
  font-size: 13px;
}

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

.token-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(330px, 430px) minmax(0, 1fr);
  gap: 22px;
}

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

label {
  display: grid;
  gap: 6px;
  color: #314139;
  font-size: 13px;
  font-weight: 800;
}

input, select, textarea {
  width: 100%;
  min-height: 39px;
  border: 1px solid #bdc7bf;
  border-radius: 6px;
  background: var(--field);
  color: var(--ink);
  outline: none;
  padding: 9px 10px;
}

textarea { resize: vertical; }

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15,118,110,.16);
}

.switch-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 39px;
}

.switch-line input {
  width: 18px;
  height: 18px;
  min-height: 0;
}

.compact {
  align-self: end;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
}

.advanced {
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 10px;
}

.advanced summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 900;
}

.advanced .inline-fields {
  margin-top: 10px;
}

button {
  min-height: 39px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 900;
  padding: 9px 14px;
}

button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-dark); }
button.secondary { border: 1px solid #aeb9b1; background: #fff; color: var(--ink); }
button.danger { background: #fff0eb; color: var(--bad); }

.table-wrap { overflow: auto; }
table { width: 100%; min-width: 620px; border-collapse: collapse; }
th, td { border-bottom: 1px solid var(--line); padding: 11px 9px; text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; }
code { color: var(--muted); font-size: 12px; word-break: break-all; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  background: #e3e9e4;
  color: #35443c;
  font-size: 12px;
  font-weight: 900;
}
.badge.ok { background: rgba(19,122,74,.13); color: var(--good); }
.badge.off { background: rgba(180,35,24,.1); color: var(--bad); }

.choice-list {
  display: grid;
  gap: 8px;
  max-height: 190px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: rgba(255,255,255,.6);
}

.choice-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.choice-list input {
  width: 16px;
  height: 16px;
  min-height: 0;
}

.send-grid {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: end;
}

.notice {
  margin-bottom: 16px;
  border-radius: 6px;
  background: #fff4d8;
  color: #6e4a17;
  font-weight: 800;
  padding: 12px 14px;
}
.notice.error { background: #ffe9e6; color: var(--bad); }

.result-list, .message-list { display: grid; gap: 10px; }
.result-card {
  display: grid;
  grid-template-columns: minmax(120px, 220px) 1fr auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255,255,255,.58);
  padding: 12px;
}
.message-card {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255,255,255,.58);
  padding: 12px;
}
.message-card strong {
  display: block;
  margin-top: 7px;
  font-weight: 800;
  word-break: break-word;
}
.empty, .muted { color: var(--muted); }

@media (max-width: 980px) {
  .sidebar { position: static; width: auto; }
  .shell { margin-left: 0; padding: 20px; }
  .topbar, .section-title, .session-box { align-items: stretch; flex-direction: column; }
  .metrics, .form-grid, .workbench, .send-grid, .message-card { grid-template-columns: 1fr; }
}
