/* ── Reset & Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-bg:        #f8f9fa;
  --color-surface:   #ffffff;
  --color-section:   #f8f9fa;
  --color-border:    rgb(0, 0, 0, 0.25);
  --color-text:      #212529;
  --color-muted:     #6c757d;
  --color-primary:   rgb(140, 33, 43);
  --color-primary-h: rgb(210, 33, 43);
  --color-danger:    #fc3545;
  --color-success:   rgb(30, 107, 83);
  --color-warning:   #ffc107;
  --color-unmerged-warning: #fefce8;
  --color-source:    #f1ccf5;
  --radius:          6px;
  --shadow:          0 1px 3px rgba(0,0,0,.1);
  --nav-height:      56px;
  --sidebar-width:   220px;
  --navbar-background: rgb(48, 48, 48);
  font-size: 14px;
  --color-unique:   rgba(0, 0, 0, 0.025);
  --color-bg-subtle: #f1f3f5;
  --color-changed:   #fefce8;
  --graph-edge-bg:  var(--color-bg);
  --graph-edge-bg-h: var(--color-primary);
  --color-table-header-bg: rgba(0, 0, 0, 0.1);
  --color-table-header: rgba(0, 0, 0, 0.75);
  --color-row-hover:  rgba(210, 33, 43, 0.05);

  --color-merged: rgba(0, 160, 0, 0.2);
  --color-manual: rgba(255, 160, 0, 0.2);
}

body {
  font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
}

p { padding-bottom: 1rem; }

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: monospace; background: var(--color-bg); padding: 1px 5px; border-radius: 3px; font-size: .9em; }
hr.section-divider { border: none; border-top: 1px solid var(--color-border); margin: 2rem 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 .75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
.text-muted { color: var(--color-muted); font-size: .875rem; }

.about { margin-top: 1em; padding-top: 1em; padding-left: 1em; border-left-style: dotted; border-left-width: 2px; border-left-color: var(--color-primary); }
.phonetic { font-size: 90%; opacity: 75%; margin-left: 3px; margin-right: 3px; }

/* ── Navbar ──────────────────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  height: var(--nav-height);
  background-color: var(--navbar-background);
  color: #fff;
  padding: 0 1.25rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}
.navbar-brand { display: flex; align-items: center; gap: 1rem; }
.navbar-brand a { color: #fff; font-weight: 700; text-decoration: none; display: flex; align-items: center; gap: .5rem; text-transform: uppercase; }
.navbar-brand > span { color: #fff; white-space: nowrap; }
.navbar-logo { height: 48px; width: auto; display: block; }
.navbar-menu { margin-left: auto; display: flex; align-items: center; gap: 1rem; }
.navbar-link { color: rgba(255,255,255,.8); font-size: .875rem; }
.navbar-link:hover { color: #fff; text-decoration: none; }
.navbar-user-info { display: flex; align-items: center; gap: .75rem; border-left: 1px solid rgba(255,255,255,.2); padding-left: 1rem; }
.navbar-user { color: rgba(255,255,255,.7); font-size: .875rem; }
.navbar-link--signout { padding-left: 2rem; }
.navbar .subtitle { color: inherit; }

/* Tenant switcher dropdown */
.navbar-dropdown { position: relative; }
.navbar-dropdown__trigger {
  display: flex; align-items: center; gap: .4rem;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.2);
  color: #fff; border-radius: var(--radius); padding: .3rem .75rem;
  font-size: .875rem; cursor: pointer; white-space: nowrap;
}
.navbar-dropdown__trigger:hover { background: rgba(255,255,255,.2); }
.navbar-tenant-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.navbar-dropdown__caret { font-size: .65rem; opacity: .7; transition: transform .2s; }
.navbar-dropdown--open .navbar-dropdown__caret { transform: rotate(180deg); }
.navbar-dropdown__menu {
  display: none; position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); box-shadow: 0 4px 12px rgba(0,0,0,.15);
  list-style: none; min-width: 220px; z-index: 200; overflow: hidden;
}
.navbar-dropdown--open .navbar-dropdown__menu { display: block; }
.navbar-dropdown__item {
  width: 100%; text-align: left; padding: .55rem 1rem;
  background: none; border: none; cursor: pointer; font-size: .875rem;
  color: var(--color-text); display: flex; align-items: center; justify-content: space-between; gap: .5rem;
}
.navbar-dropdown__item:hover { background: var(--color-bg); }
.navbar-dropdown__item--active { background: #eff6ff; font-weight: 600; }

/* Light navbar overrides */
.navbar--light .navbar-brand a { color: #111; }
.navbar--light .navbar-brand > span { color: #111; }
.navbar--light .navbar-link { color: rgba(0,0,0,.65); }
.navbar--light .navbar-link:hover { color: #000; }
.navbar--light .navbar-user { color: rgba(0,0,0,.55); }
.navbar--light .navbar-user-info { border-left-color: rgba(0,0,0,.15); }
.navbar--light .navbar-dropdown__trigger { color: #111; }
.navbar--light .navbar-dropdown__trigger:hover { background: rgba(0,0,0,.08); }
.navbar--light .navbar-dropdown__caret { opacity: .5; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.layout { display: flex; min-height: calc(100vh - var(--nav-height)); }
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 1rem;
  flex-shrink: 0;
}
.sidebar-tenant { margin-bottom: 1rem; }
.sidebar-tenant strong { display: block; font-size: .95rem; }
.sidebar-nav { display: flex; flex-direction: column; gap: .25rem; }
.sidebar-section-label { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--color-text-muted, #6c757d); padding: .5rem .5rem .15rem; margin-top: .25rem; }
.sidebar-section-label:first-child { margin-top: 0; }
.sidebar-link { display: block; padding: .4rem .5rem; border-radius: var(--radius); color: var(--color-text); font-size: .875rem; }
.sidebar-link:hover { background: var(--color-bg); text-decoration: none; }
.sidebar-link--active { background: var(--color-bg); font-weight: 600; }
.sidebar-link--subtle { opacity: .6; margin-top: .5rem; }
.sidebar-link--subtle:hover { opacity: 1; }
.sidebar-link--locked { opacity: .5; }

img.icon { width: 16px; height: 16px; margin-right: 4px; vertical-align: middle; }
img.icon.mini { width: 12px; height: 12px; }

.sidebar-nav + .flaticon-attrib { opacity: 0.75; font-size: 80%; position: absolute; bottom: 1rem; }

.main-content { flex: 1; min-width: 0; padding: 1.5rem 2rem; }

section { background-color: var(--color-section); border-width: 1px; border-style: solid; border-color: var(--color-border); border-radius: var(--radius); padding: 1em; filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.1)); }
#mappingSection section { max-height: 50vh; overflow-y: scroll; }

/* ── Auth ────────────────────────────────────────────────────────────────── */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--color-bg); background-image: url('/img/background.jpg'); background-position: bottom center; }
.auth-container { width: 100%; max-width: 400px; padding: 1rem; }
.auth-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 2rem; box-shadow: var(--shadow); }
.auth-logo { display: block; max-width: 180px; margin: 0 auto 1.25rem; }
.auth-title { font-size: 1.75rem; text-align: center; margin-bottom: .25rem; }
.auth-subtitle { text-align: center; color: var(--color-muted); margin-bottom: 1.5rem; }
.auth-message { margin-bottom: 1rem; color: var(--color-danger); }
.color-picker-row { display: flex; align-items: center; gap: .75rem; }
.color-picker-input { width: 48px; height: 36px; padding: 2px; border: 1px solid var(--color-border); border-radius: var(--radius); cursor: pointer; background: none; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .45rem 1rem;
  border-radius: var(--radius); border-width: 1px; border-style: solid; border-color: white black black white;
  font-size: .875rem; font-weight: 500; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn--block { display: flex; width: 100%; justify-content: center; }
.btn--primary { background: var(--color-primary); color: #fff; }
.btn--primary:hover { background: var(--color-primary-h); text-decoration: none; }
.btn--secondary { background: #fff; color: var(--color-text); border-color: var(--color-border); }
.btn--secondary:hover { background: var(--color-bg); text-decoration: none; }
.btn--danger { color: black; border-color: var(--color-border); }
.btn--danger:hover { background: var(--color-danger) !important; color: white; text-decoration: none; }
.btn--warning { background: var(--color-warning); color: #000; border-color: var(--color-warning); }
.btn--warning:hover { opacity: .9; color: #000; text-decoration: none; }
.btn--sm { padding: .25rem .6rem; font-size: .8rem; }

.btn--incomplete + .btn--incomplete-edit {
  margin-left: -1px; border-left-color: rgba(255, 255, 255, 0.5); border-top-left-radius: 0; border-bottom-left-radius: 0;
}

.btn--incomplete:has( + .btn--incomplete-edit) {
  margin-right: -2px; border-top-right-radius: 0; border-bottom-right-radius: 0;
}

.dup-dismiss-btn { min-width: 5.5em; justify-content: center; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form { max-width: 600px; }
.form--inline { max-width: 100%; }
.form-group { margin-bottom: 1rem; }
.form-group.test-panel { border-width: 2px; border-style: solid; border-color: var(--color-success); border-radius: var(--radius); padding: 1rem; }
.form-label { display: block; font-weight: 500; margin-bottom: .3rem; font-size: .875rem; }
.form-label--checkbox { display: flex; align-items: center; gap: .4rem; font-weight: 400; cursor: pointer; }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: .45rem .65rem;
  border: 1px solid var(--color-border); border-radius: var(--radius);
  font-size: .875rem; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(13,110,253,.15);
}
.form-input--error { border-color: var(--color-danger); }
.form-input--mono  { font-family: monospace; }
.form-textarea--code  { font-family: monospace; font-size: .8rem; }
.form-textarea--error { border-color: var(--color-danger); }
.form-error { display: block; color: var(--color-danger); font-size: .8rem; margin-top: .25rem; }
.form-hint { display: inline-block; color: var(--color-muted); font-size: .78rem; margin-top: .25rem; }
.form-actions { display: flex; align-items: center; gap: .5rem; margin-top: 1.25rem; }
.form-select--inline { width: auto; padding: .2rem .4rem; }
.required-mark { color: var(--color-danger); margin-left: .2rem; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .875rem; margin-bottom: 1rem; }
.table th, .table td { padding: .6rem .75rem; border-bottom: 1px solid var(--color-border); text-align: left; }
.table th { background: var(--color-bg); font-weight: 600; }
.table tr:hover td { background: var(--color-row-hover); }
.table-actions { white-space: nowrap; }
.table-actions > * + * { margin-left: .4rem; }
.table-empty { color: var(--color-muted); font-style: italic; }

/* ── Sensitivity chips ───────────────────────────────────────────────────── */
.sensitivity-chip { display: inline-block; padding: .1rem .45rem; border-radius: 999px; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; vertical-align: middle; margin-left: .3rem; }
.sensitivity-chip--public    { background: rgba(160, 255, 0, 0.5); color: #048f45; }
.sensitivity-chip--internal  { background: none; color: rgb(0, 0, 0, 0.5); }
.sensitivity-chip--sensitive { background: rgba(255, 180, 0, 0.5); color: rgb(160, 64, 32); }
.sensitivity-chip--secret    { background: rgba(160, 0, 0, 1.0); color: rgba(255, 255, 255, 0.95); }
.sensitivity-chip--overridden { text-decoration-line: line-through; text-decoration-color: rgb(0, 0, 0, 0.5); text-decoration-thickness: 3px; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge, .role-badge, .field-type-badge {
  display: inline-flex; align-items: center;
  padding: .15rem .5rem; border-radius: 999px;
  font-size: .75rem; font-weight: 500;
}
.badge--active { background: #d1fae5; color: #065f46; }
.api-key-reveal { background: #fefce8; border: 1px solid #fde047; border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; }
.api-key-reveal__key { font-family: monospace; font-size: .9rem; word-break: break-all; background: #fff; border: 1px solid var(--color-border); border-radius: var(--radius); padding: .5rem .75rem; }
.badge--inactive { background: #fee2e2; color: #991b1b; }
.badge--warning { background: #fef3c7; color: #92400e; }
.role-badge--admin { background: #dbeafe; color: #1e40af; }
.role-badge--editor { background: #fef9c3; color: #854d0e; }
.role-badge--viewer { background: #f3f4f6; color: #374151; }
.field-type-badge--text { background: #e0e7ff; color: #3730a3; }
.field-type-badge--number,
.field-type-badge--percent { background: #d1fae5; color: #065f46; }
.field-type-badge--amount { background: #e1daf5; color: #065f46; }
.field-type-badge--date { background: #fce7f3; color: #9d174d; }
.field-type-badge--boolean { background: #fef3c7; color: #92400e; }
.field-type-badge--enum { background: #ede9fe; color: #5b21b6; }
.field-type-badge--reference { background: #f0fdf4; color: #166534; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .875rem; animation: alertSlideIn .25s ease-out; }
.alert--success { background: #d1fae5; color: #065f46; border-left: 4px solid var(--color-success); }
.alert--error { background: #fee2e2; color: #991b1b; border-left: 4px solid var(--color-danger); }
@keyframes alertSlideIn { from { opacity: 0; transform: translateY(-.5rem); } to { opacity: 1; transform: none; } }

/* ── Loading spinner ────────────────────────────────────────────────────── */
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--color-border); border-top-color: var(--color-primary); border-radius: 50%; animation: spin .6s linear infinite; vertical-align: middle; margin-right: .4rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Page Header ─────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; flex-wrap: wrap; gap: .5rem; }
.page-header h1 { margin: 0; }
.page-header__actions { display: flex; gap: .5rem; }
.page-header__actions button { height: 2.25rem; }
.page-header__actions select { padding: 0.45rem 1rem; border-radius: var(--radius); border-color: var(--color-border); }
.page-header__actions select { &, &::picker(select) { appearance: base-select; }}
.page-header__actions select option { padding: 0.75rem; }
.page-header__actions select option[value="merged"] { background-color: var(--color-merged); }
.page-header__actions select option[value="manual"] { background-color: var(--color-manual); }

.page-header__actions select:has(option[value="merged"]:checked) { background-color: var(--color-merged); }
.page-header__actions select:has(option[value="manual"]:checked) { background-color: var(--color-manual); }

/* ── Cards / Grids ───────────────────────────────────────────────────────── */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.entity-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 1.25rem;
  display: flex; flex-direction: column; gap: .3rem;
  transition: box-shadow .15s, border-color .15s;
  text-decoration: none; color: var(--color-text);
}
.entity-card:hover { box-shadow: var(--shadow); border-color: var(--color-primary); text-decoration: none; }
.entity-card__icon { font-size: 1.5rem; }
.entity-card__name { font-weight: 600; }
.entity-card__desc { font-size: .8rem; color: var(--color-muted); }

/* ── Stats ───────────────────────────────────────────────────────────────── */
.stats-grid { display: flex; gap: 1rem; flex-wrap: wrap; }
.stat-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1.25rem 2rem; text-align: center; min-width: 140px; }
.stat-card__value { font-size: 2.5rem; font-weight: 700; }
.stat-card__label { color: var(--color-muted); }
.stat-card__link { display: inline-block; margin-top: .5rem; }

/* ── Detail List ─────────────────────────────────────────────────────────── */
.detail-list { display: grid; grid-template-columns: 200px 1fr; gap: .5rem 1rem; margin-bottom: 1.5rem; }
.detail-list__label { font-weight: 500; color: var(--color-muted); align-self: start; }
.detail-list__value { }

/* ── Tenant Picker ───────────────────────────────────────────────────────── */
.tenant-list { list-style: none; display: flex; flex-direction: column; gap: .5rem; }
.tenant-list__btn {
  width: 100%; text-align: left; padding: .75rem 1rem;
  background: var(--color-bg); border: 1px solid var(--color-border);
  border-radius: var(--radius); cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  transition: background .15s;
}
.tenant-list__btn:hover { background: var(--color-row-hover); }

/* ── Empty State ─────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--color-muted); }
.empty-state p { margin-bottom: 1rem; }

/* ── Entity graph ────────────────────────────────────────────────────────── */
#entity-graph { width: 100%; height: calc(100vh - var(--nav-height) - 100px); min-height: 400px; border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-surface); }

/* ── Pagination ──────────────────────────────────────────────────────────── */
.pagination { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; font-size: .875rem; }
.pagination-info { color: var(--color-muted); }
.pagination-link { }

/* ── Record Grid ─────────────────────────────────────────────────────────── */
.grid-wrap { overflow: auto; max-height: calc(100vh - var(--nav-height) - 12rem); border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-surface); display: inline-block; max-width: 100%; }
.record-grid { border-collapse: collapse; width: max-content; font-size: .875rem; }
.grid-th {
  background: var(--color-table-header-bg); color: var(--color-table-header); padding: .45rem .75rem;
  text-align: left; font-weight: 600; white-space: nowrap;
  position: sticky; top: 0; z-index: 2;
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  backdrop-filter: blur(12px) saturate(1.4);
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
}
.grid-th--id  { width: 52px; text-align: right; }
.grid-th--del { width: 36px; }
.grid-th__required { color: var(--color-danger); margin-left: .2em; font-weight: bold; }
.grid-cell {
  padding: .35rem .75rem; border-bottom: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  vertical-align: middle; max-width: 320px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 100px;
}
.grid-cell[data-type="boolean"] { text-align: center; }
.grid-cell[data-type="number"],
.grid-cell[data-type="percent"],
.grid-cell[data-type="amount"] { text-align:right; }
.grid-cell.is-unique { background-color: var(--color-unique); font-weight: bold; }
.grid-cell:last-child { border-right: none; }
.grid-cell[tabindex]:hover { background: var(--color-row-hover); cursor: cell; }
.grid-cell[tabindex]:focus { outline: 2px solid var(--color-primary); outline-offset: -2px; }
.grid-cell--active { padding: 0; overflow: visible; background: #fff; outline: 2px solid var(--color-primary); outline-offset: -2px; }
.grid-cell--id  { color: var(--color-muted); font-size: .8rem; text-align: right; width: 52px; min-width: unset; }
.grid-id-link   { color: inherit; text-decoration: none; }
.grid-id-link:hover { text-decoration: underline; }
.grid-cell--del { width: 40px; padding: .2rem .3rem; text-align: center; min-width: unset; }
.grid-cell--del .btn { font-size: 1rem; line-height: 1; padding: 0 .5rem; border-color: rgba(0, 0, 0, 0.1); color: rgb(128, 128, 128); background-color: rgb(128, 128, 128, 0.1); }
.grid-cell--del .btn:hover { color: white; }
.grid-cell--error,
.grid-cell--required-empty { background: #fff5f5 !important; outline: 1px solid var(--color-danger) !important; }
.grid-row--dirty .grid-cell--id::after { content: '•'; color: var(--color-warning); margin-left: 3px; }
.grid-row--saving { opacity: .55; pointer-events: none; }
.grid-row--error .grid-cell--id { color: var(--color-danger); }
.grid-input {
  width: 100%; height: 100%; border: none; outline: none;
  padding: .35rem .75rem; background: transparent;
  font-size: inherit; font-family: inherit; display: block;
}
input[type="checkbox"].grid-input { width: auto; padding: 0; margin: .3rem auto; display: block; cursor: pointer; }
input[type="date"].grid-input, input[type="number"].grid-input { padding: .3rem .5rem; }
select.grid-input { padding: .3rem .5rem; }
.grid-input-amount { display: flex; width: 100%; height: 100%; }
.grid-input--currency { width: 3.8em; min-width: 3.8em; padding: .35rem .4rem; border-right: 1px solid var(--color-border); flex-shrink: 0; font-family: monospace; text-transform: uppercase; }
.grid-input--amount  { flex: 1; min-width: 0; }

/* Amount compound input in forms */
.amount-input-group { display: flex; gap: .5rem; align-items: center; }
.form-input--currency { width: 5rem; flex-shrink: 0; font-family: monospace; text-transform: uppercase; }
.form-input--amount  { flex: 1; }

/* ── Delete confirmation modal ───────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.modal {
  background: var(--color-surface); border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  max-width: 560px; width: 100%;
  display: flex; flex-direction: column;
  max-height: 90vh; overflow-y: auto;
}
.modal__header {
  padding: 1.25rem 1.5rem .75rem;
  border-bottom: 1px solid var(--color-border);
}
.modal__title { font-size: 1.1rem; font-weight: 700; margin: 0; }
.modal__body { padding: 1.25rem 1.5rem; display: flex; flex-direction: column; gap: .75rem; }
.modal__intro { margin: 0; }
.modal__dep-list {
  margin: 0; padding-left: 1.25rem;
  display: flex; flex-direction: column; gap: .3rem;
  font-size: .875rem; color: var(--color-text);
}
.modal__warn {
  margin: 0; font-weight: 600;
  color: var(--color-danger); font-size: .875rem;
}
.modal__footer {
  padding: 1rem 1.5rem 1.5rem;
  display: flex; flex-direction: column; gap: .75rem;
}
.modal__option { display: flex; flex-direction: column; gap: .25rem; }
.modal__option .btn { align-self: flex-start; text-align: left; white-space: normal; }
.modal__option-desc { font-size: .8rem; color: var(--color-muted); padding-left: .1rem; }

/* ── API Lookup Builder ──────────────────────────────────────────────────── */
.api-pair-row { display: flex; align-items: center; gap: .4rem; margin-bottom: .35rem; }
.api-pair-row .form-input, .api-pair-row .form-select { min-width: 0; }
.api-pair-remove { flex-shrink: 0; }
.form-section-title { font-size: 1rem; font-weight: 600; margin: 2rem 0 .75rem; padding-bottom: .35rem; }

/* ── Transformation Builder ──────────────────────────────────────────────── */
.transform-field {
  display: flex; flex-wrap: wrap; align-items: center; gap: .3rem;
  padding: .35rem .45rem; min-height: 2.4rem;
  border: 1px solid var(--color-border); border-radius: 4px;
  background: var(--color-bg, #fff); cursor: default;
}
.transform-badge {
  display: inline-flex; align-items: center; gap: .25rem;
  padding: .2rem .45rem; border-radius: 3px;
  background: var(--color-primary, #3b82f6); color: #fff;
  font-size: .78rem; font-weight: 500; white-space: nowrap;
  cursor: grab; user-select: none; transition: opacity .15s;
}
.transform-badge--dragging { opacity: .35; }
.transform-badge--over { outline: 2px solid var(--color-primary, #3b82f6); outline-offset: 1px; }
.transform-badge__grip { opacity: .65; font-size: .85rem; }
.transform-badge__rm {
  background: none; border: none; color: rgba(255,255,255,.8);
  cursor: pointer; padding: 0 0 0 .15rem; font-size: .9rem; line-height: 1;
}
.transform-badge__rm:hover { color: #fff; }
.transform-add-select {
  border: none; background: transparent; color: var(--color-muted);
  font-size: .82rem; cursor: pointer; padding: 0; outline: none;
}

/* ── Record History ──────────────────────────────────────────────────────── */
.history-unmerged-notice {
  margin-bottom: .75rem; padding: .75rem 1.5rem; font-size: .85rem;
  background: var(--color-unmerged-warning);
  border-style: solid; border-width: 1px; border-color: var(--color-border); border-radius: var(--radius);
  display: inline-block;
}
.history-snapshot__source { font-size: .75rem; font-weight: 600; font-family: monospace; background: var(--color-source); color: var(--color-text); padding: .3em 1em; border-radius: 3px; }
.history-grid-wrap {
  overflow-x: auto; border-radius: 6px 6px 0 0; margin-top: .75rem;
  border-top-style: solid; border-top-width: 1px; border-top-color: var(--color-border);
}
.history-grid { width: 100%; border-collapse: collapse; font-size: .85rem; }
.history-grid th {
  padding: .35rem .6rem; text-align: left; font-weight: 600; white-space: nowrap;
  background: var(--color-bg-subtle); border-bottom: 1px solid var(--color-border);
}
.history-grid td {
  background-color: white; padding: .35rem .6rem; border: 1px solid var(--color-border); white-space: nowrap;
}
.history-grid__section-row td {
  padding: .4rem .6rem; font-weight: 600; font-size: .8rem;
  border-left-style: none; border-right-style: none;
  background: unset; padding-top: 2em;
}
.history-grid__changed { background: var(--color-changed) !important; }
.history-grid__meta { color: var(--color-muted); font-size: .8rem; }
.history-grid__ts { font-family: monospace; }

/* ── Sources ──────────────────────────────────────────────────────────── */

section.sources { max-width: 560px; }
.source-list { list-style: none; padding: 0; margin: 0 0 2rem; max-width: 560px; }
.source-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .55rem .75rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: .35rem;
  user-select: none;
}
.source-item--fixed { background: var(--color-bg); }
.source-item.drag-over { outline: 2px solid var(--color-primary); }
.source-item__handle { cursor: grab; color: var(--color-muted); font-size: 1rem; flex-shrink: 0; }
.source-item__handle--disabled { cursor: default; opacity: .25; }
.source-item__name { font-weight: 500; }
.source-item__slug { font-size: .8rem; }


/* ── Checklist ───────────────────────────────────────────────────────────── */
.checklist { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.checklist-item {
  display: flex; align-items: flex-start; gap: 0.75rem;
  padding: 0.75rem 1rem; border-radius: var(--radius);
  background: var(--color-surface); border: 1px solid var(--color-border);
}
.checklist-item--done { opacity: 0.55; }
.checklist-check {
  flex-shrink: 0; width: 1.5rem; height: 1.5rem; line-height: 1.5rem;
  text-align: center; border-radius: 50%; font-weight: 700; font-size: 0.85rem;
  border: 2px solid var(--color-border); color: var(--color-surface);
}
.checklist-item--done .checklist-check {
  background: var(--color-success); border-color: var(--color-success); color: #fff;
}
.checklist-content { display: flex; flex-direction: column; gap: 0.15rem; }
.checklist-label { font-weight: 600; }
a.checklist-label { color: var(--color-primary); text-decoration: none; }
a.checklist-label:hover { text-decoration: underline; }
.checklist-item--done .checklist-label { text-decoration: line-through; }
.checklist-hint { font-size: 0.85rem; color: var(--color-muted); }

/* ── Workflow Pipeline ───────────────────────────────────────────────────── */
.workflow-pipeline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--color-section);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.875rem;
}
.workflow-step {
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
}
.workflow-arrow {
  color: var(--color-muted);
  font-size: 1rem;
}

/* ── Empty States ────────────────────────────────────────────────────────── */
.empty-state__hint {
  color: var(--color-muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

/* ── Dialogs ─────────────────────────────────────────────────────────────── */
.dialog-section { margin-top: 1.5rem; }
.dialog-section:first-of-type { margin-top: 0; }
.dialog-section__summary { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.75rem 0; border-bottom: 1px solid var(--color-border, #e5e7eb); }
.dialog-section--danger { margin-top: 2.5rem; }
.dialog-section--danger .dialog-section__summary { border-bottom-color: var(--color-danger, #ef4444); }

.dlg {
  position: fixed; inset: 0;
  width: 90vw; max-width: 600px;
  height: fit-content; max-height: calc(100vh - var(--nav-height) - 2rem);
  padding: 0; margin: calc(var(--nav-height) + 1rem) auto auto;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.9);
  border: 3px solid white; border-radius: calc(2 * var(--radius));
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(3px);
}
.dlg--wide { max-width: 900px; }
.dlg::backdrop { background: rgba(0,0,0,0.15); }
.dlg__header { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.25rem; border-bottom: 1px solid var(--color-border, #e5e7eb); }
.dlg__header h2 { margin: 0; font-size: 1.1rem; }
.dlg__body { padding: 1.25rem; }

/* ── Tooltips ────────────────────────────────────────────────────────────── */
.tooltip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 1.25em;
  height: 1.25em;
  font-size: 0.75em;
  font-weight: 600;
  font-style: normal;
  line-height: 1;
  background-color: var(--color-primary);
  color: white;
  border-radius: 50%;
  cursor: help;
  vertical-align: middle;
  margin-left: 0.3em;
  flex-shrink: 0;
}
.tooltip::before { content: '?'; }
.tooltip::after {
  content: attr(data-tooltip);
  position: fixed;
  padding: 6px 10px;
  max-width: 280px;
  width: max-content;
  background: var(--color-text);
  color: var(--color-surface);
  font-size: 0.85rem;
  font-weight: normal;
  line-height: 1.4;
  border-radius: var(--radius);
  white-space: normal;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 300;
  /* positioned by JS via --tt-top / --tt-left */
  top: var(--tt-top, 0);
  left: var(--tt-left, 0);
  transform: translateX(-50%);
}
.tooltip:hover::after {
  opacity: 1;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .sidebar { display: none; }
  .main-content { padding: 1rem; }
  .detail-list { grid-template-columns: 1fr; }
}
