:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-soft: #eff6ff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f8fafc;
  --card: #ffffff;
  --green: #059669;
  --amber: #d97706;
  --red: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15,23,42,.04), 0 8px 24px rgba(15,23,42,.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 1080px; margin: 0 auto; padding: 0 16px 48px; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 22px 4px 18px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 42px; height: 42px; border-radius: 11px;
  background: linear-gradient(135deg, var(--blue), #4f46e5);
  color: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 16px rgba(37,99,235,.35);
}
.brand-text h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.brand-text p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

/* Tabs */
.tabs { display: flex; gap: 8px; background: #fff; padding: 5px; border-radius: 12px; box-shadow: var(--shadow); }
.tab {
  display: inline-flex; align-items: center; gap: 7px;
  border: none; background: transparent; cursor: pointer;
  padding: 9px 16px; border-radius: 9px; font-size: 13px; font-weight: 600;
  color: var(--muted); transition: all .15s ease;
}
.tab:hover { color: var(--ink-2); }
.tab.active { background: var(--blue); color: #fff; box-shadow: 0 4px 12px rgba(37,99,235,.3); }

/* Panels */
.panel { display: none; }
.panel.active { display: block; }
.panel { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Card */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px;
  box-shadow: var(--shadow); margin-bottom: 18px;
}
.card.gradient {
  background: linear-gradient(135deg, #eff6ff, #eef2ff);
  border-color: #dbeafe;
}
.card-head { display: flex; align-items: center; gap: 9px; color: var(--blue); margin-bottom: 6px; }
.card-head.row { justify-content: space-between; align-items: center; }
.card-head h2 { margin: 0; font-size: 15px; font-weight: 700; color: var(--ink); }
.head-left { display: flex; align-items: center; gap: 9px; color: var(--blue); }
.card-sub { margin: 6px 0 18px; color: var(--muted); font-size: 13px; }

/* Inputs */
.input-row { display: flex; gap: 10px; flex-wrap: wrap; }
.model-input {
  flex: 1; min-width: 240px;
  height: 48px; padding: 0 16px; font-size: 15px; letter-spacing: .02em;
  border: 1px solid var(--line); border-radius: 11px; background: #fff;
  outline: none; transition: border-color .15s, box-shadow .15s; font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}
.model-input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.select {
  height: 48px; padding: 0 14px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 11px; background: #fff;
  outline: none; min-width: 220px; cursor: pointer;
}
.select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.field { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 220px; }
.field label { font-size: 12px; font-weight: 600; color: var(--ink-2); }

.format-hint { margin-top: 12px; font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.example { color: var(--blue); cursor: pointer; font-family: ui-monospace, Menlo, Consolas, monospace; }
.example:hover { text-decoration: underline; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  height: 48px; padding: 0 20px; border-radius: 11px; font-size: 14px; font-weight: 600;
  border: 1px solid transparent; transition: all .15s ease; white-space: nowrap;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); box-shadow: 0 6px 16px rgba(37,99,235,.3); }
.btn-outline { background: #fff; border-color: var(--line); color: var(--ink-2); height: 38px; padding: 0 14px; font-size: 13px; }
.btn-outline:hover { border-color: var(--blue); color: var(--blue); }

/* Error */
.error-box {
  background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c;
  padding: 14px 16px; border-radius: 12px; margin-bottom: 18px;
  font-size: 13px; display: flex; gap: 10px; align-items: flex-start;
}
.error-box svg { flex: none; margin-top: 1px; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  background: var(--blue-soft); border: 1px solid #dbeafe; border-radius: 10px;
  padding: 8px 14px; min-width: 96px;
}
.chip .k { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.chip .v { font-size: 14px; font-weight: 700; color: var(--ink); font-family: ui-monospace, Menlo, Consolas, monospace; }
.chip .v small { font-weight: 500; color: var(--muted); font-family: inherit; }

/* BOM summary */
.bom-summary { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.sum-pill { font-size: 12px; font-weight: 600; padding: 6px 12px; border-radius: 999px; }
.sum-pill.total { background: #eef2ff; color: #4338ca; }
.sum-pill.self { background: #ecfdf5; color: var(--green); }
.sum-pill.buy { background: #fffbeb; color: var(--amber); }

/* Table */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.bom-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 720px; }
.bom-table thead th {
  background: #f8fafc; text-align: left; padding: 11px 14px;
  font-size: 12px; font-weight: 700; color: var(--muted);
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.bom-table tbody td { padding: 11px 14px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
.bom-table tbody tr:last-child td { border-bottom: none; }
.bom-table tbody tr:hover { background: #f8fafc; }
.col-seq { width: 64px; }
.col-num { width: 70px; text-align: center; }
.col-unit { width: 56px; text-align: center; }
.col-cat { width: 84px; text-align: center; }
.bom-table .num { text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.bom-table .unit { text-align: center; color: var(--muted); }
.cat-tag { display: inline-block; padding: 2px 9px; border-radius: 6px; font-size: 11px; font-weight: 700; }
.cat-self { background: #ecfdf5; color: var(--green); }
.cat-buy { background: #fffbeb; color: var(--amber); }
.name-cell { font-weight: 600; color: var(--ink); }
.pn-cell { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; color: var(--ink-2); word-break: break-all; }
.note-cell { color: var(--muted); font-size: 12px; }
.seq-cell { font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--muted); }

/* Query result */
.query-row { display: flex; gap: 16px; flex-wrap: wrap; }
.query-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 14px; }
.q-card { border: 1px solid var(--line); border-radius: 12px; padding: 16px; text-align: center; }
.q-card .q-motor { font-size: 13px; color: var(--muted); font-weight: 600; }
.q-card .q-stroke { font-size: 26px; font-weight: 800; color: var(--blue); margin-top: 8px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.q-card .q-none { font-size: 20px; font-weight: 700; color: #cbd5e1; margin-top: 8px; }
.q-note { margin-top: 12px; font-size: 12px; color: var(--muted); }

/* Footer */
.footer { text-align: center; color: #94a3b8; font-size: 12px; padding-top: 8px; }
.footer p { margin: 2px 0; }

/* extra layout */
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stat-card .num { font-size: 28px; font-weight: 800; }
.stat-card .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }

.note-list { margin: 0; padding-left: 20px; color: var(--ink-2); font-size: 13px; line-height: 1.9; }
.note-list li { margin-bottom: 2px; }

.lib-section { margin-top: 14px; }
.lib-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; color: var(--ink); margin-bottom: 8px; }
.lib-title svg { color: var(--blue); }
.count-tag { font-size: 12px; font-weight: 600; color: var(--muted); background: #f1f5f9; padding: 1px 8px; border-radius: 999px; }

.card.gradient.amber { background: linear-gradient(135deg, #fffbeb, #fef3c7); border-color: #fde68a; }

.std-strokes { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.std-pill { font-size: 13px; font-weight: 700; padding: 6px 12px; border-radius: 999px; }
.std-pill.b3 { background: #dbeafe; color: #1d4ed8; }
.std-pill.b4 { background: #e0e7ff; color: #4338ca; }
.std-pill.b5 { background: #ede9fe; color: #6d28d9; }
.std-pill.none { background: #f1f5f9; color: #94a3b8; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state svg { color: #cbd5e1; margin-bottom: 12px; }
.empty-state h3 { margin: 0 0 4px; font-size: 16px; color: var(--ink-2); }
.empty-state p { margin: 0; font-size: 13px; }

.field-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 14px; }
.field-cell { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.field-cell .k { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.field-cell .v { font-size: 14px; font-weight: 600; font-family: ui-monospace, Menlo, Consolas, monospace; }

.status-ok { display: flex; align-items: center; gap: 8px; color: #059669; font-weight: 600; margin: 14px 0; }
.status-err { display: flex; align-items: flex-start; gap: 8px; color: #dc2626; font-weight: 600; margin: 14px 0; }
.status-err ul { margin: 6px 0 0; padding-left: 18px; font-weight: 400; font-size: 13px; }

/* generator */
.gen-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-top: 6px; }
.gen-field { display: flex; flex-direction: column; gap: 6px; }
.gen-field label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.gen-field select { height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 13px; }
.gen-field select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.15); outline: none; }
.gen-output { margin-top: 16px; background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 12px; padding: 14px 16px; }
.gen-output .lbl { font-size: 12px; color: #047857; margin-bottom: 6px; }
.gen-output .model { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 18px; font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 10px; }
.gen-output .model code { flex: 1; }
.gen-warnings { margin-top: 12px; background: #fffbeb; border: 1px solid #fde68a; border-radius: 12px; padding: 12px 16px; color: #b45309; font-size: 13px; }
.gen-warnings ul { margin: 6px 0 0; padding-left: 18px; }
.gen-reset { margin-top: 14px; display: flex; justify-content: flex-end; }

.text-center { text-align: center; }

/* utilities */
.hidden { display: none !important; }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }
.text-muted { color: var(--muted); }
.hint-sub { font-size: 12px; color: var(--muted); margin-top: 6px; }
.match-config {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--blue-soft); border: 1px solid #dbeafe; color: var(--blue-dark);
  font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: 999px;
  margin-bottom: 12px;
}
.match-config b { font-family: ui-monospace, Menlo, Consolas, monospace; }

@media (max-width: 720px) {
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .tabs { width: 100%; overflow-x: auto; }
  .tab { flex: none; }
}
