:root {
  color-scheme: light dark;
  --bg: #f4f6f9;
  --panel-bg: #ffffff;
  --border: #d8dee6;
  --border-soft: #e6eaf0;
  --text: #1c2530;
  --muted: #6b7686;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --secondary: #7c3aed;
  --secondary-soft: #ede9fe;
  --header-bg: #eef2f8;
  --header-text: #1c2530;
  --row-alt: #fafbfd;
  --pk-color: #b8860b;
  --fk-color: #2563eb;
  --edge-color: #b7c0cc;
  --edge-color-active: #2563eb;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, 0.18);
  --dim-opacity: 0.22;
  --canvas-dot: #d3dae3;
  --brand-logo: url("../assets/reknew-logo.png");

  /* Tag color palette (prioritization labels) - auto-assigned round-robin
     to new tags, editable in the Tags tab. */
  --tag-red: #dc2626; --tag-red-soft: #fee2e2;
  --tag-orange: #ea580c; --tag-orange-soft: #ffedd5;
  --tag-amber: #b45309; --tag-amber-soft: #fef3c7;
  --tag-green: #16a34a; --tag-green-soft: #dcfce7;
  --tag-teal: #0d9488; --tag-teal-soft: #ccfbf1;
  --tag-sky: #0284c7; --tag-sky-soft: #e0f2fe;
  --tag-fuchsia: #a21caf; --tag-fuchsia-soft: #fae8ff;
  --tag-pink: #db2777; --tag-pink-soft: #fce7f3;
  --tag-gray: #4b5563; --tag-gray-soft: #f1f5f9;
}

/* Theme resolution order: an explicit choice (data-theme, set by the theme
   switch and persisted to localStorage) always wins; with no explicit
   choice ("system"), prefers-color-scheme decides. Guarding the media query
   with :not([data-theme="light"]) and repeating the same values under an
   explicit :root[data-theme="dark"] rule means the toggle overrides the OS
   setting in both directions, not just one. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161d;
    --panel-bg: #1a2029;
    --border: #2a3341;
    --border-soft: #232b37;
    --text: #e6eaf0;
    --muted: #8b96a5;
    --accent: #5b9bff;
    --accent-soft: #1e3a63;
    --secondary: #a78bfa;
    --secondary-soft: #362a5c;
    --header-bg: #212a37;
    --header-text: #e6eaf0;
    --row-alt: #1e2430;
    --pk-color: #e0b04b;
    --fk-color: #6ea8ff;
    --edge-color: #3a4454;
    --edge-color-active: #6ea8ff;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
    --canvas-dot: #26303d;
    --brand-logo: url("../assets/reknew-logo-white.png");

    --tag-red: #f87171; --tag-red-soft: #4c1d1d;
    --tag-orange: #fb923c; --tag-orange-soft: #4a2c12;
    --tag-amber: #fbbf24; --tag-amber-soft: #452f08;
    --tag-green: #4ade80; --tag-green-soft: #143824;
    --tag-teal: #2dd4bf; --tag-teal-soft: #0f3735;
    --tag-sky: #38bdf8; --tag-sky-soft: #0e2e42;
    --tag-fuchsia: #e879f9; --tag-fuchsia-soft: #3d1447;
    --tag-pink: #f472b6; --tag-pink-soft: #4a1332;
    --tag-gray: #9ca3af; --tag-gray-soft: #2a3341;
  }
}

:root[data-theme="dark"] {
  --bg: #12161d;
  --panel-bg: #1a2029;
  --border: #2a3341;
  --border-soft: #232b37;
  --text: #e6eaf0;
  --muted: #8b96a5;
  --accent: #5b9bff;
  --accent-soft: #1e3a63;
  --secondary: #a78bfa;
  --secondary-soft: #362a5c;
  --header-bg: #212a37;
  --header-text: #e6eaf0;
  --row-alt: #1e2430;
  --pk-color: #e0b04b;
  --fk-color: #6ea8ff;
  --edge-color: #3a4454;
  --edge-color-active: #6ea8ff;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
  --canvas-dot: #26303d;
  --brand-logo: url("../assets/reknew-logo-white.png");

  --tag-red: #f87171; --tag-red-soft: #4c1d1d;
  --tag-orange: #fb923c; --tag-orange-soft: #4a2c12;
  --tag-amber: #fbbf24; --tag-amber-soft: #452f08;
  --tag-green: #4ade80; --tag-green-soft: #143824;
  --tag-teal: #2dd4bf; --tag-teal-soft: #0f3735;
  --tag-sky: #38bdf8; --tag-sky-soft: #0e2e42;
  --tag-fuchsia: #e879f9; --tag-fuchsia-soft: #3d1447;
  --tag-pink: #f472b6; --tag-pink-soft: #4a1332;
  --tag-gray: #9ca3af; --tag-gray-soft: #2a3341;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

#app {
  height: 100vh;
}

#diagram-root {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding-top: env(safe-area-inset-top, 0px);
}

/* ---------- Top bar ---------- */
#topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 52px;
  padding: 0 16px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 20;
}

#sidebar-toggle {
  border: 1px solid var(--border);
  background: var(--panel-bg);
  border-radius: 7px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  color: var(--text);
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#sidebar-toggle:hover { background: var(--header-bg); }

#topbar .title-block { display: flex; flex-direction: column; min-width: 0; flex: 0 1 auto; }
#topbar .title-row {
  display: inline-flex; align-items: center; gap: 5px;
  cursor: pointer;
  border-radius: 5px;
  padding: 1px 4px;
  margin: 0 -4px;
  max-width: 26vw;
}
#topbar .title-row:hover { background: var(--header-bg); }
#topbar .title-row .rename-hint { flex: 0 0 auto; color: var(--muted); opacity: 0; transition: opacity 0.1s; }
#topbar .title-row:hover .rename-hint { opacity: 1; }
#topbar .title { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#topbar .title-edit-input {
  font-size: 14px; font-weight: 700; font-family: inherit;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 5px;
  padding: 1px 5px;
  width: 26vw; min-width: 160px; max-width: 320px;
  outline: none;
}
#topbar .subtitle { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 3px; flex: 0 0 auto; }
.tab-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { background: var(--panel-bg); color: var(--accent); box-shadow: var(--shadow); }

#diagram-root:not([data-tab="diagrams"]) .toolbar,
#diagram-root:not([data-tab="diagrams"]) #sidebar-toggle { display: none; }

.search-wrap { flex: 1 1 auto; max-width: 420px; position: relative; }
.search-wrap input {
  width: 100%;
  padding: 7px 12px 7px 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.search-wrap input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-wrap svg { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--muted); pointer-events: none; }
.search-count { font-size: 11px; color: var(--muted); white-space: nowrap; }

.topbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.toolbar button {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
  border-radius: 7px;
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
}
.toolbar button:hover { background: var(--header-bg); }
.toolbar button svg { width: 14px; height: 14px; }

/* ---------- Body / page layout ---------- */
#body { flex: 1 1 auto; display: flex; min-height: 0; position: relative; }

.page { display: none; flex: 1 1 auto; min-height: 0; }
.page.active { display: flex; }

.list-nav-wrap {
  display: flex;
  flex-direction: column;
  flex: 0 0 280px;
  max-width: 280px;
}
.list-nav {
  flex: 1 1 auto;
  min-height: 0;
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px 0;
}
.list-nav-logo {
  flex: 0 0 40px;
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
  border-top: 1px solid var(--border);
  background-image: var(--brand-logo);
  background-size: 96px auto;
  background-repeat: no-repeat;
  background-position: 14px center;
}
#sidebar-wrap.collapsed { display: none; }

.detail-pane {
  flex: 1 1 auto;
  overflow-y: auto;
  min-width: 0;
}

.schema-group { margin-bottom: 4px; }
.schema-group-title {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 14px 4px;
}

.table-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 14px;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.table-item:hover { background: var(--header-bg); }
.table-item.active { background: var(--accent-soft); border-left-color: var(--accent); }
.table-item.dim { opacity: var(--dim-opacity); }
.table-item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.table-item .count { font-size: 10.5px; color: var(--muted); flex: 0 0 auto; background: var(--header-bg); border-radius: 8px; padding: 1px 6px; }

/* ---------- Canvas ---------- */
#viewport {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  cursor: grab;
  background-color: var(--bg);
  background-image: radial-gradient(var(--canvas-dot) 1px, transparent 1px);
  background-size: 22px 22px;
}
#viewport.panning { cursor: grabbing; }

#canvas {
  position: absolute;
  left: 0; top: 0;
  transform-origin: 0 0;
  will-change: transform;
}

#edges-svg { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
#edges-svg path.edge { fill: none; stroke: var(--edge-color); stroke-width: 1.6; transition: stroke 0.15s, opacity 0.15s, stroke-width 0.15s; }
#edges-svg path.edge.active { stroke: var(--edge-color-active); stroke-width: 2.4; }
#edges-svg path.edge.hover { stroke: var(--accent); stroke-width: 2.4; }
#edges-svg path.edge.dim { opacity: var(--dim-opacity); }
/* Invisible, much wider than the visible line, so hovering/clicking a
   relationship doesn't require pixel-precision on a 1.6px stroke. */
#edges-svg path.edge-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }

.edge-tooltip {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  box-shadow: var(--shadow-lg);
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 0.08s, transform 0.08s;
}
.edge-tooltip.show { opacity: 1; transform: translateY(0); }
.edge-tooltip-sub { display: block; font-size: 10.5px; color: var(--muted); margin-top: 2px; }

.tm-table {
  position: absolute;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow 0.15s, opacity 0.15s, border-color 0.15s;
}
.tm-table.dim { opacity: var(--dim-opacity); }
/* .selected = the table the user clicked; .related = connected to it (via
   an FK either direction) - two distinct colors so the selection direction
   reads at a glance. Neither is set (both classes absent) = default color. */
.tm-table.selected { border-color: var(--accent); border-width: 2px; box-shadow: var(--shadow-lg); z-index: 6; }
.tm-table.related { border-color: var(--secondary); box-shadow: var(--shadow-lg); z-index: 5; }
.tm-table.selected .tm-header { background: var(--accent-soft); color: var(--accent); }
.tm-table.related .tm-header { background: var(--secondary-soft); color: var(--secondary); }
.tm-table.match { border-color: #d29922; }
.tm-table.dragging { z-index: 30; box-shadow: var(--shadow-lg); transition: none; cursor: grabbing; }
.tm-table.dragging .tm-header { cursor: grabbing; }

.tm-header {
  background: var(--header-bg);
  color: var(--header-text);
  font-weight: 700;
  font-size: 12.5px;
  cursor: grab;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.tm-header .schema-tag { font-weight: 500; font-size: 10px; color: var(--muted); }
.tm-header .comment-badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10px; font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 1px 6px;
  flex: 0 0 auto;
}

.tm-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  height: 22px;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}
.tm-row:last-child { border-bottom: none; }
.tm-row:nth-child(even) { background: var(--row-alt); }
.tm-row.pk { font-weight: 700; }
.key-icon { flex: 0 0 auto; width: 13px; height: 13px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.key-icon svg { display: block; width: 100%; height: 100%; }
.key-icon.pk { color: var(--pk-color); }
.key-icon.fk { color: var(--fk-color); }
.tm-row .col-name { overflow: hidden; text-overflow: ellipsis; flex: 1 1 auto; }
.tm-row .col-type { color: var(--muted); font-size: 11px; flex: 0 0 auto; overflow: hidden; text-overflow: ellipsis; max-width: 40%; }
.tm-row .col-null { flex: 0 0 auto; width: 6px; height: 6px; border-radius: 50%; border: 1px solid var(--muted); }
.tm-row .col-null.nn { background: var(--muted); }

/* ---------- Zoom controls (floating, mirrors #legend on the other corner) ---------- */
#zoom-controls {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: flex;
  gap: 2px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow);
  padding: 3px;
  z-index: 10;
}
#zoom-controls button {
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: 6px;
  padding: 6px 11px;
  font-size: 13px;
  min-width: 30px;
  cursor: pointer;
}
#zoom-controls button:hover { background: var(--header-bg); }

/* ---------- Legend ---------- */
#legend {
  position: absolute;
  right: 14px;
  bottom: 14px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 10;
}
#legend .row { display: flex; align-items: center; gap: 6px; }

/* ---------- Detail content (shared by the floating diagram panel and the
   full Tables/Relationships tab panes) ---------- */
#detail, .detail-pane .detail-card { background: var(--panel-bg); }

#detail {
  position: absolute;
  right: 14px;
  top: 14px;
  width: 300px;
  max-height: calc(100% - 28px);
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  z-index: 15;
  display: none;
}
#detail.open { display: block; }

.detail-pane { padding: 22px 26px 60px; }
.detail-pane .detail-card { max-width: 640px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); }
.detail-pane .detail-card.wide { max-width: 860px; }
.table-scroll { overflow-x: auto; }
.empty-hint { color: var(--muted); font-size: 13px; padding: 6px 2px; }

.dh {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--panel-bg);
}
.dh .name { font-weight: 700; font-size: 14px; }
.dh .schema { font-size: 11px; color: var(--muted); }
.dh .card { display: flex; flex-direction: column; gap: 2px; }
.dh .close-btn { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 4px; }
.comment { padding: 8px 14px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--border-soft); }
.comment-native-label { display: block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); opacity: 0.8; margin-bottom: 2px; }

/* ---------- Description (entity-level, user-authored) ---------- */
.description-section { padding: 4px 14px 12px; }
.description-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 12.5px;
  font-family: inherit;
  padding: 8px 10px;
  outline: none;
  resize: vertical;
  box-sizing: border-box;
}
.description-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.detail-card table, #detail table { width: 100%; border-collapse: collapse; font-size: 12px; }
.detail-card td, .detail-card th, #detail td, #detail th { text-align: left; padding: 5px 14px; border-bottom: 1px solid var(--border-soft); }
.detail-card th, #detail th { color: var(--muted); font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.03em; }
.detail-card td.type, #detail td.type { color: var(--muted); }
.rel-list { padding: 6px 14px 14px; font-size: 12px; }
.rel-list .rel-item { padding: 4px 0; color: var(--muted); cursor: pointer; }
.rel-list .rel-item:hover { color: var(--accent); }
.rel-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); padding-top: 8px; }
.badge { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: 0.02em; padding: 1px 6px; border-radius: 8px; background: var(--header-bg); color: var(--muted); }
.badge.one-to-one, .badge.pk { color: var(--pk-color); }
.badge.many-to-one, .badge.fk { color: var(--fk-color); }

/* ---------- Relationships tab list ---------- */
.rel-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 14px;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.rel-row:hover { background: var(--header-bg); }
.rel-row.active { background: var(--accent-soft); border-left-color: var(--accent); }
.rel-row.dim { opacity: var(--dim-opacity); }
.rel-row .main-line { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rel-row .sub-line { font-size: 10.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Table detail (full pane) column list ---------- */
.detail-card .col-row { display: flex; align-items: center; gap: 6px; }
.jump-link { color: var(--accent); cursor: pointer; text-decoration: none; }
.jump-link:hover { text-decoration: underline; }

/* ---------- Column-level lineage/description inputs (inline in the columns table) ---------- */
.col-source-input, .col-sourcefield-input, .col-description-input {
  width: 100%;
  min-width: 110px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  padding: 3px 6px;
  outline: none;
}
.col-source-input:hover, .col-sourcefield-input:hover, .col-description-input:hover { border-color: var(--border); background: var(--bg); }
.col-source-input:focus, .col-sourcefield-input:focus, .col-description-input:focus { border-color: var(--accent); background: var(--bg); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- Data lineage (entity owner + source systems, source detail form) ---------- */
.lineage-section { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 12px; }
.lineage-row { display: flex; flex-direction: column; gap: 5px; }
.lineage-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.lineage-row input[type="text"], .lineage-row input[type="url"], .lineage-row textarea, .lineage-row select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
  font-size: 12.5px;
  font-family: inherit;
  padding: 7px 9px;
  outline: none;
  box-sizing: border-box;
  resize: vertical;
}
.lineage-row input:focus, .lineage-row textarea:focus, .lineage-row select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.source-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.source-pill {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 14px;
  padding: 3px 6px 3px 10px;
}
.source-pill-remove { border: none; background: none; color: inherit; cursor: pointer; font-size: 10px; line-height: 1; padding: 3px; opacity: 0.75; }
.source-pill-remove:hover { opacity: 1; }
.source-add-row { display: flex; gap: 6px; margin-top: 6px; }
.source-add-row .source-add-input { flex: 1 1 auto; }
.source-add-row .btn { flex: 0 0 auto; padding: 7px 12px; }

/* ---------- Tags (prioritization labels) ---------- */
.tags-section { padding: 12px 14px 10px; display: flex; flex-direction: column; gap: 6px; }
.tag-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  border-radius: 14px;
  padding: 3px 6px 3px 10px;
}
.tag-pill-remove { border: none; background: none; color: inherit; cursor: pointer; font-size: 10px; line-height: 1; padding: 3px; opacity: 0.75; }
.tag-pill-remove:hover { opacity: 1; }
.tag-add-row { display: flex; gap: 6px; }
.tag-add-row .tag-add-input { flex: 1 1 auto; }
.tag-add-row .btn { flex: 0 0 auto; padding: 7px 12px; }

/* Small, fixed-size, text-free markers on the canvas table header - the
   header height is load-bearing (edge/marker math assumes a fixed row
   height), so this stays a single-line row of dots rather than wrapping
   pills; hover for the tag names via the title attribute. */
.tm-header .tag-dots { display: inline-flex; align-items: center; gap: 3px; flex: 0 0 auto; }
.tag-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; cursor: pointer; }

.tag-red { color: var(--tag-red); background: var(--tag-red-soft); }
.tag-dot.tag-red { background: var(--tag-red); }
.tag-orange { color: var(--tag-orange); background: var(--tag-orange-soft); }
.tag-dot.tag-orange { background: var(--tag-orange); }
.tag-amber { color: var(--tag-amber); background: var(--tag-amber-soft); }
.tag-dot.tag-amber { background: var(--tag-amber); }
.tag-green { color: var(--tag-green); background: var(--tag-green-soft); }
.tag-dot.tag-green { background: var(--tag-green); }
.tag-teal { color: var(--tag-teal); background: var(--tag-teal-soft); }
.tag-dot.tag-teal { background: var(--tag-teal); }
.tag-sky { color: var(--tag-sky); background: var(--tag-sky-soft); }
.tag-dot.tag-sky { background: var(--tag-sky); }
.tag-fuchsia { color: var(--tag-fuchsia); background: var(--tag-fuchsia-soft); }
.tag-dot.tag-fuchsia { background: var(--tag-fuchsia); }
.tag-pink { color: var(--tag-pink); background: var(--tag-pink-soft); }
.tag-dot.tag-pink { background: var(--tag-pink); }
.tag-gray { color: var(--tag-gray); background: var(--tag-gray-soft); }
.tag-dot.tag-gray { background: var(--tag-gray); }

.tag-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-swatch {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.tag-swatch.selected { border-color: var(--text); box-shadow: 0 0 0 2px var(--panel-bg); }

.tag-filter-banner {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 6px 5px 12px;
  font-size: 12px;
  font-weight: 600;
  flex: 0 0 auto;
}
.tag-filter-banner button { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 12px; line-height: 1; padding: 4px; }
.tag-filter-banner button:hover { color: var(--text); }

/* ---------- Comments (entity-level annotations) ---------- */
.comments-section { padding: 10px 14px 14px; border-top: 1px solid var(--border-soft); }
.comment-list { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 10px; }
.comment-item { background: var(--bg); border: 1px solid var(--border-soft); border-radius: 8px; padding: 8px 10px; }
.comment-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.comment-author { font-size: 11.5px; font-weight: 700; color: var(--text); }
.comment-time { font-size: 10.5px; color: var(--muted); flex: 1 1 auto; }
.comment-delete { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 11px; line-height: 1; padding: 2px; flex: 0 0 auto; }
.comment-delete:hover { color: #dc2626; }
.comment-text { font-size: 12.5px; color: var(--text); white-space: pre-wrap; line-height: 1.4; }
.comment-form { display: flex; flex-direction: column; gap: 6px; }
.comment-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
  font-size: 12.5px;
  font-family: inherit;
  padding: 7px 9px;
  outline: none;
  resize: vertical;
  box-sizing: border-box;
}
.comment-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.comment-form .btn { align-self: flex-end; padding: 6px 12px; }

/* ---------- Activity tab ---------- */
.detail-pane .activity-feed { max-width: 720px; display: flex; flex-direction: column; gap: 10px; }
.activity-item {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
}
.activity-item:hover { border-color: var(--accent); }
.activity-item-head { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; flex-wrap: wrap; }
.activity-table {
  font-size: 11px; font-weight: 700; color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 2px 7px;
}
.activity-item .comment-author { font-size: 12px; }
.activity-item .comment-time { flex: 0 0 auto; }
.activity-item .comment-text { font-size: 13px; }

/* ---------- Empty state ---------- */
#empty-state {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  color: var(--muted); font-size: 13px;
}
#empty-state.show { display: flex; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

[x-cloak] { display: none !important; }

/* ---------- Import screen ---------- */
#screen-import {
  height: 100vh;
  overflow-y: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 20px 60px;
}
.import-card {
  position: relative;
  width: 100%;
  max-width: 640px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 32px 32px 28px;
}
.import-card .brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
.import-card .brand .name { font-size: 20px; font-weight: 800; letter-spacing: -0.01em; }
.import-card .brand .tag { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.import-card .lede { color: var(--muted); font-size: 13px; margin-bottom: 22px; }

.field-label { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 18px 0 6px; }
.field-label:first-of-type { margin-top: 0; }

.title-input, .sql-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  padding: 9px 12px;
  outline: none;
  box-sizing: border-box;
}
.title-input:focus, .sql-textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.sql-textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; min-height: 200px; resize: vertical; line-height: 1.5; }

.import-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--header-bg); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:disabled:hover { background: var(--panel-bg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }
.btn.ghost { background: transparent; }
.btn.ghost:disabled:hover { background: transparent; }

.field-hint { font-size: 11.5px; color: var(--muted); margin-top: 6px; line-height: 1.4; }

.import-error {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, #dc2626 12%, var(--panel-bg));
  border: 1px solid color-mix(in srgb, #dc2626 35%, var(--border));
  color: #dc2626;
  font-size: 12.5px;
}

.resume-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 22px;
  font-size: 12.5px;
}
.resume-banner .meta { color: var(--muted); font-size: 11.5px; }
.resume-banner .actions { display: flex; gap: 6px; flex: 0 0 auto; }

.divider-row { display: flex; align-items: center; gap: 10px; margin: 22px 0 4px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.divider-row::before, .divider-row::after { content: ""; flex: 1 1 auto; height: 1px; background: var(--border-soft); }

/* ---------- Project menu (topbar dropdown) ---------- */
.project-menu { position: relative; flex: 0 0 auto; }
.project-menu > .btn { border-radius: 7px; }
.project-menu > .btn.icon-btn { padding: 6px 7px; gap: 4px; }
.project-menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 200px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 40;
}
.project-menu-panel button {
  display: flex; align-items: center; gap: 8px; width: 100%;
  border: none; background: none; color: var(--text);
  font-size: 12.5px; text-align: left;
  padding: 8px 10px; border-radius: 7px; cursor: pointer;
}
.project-menu-panel button:hover { background: var(--header-bg); }
.project-menu-panel .menu-sep { height: 1px; background: var(--border-soft); margin: 5px 2px; }

/* ---------- Theme switch (light / dark / system) ---------- */
.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  flex: 0 0 auto;
}
.theme-switch button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 24px;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
}
.theme-switch button:hover { color: var(--text); }
.theme-switch button.active { background: var(--panel-bg); color: var(--accent); box-shadow: var(--shadow); }
.theme-switch svg { width: 14px; height: 14px; }

.import-card .theme-switch { position: absolute; top: 20px; right: 20px; }
.brand-logo {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 5;
  width: 112px;
  height: 22px;
  background-image: var(--brand-logo);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

@media (max-width: 900px) {
  #topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; row-gap: 8px; }
  #topbar .title { max-width: 50vw; }
  .search-wrap { order: 3; flex: 1 1 100%; max-width: none; }
  .tabs { order: 2; }
}

@media (max-width: 760px) {
  #page-diagrams #sidebar-wrap { position: absolute; left: 0; top: 0; bottom: 0; z-index: 25; box-shadow: var(--shadow-lg); }
  #sidebar-wrap.collapsed { display: none; }
  #detail { width: calc(100% - 28px); }
  .list-nav-wrap { flex: 0 0 220px; max-width: 220px; }
  #page-tables .list-nav-wrap, #page-relationships .list-nav-wrap {
    position: absolute; left: 0; top: 0; bottom: 0; z-index: 5; box-shadow: var(--shadow-lg);
  }
}
