:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --line: #e3e9f1;
  --line-strong: #cfd8e3;
  --text: #1e293b;
  --text-soft: #475569;
  --muted: #7c8a9e;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-weak: #eff6ff;
  --ok: #0b7a3d;
  --ok-bg: #e6f6ec;
  --warn: #b45309;
  --warn-bg: #fef3e2;
  --danger: #c2410c;
  --danger-bg: #fdecec;
  --shadow: 0 8px 28px rgba(30, 52, 82, 0.12);
  --h1: 42px;
  --h2: 54px;
  --h3: 28px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

button { font-family: inherit; cursor: pointer; }
input, button { font-size: 13px; }
h1, h2, h3, p { margin: 0; }

/* ---------- login ---------- */
.login-mask {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background: radial-gradient(1200px 600px at 20% 0%, #dbeafe 0%, #eef2f7 45%, #e8eef7 100%);
  padding: 20px;
}

.login-card {
  width: 380px;
  max-width: 100%;
  background: var(--panel);
  border-radius: 18px;
  padding: 34px 32px 26px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.7);
}

.login-logo, .logo {
  display: inline-grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #4f8cff);
  border-radius: 10px;
}

.login-logo { width: 46px; height: 46px; font-size: 15px; margin-bottom: 16px; }

.login-card h1 { font-size: 20px; font-weight: 700; letter-spacing: 0.2px; }
.login-sub { color: var(--muted); font-size: 12px; margin-top: 6px; }

.field {
  display: block;
  margin-top: 18px;
  font-size: 12px;
  color: var(--text-soft);
  font-weight: 600;
}

.field input {
  width: 100%;
  margin-top: 7px;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #fbfdff;
  color: var(--text);
  font-weight: 400;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

#login-btn {
  width: 100%;
  height: 42px;
  margin-top: 22px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(180deg, #2f6ff0, #1d5ce0);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.25);
}

#login-btn:disabled { opacity: 0.6; cursor: default; }

.login-tip { min-height: 18px; margin-top: 12px; font-size: 12px; color: #dc2626; text-align: center; }
.login-foot { margin-top: 6px; font-size: 11px; color: var(--muted); text-align: center; }

/* ---------- app shell ---------- */
#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: none;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 38px; height: 38px; font-size: 12px; border-radius: 9px; flex: none; }
.brand h1 { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand p { font-size: 11px; color: var(--muted); margin-top: 2px; }

.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.online { display: flex; align-items: center; margin-right: 6px; }
.online .avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid #fff;
  margin-left: -7px;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: #64748b;
}
.online .avatar:first-child { margin-left: 0; }
.online .more { font-size: 11px; color: var(--muted); margin-left: 6px; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--brand-weak);
  color: var(--brand-dark);
  font-weight: 600;
  font-size: 12px;
  max-width: 160px;
}
.user-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; flex: none; }
.user-chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

button.primary, button.ghost, button.icon {
  border-radius: 8px;
  height: 32px;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

button.primary {
  padding: 0 14px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 3px 10px rgba(37, 99, 235, 0.22);
}
button.primary:hover { background: var(--brand-dark); }

button.ghost {
  padding: 0 12px;
  background: #f6f8fc;
  border-color: var(--line);
  color: var(--text-soft);
  font-weight: 500;
}
button.ghost:hover { border-color: var(--line-strong); background: #eef3fb; color: var(--text); }
button.ghost em, .tab em {
  font-style: normal;
  font-size: 11px;
  padding: 1px 6px;
  margin-left: 5px;
  border-radius: 999px;
  background: #e8eefb;
  color: var(--brand-dark);
}

button.icon {
  width: 32px;
  padding: 0;
  background: #f6f8fc;
  border-color: var(--line);
  color: var(--text-soft);
  font-size: 15px;
  line-height: 1;
}
button.icon:hover { border-color: var(--line-strong); background: #eef3fb; }

.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: none;
}

.tab {
  position: relative;
  height: 40px;
  padding: 0 14px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  border-radius: 0;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand-dark); }
.tab.active::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--brand);
}

.tabs-right { margin-left: auto; }

.conn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
  padding: 5px 10px;
  border-radius: 999px;
  background: #f5f7fb;
  border: 1px solid var(--line);
}
.conn i { width: 7px; height: 7px; border-radius: 50%; background: #f59e0b; }
.conn.ok i { background: #22c55e; }
.conn.poll i { background: #2563eb; }
.conn.bad i { background: #ef4444; }

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 18px 0;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-bottom: 10px;
  flex: none;
}

.search {
  position: relative;
  flex: 0 1 320px;
  min-width: 220px;
}
.search input {
  width: 100%;
  height: 34px;
  padding: 0 62px 0 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--text);
}
.search input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.search kbd {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  color: var(--muted);
  background: #f1f5f9;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 2px 5px;
  font-family: inherit;
}

.seg {
  display: inline-flex;
  background: #e9eff8;
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--text-soft);
  padding: 5px 12px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
}
.seg button.active { background: #fff; color: var(--brand-dark); font-weight: 600; box-shadow: 0 1px 3px rgba(15, 35, 75, 0.12); }

.check { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-soft); cursor: pointer; }
.check input { accent-color: var(--brand); }

.spacer { flex: 1; }

.zoom { display: inline-flex; align-items: center; gap: 6px; color: var(--text-soft); }
.zoom span { font-size: 11px; min-width: 36px; text-align: center; color: var(--muted); }

.grid-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px 12px 0 0;
  box-shadow: 0 2px 10px rgba(30, 52, 82, 0.04);
}

.hintbar {
  flex: none;
  padding: 8px 4px;
  font-size: 11px;
  color: var(--muted);
}

.panel-note {
  margin-bottom: 10px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text-soft);
  font-size: 12px;
}

.simple-table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 14px;
}

.simple-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
}
.simple-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f3f7fd;
  color: var(--text-soft);
  font-weight: 600;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.simple-table td { padding: 9px 14px; border-bottom: 1px solid #eef2f7; }
.simple-table tr:hover td { background: #f8fbff; }
.simple-table td.mono { font-family: Consolas, "Courier New", monospace; font-size: 12px; color: #0f172a; }

/* ---------- grid ---------- */
#grid {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  background: #fff;
  font-variant-numeric: tabular-nums;
  min-width: 100%;
}

#grid col { min-width: 52px; }

#grid td .cell { display: block; }
#grid td.col-A .cell,
#grid td.col-Y .cell {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
#grid td.col-B .cell {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

#grid th {
  position: sticky;
  top: 0;
  z-index: 6;
  height: var(--h2);
  padding: 4px 6px;
  font-size: 10.5px;
  font-weight: 700;
  color: #1f2d3d;
  text-align: center;
  vertical-align: middle;
  line-height: 1.3;
  border-right: 1px solid #dbe4ef;
  border-bottom: 1px solid #cbd6e4;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: hidden;
}

#grid thead tr:nth-child(1) th { top: 0; height: var(--h1); z-index: 8; font-size: 11.5px; }
#grid thead tr:nth-child(2) th { top: var(--h1); z-index: 9; }
#grid thead tr:nth-child(3) th { top: calc(var(--h1) + var(--h2)); z-index: 7; height: var(--h3); font-size: 10px; }

#grid th.h-basic { background: #dce9f7; }
#grid th.h-test { background: #fdf0d5; }
#grid th.h-batch { background: #e9e2f9; }
#grid th.h-prod { background: #dff2e4; }
#grid th.h-note { background: #eef2f7; }
#grid thead tr:nth-child(1) th.h-basic { background: #cfe2f6; }
#grid thead tr:nth-child(1) th.h-test { background: #fbe6bd; }
#grid thead tr:nth-child(1) th.h-batch { background: #ded2f5; }
#grid thead tr:nth-child(1) th.h-prod { background: #cdebd6; }

#grid td {
  height: 34px;
  padding: 5px 7px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text);
  border-right: 1px solid #edf1f7;
  border-bottom: 1px solid #edf1f7;
  vertical-align: middle;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  background: #fff;
}

#grid tbody tr:nth-child(even) td { background: #fbfdff; }
#grid tbody tr:hover td { background: #f4f9ff; }
#grid tbody tr.has-error td.col-A { box-shadow: inset 3px 0 0 #f87171; }
#grid tbody tr.has-warn td.col-A { box-shadow: inset 3px 0 0 #fbbf24; }

#grid td.center { text-align: center; }
#grid td.num { text-align: right; }
#grid td.readonly { background: #f8fafc; }
#grid td.readonly .tag { pointer-events: none; }

#grid td.editable { cursor: cell; }
#grid td.editable:hover { outline: 2px solid rgba(37, 99, 235, 0.35); outline-offset: -2px; }
#grid td.editing { padding: 0; }

#grid td input {
  width: 100%;
  height: 100%;
  min-height: 32px;
  margin: 0;
  padding: 4px 6px;
  border: 2px solid var(--brand);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  outline: none;
}

#grid td .tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
}
#grid td .tag.ok { background: var(--ok-bg); color: var(--ok); }
#grid td .tag.pending { background: var(--warn-bg); color: var(--warn); }
#grid td .tag.bad { background: var(--danger-bg); color: var(--danger); }

#grid mark { background: #fff1a8; color: inherit; border-radius: 3px; padding: 0 1px; }
#grid td.flash { animation: flash 1.1s ease-out; }
@keyframes flash { 0% { background: #dbeafe; } 100% { background: transparent; } }

#grid td.col-A { position: sticky; left: 0; z-index: 3; background: #fff; font-family: Consolas, "Courier New", monospace; font-size: 11.5px; }
#grid th.sticky-col { position: sticky; left: 0; }
#grid thead tr th.sticky-col { z-index: 30; }
#grid tbody tr:nth-child(even) td.col-A { background: #fbfdff; }
#grid tbody tr:hover td.col-A { background: #f4f9ff; }

/* ---------- drawer ---------- */
#drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 400px;
  max-width: 92vw;
  z-index: 60;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 32px rgba(20, 40, 70, 0.12);
  display: flex;
  flex-direction: column;
  animation: slideIn 0.18s ease-out;
}
@keyframes slideIn { from { transform: translateX(24px); opacity: 0.4; } to { transform: none; opacity: 1; } }

.drawer-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.drawer-head h2 { font-size: 14px; font-weight: 700; margin-right: auto; }
.drawer-head .icon { width: 28px; height: 28px; }

.drawer-body { overflow: auto; padding: 6px 16px 24px; }
.drawer-body section { padding: 12px 0 6px; }
.drawer-body h3 {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-soft);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.pill {
  display: inline-block;
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #fdecec;
  color: var(--danger);
  font-weight: 700;
}
.muted-pill { background: #f1f5f9; color: var(--muted); font-weight: 500; }

.list { display: flex; flex-direction: column; gap: 6px; }

.issue {
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 12px;
  color: var(--text-soft);
}
.issue:hover { border-color: var(--line-strong); background: #f8fbff; }
.issue .ref { font-family: Consolas, monospace; font-size: 11px; color: var(--brand-dark); flex: none; font-weight: 700; }
.issue.error { border-left: 3px solid #f87171; }
.issue.warn { border-left: 3px solid #fbbf24; }
.empty { color: var(--muted); font-size: 12px; padding: 10px 0; }

.hist {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  font-size: 12px;
}
.hist-top { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.hist-top .who { color: var(--brand-dark); font-weight: 700; font-size: 11.5px; }
.hist-top .ref { font-family: Consolas, monospace; }
.hist-top .time { margin-left: auto; }
.hist-diff { margin-top: 5px; color: var(--text-soft); line-height: 1.5; word-break: break-word; }
.hist-diff del { color: #b91c1c; background: #fdecec; text-decoration: line-through; padding: 0 3px; border-radius: 3px; }
.hist-diff ins { color: #15803d; background: #e6f6ec; text-decoration: none; padding: 0 3px; border-radius: 3px; }
.hist .revert {
  margin-top: 6px;
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--text-soft);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 11px;
}
.hist .revert:hover { border-color: var(--brand); color: var(--brand-dark); }

/* ---------- status bar + toast ---------- */
.statusbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 7px 18px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
}
.statusbar .spacer { flex: 1; }
#stat-saved { color: #15803d; }
#stat-saved.pending { color: var(--warn); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 46px;
  transform: translateX(-50%);
  z-index: 100;
  background: #1e293b;
  color: #fff;
  font-size: 12px;
  padding: 9px 16px;
  border-radius: 9px;
  box-shadow: 0 8px 24px rgba(15, 30, 55, 0.28);
  max-width: 80vw;
  animation: toastIn 0.18s ease-out;
}
.toast.error { background: #b91c1c; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (max-width: 900px) {
  .brand p { display: none; }
  .online { display: none; }
  .view { padding: 10px 10px 0; }
  .toolbar { gap: 8px; }
  .search { flex: 1 1 100%; }
}
