:root {
  --bg: #f5f6f8; --card: #fff; --ink: #1f2430; --muted: #6b7280;
  --brand: #1f5eff; --line: #e3e6ea; --ok: #128a4a; --err: #c0362c;
}
* { box-sizing: border-box; }
/* The [hidden] attribute must always beat display rules below (e.g. the modal
   backdrop's display:flex), or hidden panels would stay visible. */
[hidden] { display: none !important; }
body { margin: 0; font-family: -apple-system, "Segoe UI", "Sarabun", sans-serif;
  background: var(--bg); color: var(--ink); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar { display: flex; align-items: center; gap: 18px; padding: 10px 20px;
  background: var(--ink); color: #fff; }
.topbar a { color: #cfd6e4; }
.topbar a:hover { color: #fff; }
.topbar .brand { font-weight: 700; color: #fff; font-size: 16px; }
.topbar nav { display: flex; gap: 16px; }
.topbar .spacer { flex: 1; }
.topbar .who { color: #aab2c2; font-size: 13px; }

.content { max-width: 1080px; margin: 24px auto; padding: 0 20px; }
h1 { font-size: 22px; } h2 { font-size: 17px; margin-top: 24px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 18px; margin: 14px 0; }
.card.narrow { max-width: 360px; margin: 60px auto; }

label { display: block; margin: 10px 0; font-size: 14px; color: var(--muted); }
input, select { width: 100%; padding: 8px 10px; margin-top: 4px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }

button, .btn { display: inline-block; padding: 9px 16px; font-size: 14px; cursor: pointer;
  background: var(--brand); color: #fff; border: 0; border-radius: 6px; }
button:hover, .btn:hover { opacity: .92; text-decoration: none; }
button:disabled { background: #9db4ff; cursor: not-allowed; }
.btn.secondary, button.secondary { background: #e9edf3; color: var(--ink); }
.link { background: none; color: var(--brand); padding: 0; }
.link.danger { color: var(--err); }
.row-actions { display: flex; gap: 10px; align-items: center; margin-top: 12px; }
.page-head { display: flex; align-items: center; justify-content: space-between; }

table { width: 100%; border-collapse: collapse; background: #fff; margin-top: 12px;
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { background: #fafbfc; color: var(--muted); font-weight: 600; }
td.actions { display: flex; gap: 12px; align-items: center; }
td.actions form { display: inline; }

.muted { color: var(--muted); }
.error { color: var(--err); background: #fdecea; padding: 8px 12px; border-radius: 6px; }
.success { color: var(--ok); background: #e7f5ec; padding: 8px 12px; border-radius: 6px; }

.tiles { display: flex; flex-wrap: wrap; gap: 14px; margin: 16px 0; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 16px 20px;
  min-width: 120px; display: flex; flex-direction: column; }
.tile .num { font-size: 26px; font-weight: 700; }
.tile span:last-child { color: var(--muted); font-size: 13px; }

.kv { list-style: none; padding: 0; margin: 0; }
.kv li { display: flex; gap: 12px; padding: 5px 0; border-bottom: 1px dashed var(--line); }
.kv li b { width: 150px; color: var(--muted); font-weight: 600; }

.status, .pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.status-uploaded, .pill.new { background: #eef2ff; color: #3a52cc; }
.status-matched, .pill.update { background: #fff5e6; color: #b26a00; }
.status-queued { background: #eef2ff; color: #3a52cc; }
.status-processing { background: #e6f2ff; color: #0a66c2; }
.status-completed { background: #e7f5ec; color: var(--ok); }
.status-failed, .pill.error { background: #fdecea; color: var(--err); }
.status-none { background: #eef0f3; color: var(--muted); }
tr.row-error td { background: #fff6f5; }

/* Batch banner */
.batch-banner { background: #e6f2ff; border-color: #b9d9ff; color: #0a66c2; }
.batch-banner.needs-auth { background: #fdf0e6; border-color: #f0b37a; color: #9a5b00; }

/* Q-global status chip + auth modal */
.qg-chip { display: inline-flex; align-items: center; margin-right: 4px; }
label.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
label.checkbox-row input { width: auto; }

/* Non-live AI (test mode) banner */
.test-mode-banner { background: #fff4e5; border-color: #ffc27a; color: #9a5b00; font-weight: 500; }

/* Modals */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 24, 33, .45);
  display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; z-index: 50; }
.modal { background: #fff; border-radius: 10px; padding: 22px; width: 100%; max-width: 640px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .25); }
.modal h2 { margin-top: 0; }
.scroll { max-height: 320px; overflow: auto; }
td.actions a { white-space: nowrap; }
td.actions a.danger { color: var(--err); }
