:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1d2330; --muted: #6b7280; --line: #e3e6eb;
  --accent: #2557d6; --accent-weak: #e8eefc; --ok: #16794a; --ok-weak: #e3f4ea;
  --warn: #9a5b00; --warn-weak: #fdf1dc; --bad: #b42318; --bad-weak: #fdeceb;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); min-height: 1em; }
button, .button { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 6px; padding: 6px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .button:hover { border-color: #c5cbd5; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); }
button.link { border: none; background: none; color: var(--accent); padding: 4px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--accent-weak); color: var(--accent); font-size: 12px; white-space: nowrap; }
.badge.ok { background: var(--ok-weak); color: var(--ok); }
.badge.warn { background: var(--warn-weak); color: var(--warn); }
.badge.bad { background: var(--bad-weak); color: var(--bad); }
.badge.grey { background: #eef0f3; color: var(--muted); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 24px; width: min(380px, 100%); display: grid; gap: 12px; }
.card h1 { margin: 0; font-size: 20px; }
.card label { display: grid; gap: 4px; }

.top { height: 52px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); gap: 12px; }
.brand { font-weight: 600; }
.top-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.layout { display: grid; grid-template-columns: 340px 1fr; height: calc(100vh - 52px); }
.list { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.drop { margin: 12px; padding: 14px; border: 1px dashed #c5cbd5; border-radius: 8px; text-align: center; color: var(--muted); }
.drop.over { border-color: var(--accent); background: var(--accent-weak); color: var(--accent); }
.filters { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 12px 8px; }
.filters button { padding: 3px 8px; font-size: 12px; }
.filters button.on { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); }
.items { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.items li { padding: 10px 12px; border-top: 1px solid var(--line); cursor: pointer; display: grid; gap: 3px; grid-template-columns: minmax(0, 1fr); }
.items li:hover { background: #f9fafb; }
.items li.sel { background: var(--accent-weak); }
.items .row1 { display: flex; justify-content: space-between; gap: 8px; }
.items .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.items .row1 .badge { flex-shrink: 0; }
.viewer { position: relative; }
.viewer .open { position: absolute; top: 8px; right: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font-size: 12px; color: var(--accent); text-decoration: none; }

.detail { overflow: hidden; display: flex; min-height: 0; }
.detail .empty { margin: auto; }
.split { display: grid; grid-template-columns: minmax(320px, 42%) 1fr; width: 100%; min-height: 0; }
.viewer { border-right: 1px solid var(--line); background: #e9ebef; }
.viewer iframe, .viewer img { width: 100%; height: 100%; border: 0; object-fit: contain; }
.panel { overflow: auto; padding: 16px; display: grid; gap: 16px; align-content: start; }
.panel h2 { margin: 0; font-size: 16px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.panel h3 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.fields label { display: grid; gap: 2px; font-size: 12px; color: var(--muted); }
.fields input { color: var(--text); }
.fields .wide { grid-column: 1 / -1; }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 500; background: #fafbfc; position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.picked td { background: var(--ok-weak); }
tr.taken td { color: var(--muted); }
.table-wrap { max-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.totals { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; padding: 10px 12px; border-radius: 8px; background: #fafbfc; border: 1px solid var(--line); }
.totals.ok { background: var(--ok-weak); border-color: #b7e0c8; }
.totals.bad { background: var(--warn-weak); border-color: #f2d7a6; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.note { padding: 10px 12px; border-radius: 8px; background: var(--accent-weak); color: #1f3d8a; }
.note.bad { background: var(--bad-weak); color: var(--bad); }
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 20px; width: min(900px, calc(100% - 32px)); }
dialog h2 { margin: 0 0 4px; font-size: 16px; }
code.sql { display: block; white-space: pre-wrap; font-size: 12px; background: #f3f4f6; padding: 6px 8px; border-radius: 6px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .list { max-height: 45vh; border-right: none; border-bottom: 1px solid var(--line); }
  .split { grid-template-columns: 1fr; }
  .viewer { height: 60vh; border-right: none; border-bottom: 1px solid var(--line); }
}

/* điều hướng giữa hai màn */
.nav { display: inline-flex; gap: 4px; margin-left: 12px; font-weight: 400; }
.nav a { padding: 4px 10px; border-radius: 6px; color: var(--muted); text-decoration: none; }
.nav a.on { background: var(--accent-weak); color: var(--accent); }

/* màn mở job: ô theo trạng thái */
.fld { display: grid; gap: 2px; font-size: 12px; color: var(--muted); }
.fld .fl { display: flex; gap: 6px; align-items: center; }
.fld input, .fld select, .fld textarea { color: var(--text); width: 100%; }
.fld.wide { grid-column: 1 / -1; }
.fs { font-size: 10px; padding: 0 6px; border-radius: 999px; }
.fs-auto, .fs-learned { background: var(--ok-weak); color: var(--ok); }
.fs-suggest { background: var(--warn-weak); color: var(--warn); }
.fs-missing { background: var(--bad-weak); color: var(--bad); }
.fs-none { background: #eef0f3; color: var(--muted); }
.st-auto input, .st-learned input { border-color: #9fd3b4; }
.st-suggest input, .st-suggest select { border-color: #f0c87a; background: #fffaf0; }
.st-missing input, .st-missing select { border-color: #f1a7a1; background: #fff6f5; }
.has-err input, .has-err select, .has-err textarea { border-color: var(--bad); }
td input { width: 100%; min-width: 70px; }
.tabs { display: flex; gap: 4px; padding: 6px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { font-size: 12px; padding: 3px 8px; white-space: nowrap; }
.tabs button.on { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); }
.viewer { display: flex; flex-direction: column; }
.viewer iframe, .viewer img { flex: 1; min-height: 0; }
pre.json { max-height: 50vh; overflow: auto; background: #f3f4f6; padding: 10px; border-radius: 6px; font-size: 12px; }
.split > * { min-width: 0; }
.panel { min-width: 0; }
.items .small { overflow-wrap: anywhere; }
.panel > * { min-width: 0; }
.viewer .tabs + iframe, .viewer .tabs + img, .viewer .tabs + .empty { min-height: 0; }
