:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --line: #dfe6f0;
  --text: #243142;
  --muted: #6b7787;
  --blue: #2563eb;
  --green: #12a150;
  --red: #dc3545;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: #172033;
  color: white;
  display: flex;
  flex-direction: column;
  padding: 18px;
  gap: 16px;
}

.brand, .settings, .nav, button {
  border: 0;
  border-radius: 6px;
  padding: 9px 12px;
  cursor: pointer;
}

.brand {
  background: transparent;
  color: white;
  text-align: left;
  font-size: 18px;
  font-weight: 700;
  padding: 4px 0;
}

nav { display: grid; gap: 8px; }
.nav-group {
  color: #94a3b8;
  font-size: 12px;
  font-weight: 700;
  margin-top: 8px;
  padding: 4px 2px;
}
.nav {
  background: transparent;
  color: #cbd5e1;
  text-align: left;
  font-size: 14px;
}
.nav.active, .nav:hover { background: #263650; color: white; }
.settings { margin-top: auto; background: var(--blue); color: white; }

main { flex: 1; min-width: 0; padding: 18px; }
.page { display: none; }
.page.active { display: block; }
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.page-head > div {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}
.inline-field input {
  width: 76px;
}
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 14px 0 8px; }

.grid.two {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, .75fr);
  gap: 12px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 12px;
}
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
button { background: var(--blue); color: white; }
button:hover { filter: brightness(1.05); }
button.danger, [data-action="delCol"], [data-action="delRow"] { background: var(--red); }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: white;
}
textarea { min-height: 64px; resize: vertical; }
label { display: grid; gap: 5px; margin-bottom: 9px; color: var(--muted); font-size: 13px; }
label input[type="checkbox"] { width: auto; }

.table-wrap { overflow: auto; max-height: 56vh; border: 1px solid var(--line); border-radius: 6px; }
.table-wrap.tall { max-height: calc(100vh - 210px); }
table { width: 100%; border-collapse: collapse; background: white; }
th, td { border: 1px solid var(--line); padding: 7px; min-width: 120px; vertical-align: top; }
th { background: #eef4ff; color: #334155; position: sticky; top: 0; z-index: 1; }
td[contenteditable="true"] { background: #fff; }
tr.selected td { outline: 2px solid #93c5fd; outline-offset: -2px; }
.column-config {
  display: grid;
  grid-template-columns: 1fr auto auto minmax(160px, 260px);
  gap: 6px;
  align-items: center;
  max-height: 65vh;
  overflow: auto;
}
.column-config.wide {
  grid-template-columns: minmax(180px, 1fr) 90px 90px minmax(180px, 260px) 90px;
}
.column-config-head {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 90px 90px minmax(180px, 260px) 90px;
  gap: 6px;
  color: var(--blue);
  border-bottom: 2px solid var(--line);
  padding-bottom: 8px;
  margin-bottom: 8px;
}
.column-config input[type="checkbox"] { width: auto; }
.hint { color: var(--muted); margin: 0 0 12px; }
.drop {
  border: 2px dashed #9aa9bd;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  text-align: center;
  padding: 30px 10px;
  margin: 8px 0;
}
.drop.drag { border-color: var(--blue); color: var(--blue); }
.logbox {
  background: #1f2937;
  color: #d1d5db;
  border-radius: 6px;
  padding: 10px;
  min-height: 110px;
  max-height: 180px;
  overflow: auto;
  font-family: Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
}
.logbox.large { min-height: 70vh; max-height: 70vh; }
dialog {
  border: 0;
  border-radius: 10px;
  width: min(560px, 92vw);
  box-shadow: 0 20px 80px #0004;
}
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; }

@media (max-width: 980px) {
  body { display: block; }
  .sidebar { width: auto; min-height: auto; }
  .grid.two { grid-template-columns: 1fr; }
  .page-head { align-items: flex-start; flex-direction: column; }
}
