:root {
  --ink: #1a2733;
  --muted: #5c6b7a;
  --accent: #107a57;
  --accent-soft: #e3f2ec;
  --warn: #c4790c;
  --danger: #b3372e;
  --bg: #f7f8fa;
  --card: #ffffff;
  --border: #dde3e9;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.55 "Segoe UI", system-ui, -apple-system, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.7rem 1.5rem; background: var(--card);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 650;
  font-size: 1.1rem; color: var(--ink); letter-spacing: 0.2px; }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; align-items: center; gap: 1rem; }
.usernav { display: flex; align-items: center; gap: 0.4rem; }
/* Right-justified icon cluster next to a section heading. */
.headtools { display: flex; align-items: center; gap: 0.25rem; }
.saved-flash { font-size: 0.85rem; }
.saved-flash.ok { color: var(--ok, #2e7d32); }
.saved-flash.err { color: var(--danger); }
.modelpicker { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.modelpicker select { width: auto; }
.modelpicker .kv { flex-basis: 100%; word-break: break-all; }

.container { max-width: 1100px; margin: 1.6rem auto; padding: 0 1.2rem; }
.footer { text-align: center; padding: 2rem 0 1rem; font-size: 0.85rem; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.2rem 1.4rem; margin-bottom: 1.2rem;
}
.card h2 { margin-top: 0.1rem; }
.auth-card { max-width: 400px; margin: 4rem auto; }

label { display: block; font-weight: 600; margin: 0.7rem 0 0.2rem; }
input[type=text], input[type=email], input[type=password], input[type=number], select {
  width: 100%; padding: 0.5rem 0.6rem; border: 1px solid var(--border);
  border-radius: 6px; font: inherit; background: #fff;
}
input[type=file] { margin: 0.4rem 0; }
button, .btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 6px;
  padding: 0.5rem 1rem; font: inherit; font-weight: 600; cursor: pointer;
  margin-top: 0.8rem;
}
button:hover { filter: brightness(1.07); }
button.link { background: none; color: var(--accent); padding: 0; margin: 0;
  font-weight: 500; }
form.inline { display: inline; }

.error { background: #fdecea; color: var(--danger); border: 1px solid #f2c7c3;
  border-radius: 6px; padding: 0.5rem 0.8rem; margin: 0.6rem 0; }

table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border); }
th { font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--muted); }

.chip { display: inline-block; padding: 0.1rem 0.6rem; border-radius: 999px;
  font-size: 0.8rem; font-weight: 600; background: var(--accent-soft);
  color: var(--accent); }
.chip.uploaded, .chip.discovering, .chip.rediscovering { background: #fff4e0; color: var(--warn); }
.chip.failed, .chip.rejected { background: #fdecea; color: var(--danger); }
.chip.user_validating { background: #e7effc; color: #2a5db0; }

.progress { background: var(--border); border-radius: 999px; height: 8px;
  overflow: hidden; margin: 0.6rem 0; }
.progress > div { background: var(--accent); height: 100%; transition: width 0.4s; }

.pagegrid { display: flex; flex-direction: column; gap: 1rem; }
.pageimg { width: 100%; border: 1px solid var(--border); border-radius: 6px; }
.fieldrow select { width: auto; }
.fieldrow input[type=text] { width: 100%; }
code { background: var(--accent-soft); padding: 0.05rem 0.35rem; border-radius: 4px;
  font-size: 0.86em; }

/* Icon buttons: colored when enabled, gray when disabled; hover shows a
   native tooltip via the title attribute. */
.iconbtn {
  background: none; border: 0; padding: 4px; margin: 0 2px; cursor: pointer;
  border-radius: 6px; line-height: 0; vertical-align: middle;
  color: var(--accent);
}
.iconbtn:hover { background: var(--accent-soft); }
.iconbtn svg { width: 20px; height: 20px; display: block; }
.iconbtn.danger { color: var(--danger); }
.iconbtn.warn { color: var(--warn); }
.iconbtn[disabled], .iconbtn.disabled {
  color: #9aa7b2; cursor: default; pointer-events: none;
}
.iconbtn.fileicon { display: inline-block; }
.iconbtn.fileicon input { display: none; }
.rowlink { cursor: pointer; }
.rowlink:hover { background: var(--accent-soft); }

.scorecell { font-variant-numeric: tabular-nums; }
/* Keep row actions on one line: the column is wide enough for the icons. */
.actioncol { white-space: nowrap; width: 1%; }
td.actions .iconbtn { display: inline-block; }
.detail-section { margin: 0.8rem 0; }
.detail-section h3 { margin: 0.3rem 0; font-size: 0.95rem; }
.kv { color: var(--muted); font-size: 0.9rem; }
pre.mono { background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.6rem; overflow: auto; max-height: 260px;
  font-size: 0.82rem; }

/* Modals */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20,30,40,.55);
  z-index: 20; }
.modal-card { background: var(--card); border-radius: var(--radius);
  max-width: 520px; margin: 8vh auto; padding: 1.4rem 1.6rem;
  box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal-card.wide { max-width: 720px; }
/* Every modal closes with a single X in its top-right corner. */
.modal-head { display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; margin-bottom: 0.4rem; }
.modal-head h2 { margin: 0; }
.modal-x { background: none; border: 0; cursor: pointer; color: var(--muted);
  font-size: 1.4rem; line-height: 1; padding: 0 0.2rem; border-radius: 6px; }
.modal-x:hover { background: var(--accent-soft); color: var(--ink); }
/* The field-path cell must not stretch the detail table; clip long names. */
td.fieldname { max-width: 320px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
td.fieldname code { font-size: 0.82rem; }

/* Section header with a right-justified action */
.sec-head { display: flex; align-items: center; justify-content: space-between;
  margin: 0 0 0.6rem; }
.sec-head h2 { margin: 0; }

/* Table filter/pager toolbar */
.tabletools { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap;
  margin-bottom: 0.6rem; }
.tabletools input, .tabletools select { width: auto; }
.pager { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.6rem;
  color: var(--muted); font-size: 0.9rem; }
.dropzone { border: 2px dashed var(--border); border-radius: 8px;
  padding: 1.4rem; text-align: center; color: var(--muted); cursor: pointer; }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
