/* ST2 Data Model Browser — styles */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: #1f2328;
  background: #f6f8fa;
}

body { display: flex; flex-direction: column; }

/* ---- Top bar ---- */
#topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: #0b5394;
  color: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  z-index: 10;
}
#topbar .brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.2px;
  flex-shrink: 0;
}
#breadcrumbs {
  flex: 1;
  font-size: 14px;
  color: #d9e6f2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#breadcrumbs a {
  color: #fff;
  text-decoration: none;
  padding: 2px 6px;
  border-radius: 4px;
}
#breadcrumbs a:hover { background: rgba(255,255,255,0.15); }
#breadcrumbs .sep { margin: 0 4px; color: #92b5d4; }
#topbar .search input {
  width: 320px;
  padding: 7px 12px;
  border: 1px solid #0b5394;
  border-radius: 6px;
  font-size: 14px;
  background: rgba(255,255,255,0.95);
  color: #1f2328;
}
#topbar .search input:focus {
  outline: 2px solid #ffc107;
  outline-offset: 1px;
}

/* ---- Layout ---- */
#layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ---- Sidebar ---- */
#sidebar {
  width: 320px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid #d1d9e0;
  overflow-y: auto;
  padding: 12px 0;
}
#search-results {
  border-bottom: 1px solid #d1d9e0;
  padding: 8px 16px 12px;
}
#search-results .header {
  font-weight: 600;
  color: #57606a;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
#search-results .result {
  display: block;
  padding: 4px 8px;
  border-radius: 4px;
  color: #0b5394;
  text-decoration: none;
  font-size: 14px;
}
#search-results .result:hover { background: #eaf2fa; }
#search-results .result .path { color: #8c959f; font-size: 12px; }

#tree { padding: 0 8px; }
#tree .group-label {
  font-size: 11px;
  font-weight: 700;
  color: #57606a;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  padding: 12px 10px 6px;
}
#tree .db {
  display: block;
  padding: 6px 10px;
  border-radius: 6px;
  color: #1f2328;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}
#tree .db:hover { background: #eaf2fa; }
#tree .db.active { background: #0b5394; color: #fff; }
#tree .db .meta {
  font-weight: 400;
  color: #57606a;
  font-size: 12px;
  margin-left: 6px;
}
#tree .db.active .meta { color: #cfd8e3; }
#tree .db.idmp::before { content: "★ "; color: #bf9000; font-size: 12px; }
#tree .db.light .meta { opacity: 0.8; }

#tree ul.tables {
  list-style: none;
  margin: 2px 0 8px 10px;
  padding: 0 0 0 10px;
  border-left: 1px solid #d1d9e0;
}
#tree ul.tables li { padding: 2px 0; }
#tree ul.tables a {
  display: block;
  padding: 3px 8px;
  border-radius: 4px;
  color: #1f2328;
  text-decoration: none;
  font-size: 13px;
  line-height: 1.3;
}
#tree ul.tables a:hover { background: #f0f4f8; }
#tree ul.tables a.active { background: #fff2cc; color: #7f6000; font-weight: 600; }
#tree ul.tables a .t-meta {
  color: #8c959f;
  font-size: 11px;
  margin-left: 4px;
}

/* ---- Content ---- */
#content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px 64px;
  min-width: 0;
}
#content h1 {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 700;
}
#content h2 {
  margin: 28px 0 12px;
  font-size: 18px;
  font-weight: 700;
  color: #24292f;
  padding-bottom: 6px;
  border-bottom: 1px solid #d1d9e0;
}
#content .subtitle {
  color: #57606a;
  font-size: 14px;
  margin-bottom: 2px;
}
#content .blurb {
  background: #eaf2fa;
  border-left: 3px solid #0b5394;
  padding: 10px 14px;
  margin: 14px 0 20px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1.5;
}
#content .blurb.custom { background: #fff2cc; border-left-color: #bf9000; color: #7f6000; }

/* Stat cards */
.stat-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0 8px; }
.stat-card {
  background: #fff;
  border: 1px solid #d1d9e0;
  border-radius: 6px;
  padding: 10px 14px;
  min-width: 120px;
}
.stat-card .n { font-size: 22px; font-weight: 700; color: #0b5394; line-height: 1; }
.stat-card .l { font-size: 12px; color: #57606a; text-transform: uppercase; letter-spacing: 0.4px; margin-top: 4px; }

/* ---- DB / table cards in root & DB views ---- */
.db-grid, .table-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin: 14px 0 24px;
}
.db-card, .table-card {
  display: block;
  background: #fff;
  border: 1px solid #d1d9e0;
  border-radius: 6px;
  padding: 12px 14px;
  color: inherit;
  text-decoration: none;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.db-card:hover, .table-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  border-color: #0b5394;
}
.db-card .name, .table-card .name {
  font-weight: 700;
  font-size: 15px;
  color: #0b5394;
}
.db-card .iso { font-size: 12px; color: #bf9000; font-weight: 600; margin-top: 2px; }
.db-card .desc {
  font-size: 13px;
  color: #57606a;
  margin-top: 6px;
  line-height: 1.4;
}
.db-card.idmp { border-left: 3px solid #bf9000; }
.db-card.light { opacity: 0.85; }
.db-card.light .name { color: #57606a; }
.db-card .stats, .table-card .stats {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: #57606a;
  margin-top: 8px;
}
.db-card .stats span strong, .table-card .stats span strong { color: #24292f; }
.table-card .concept {
  font-size: 12px;
  color: #bf9000;
  font-style: italic;
  margin-top: 2px;
}

/* ---- Table detail ---- */
.col-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid #d1d9e0;
  border-radius: 6px;
  overflow: hidden;
  font-size: 13px;
  margin: 8px 0 20px;
}
.col-table th {
  text-align: left;
  padding: 8px 12px;
  background: #f6f8fa;
  border-bottom: 1px solid #d1d9e0;
  font-weight: 600;
  color: #57606a;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.col-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #eaeef2;
  vertical-align: top;
}
.col-table tr:last-child td { border-bottom: none; }
.col-table tr.pk td { background: #f2f7fc; }
.col-table .badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  margin-right: 4px;
}
.badge.pk { background: #0b5394; color: #fff; }
.badge.fk { background: #6f42c1; color: #fff; }
.badge.xref { background: #0d9488; color: #fff; }
.badge.notnull { background: #d1d9e0; color: #57606a; }
.col-table .colname { font-family: "SF Mono", "Consolas", monospace; font-weight: 600; color: #24292f; }
.col-table .type { font-family: "SF Mono", "Consolas", monospace; color: #57606a; }
.col-table .note {
  font-size: 12px;
  color: #7f6000;
  font-style: italic;
  background: #fffbe6;
  border-radius: 3px;
  padding: 2px 6px;
  display: inline-block;
}
.col-table .fk-target {
  font-size: 12px;
  color: #6f42c1;
}
.col-table .fk-target a { color: #6f42c1; text-decoration: none; border-bottom: 1px dotted #6f42c1; }
.col-table .fk-target a:hover { color: #4b2d80; border-bottom-color: #4b2d80; }
/* Cross-service reference variant: teal, dashed underline to distinguish from real FK */
.col-table .fk-target.xref { color: #0d9488; }
.col-table .fk-target.xref a { color: #0d9488; border-bottom: 1px dashed #0d9488; }
.col-table .fk-target.xref a:hover { color: #0f766e; border-bottom-color: #0f766e; }

/* FK section */
.fk-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 8px 0 16px;
}
.fk-section .fk-list {
  background: #fff;
  border: 1px solid #d1d9e0;
  border-radius: 6px;
  padding: 12px 14px;
  max-height: 420px;
  overflow-y: auto;
}
.fk-section h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: #57606a;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 700;
}
.fk-section ul { list-style: none; margin: 0 0 8px; padding: 0; }
.fk-section li { padding: 4px 0; font-size: 13px; line-height: 1.5; }
.fk-section li a { color: #0b5394; text-decoration: none; }
.fk-section li a:hover { text-decoration: underline; }
.fk-section li .col { font-family: "SF Mono", "Consolas", monospace; font-size: 12px; color: #6f42c1; }
.fk-section li.xref { color: #065f5a; }
.fk-section li.xref .col { color: #0d9488; }
.fk-section li.xref a.xref-link { color: #0d9488; border-bottom: 1px dashed #0d9488; }
.fk-section li.xref a.xref-link:hover { color: #0f766e; border-bottom-color: #0f766e; }
.fk-section .empty { color: #8c959f; font-size: 12px; font-style: italic; }
.fk-section h4.fk-sub {
  margin: 10px 0 4px;
  font-size: 12px;
  color: #24292f;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.fk-section h4.fk-sub:first-child { margin-top: 0; }
.fk-section h4.fk-sub .muted { font-weight: 400; font-size: 11px; margin-left: 4px; }

/* Mermaid panels */
.diagram-wrap {
  background: #fff;
  border: 1px solid #d1d9e0;
  border-radius: 6px;
  padding: 12px;
  overflow: auto;
  margin: 8px 0 20px;
}
.diagram-wrap.compact {
  max-height: 480px;
}
.diagram-wrap.compact svg {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
  /* SVG nodes handle their own clicks (hover + open fullscreen); empty-space
     clicks bubble to the wrapper which also opens fullscreen. */
}
.diagram-wrap.clickable {
  cursor: zoom-in;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.diagram-wrap.clickable:hover {
  border-color: #0b5394;
  box-shadow: 0 2px 8px rgba(11, 83, 148, 0.18);
}
.diagram-wrap.fullsize svg { display: block; }

/* Section header with inline fullscreen button */
.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 28px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid #d1d9e0;
}
.section-header h2 {
  font-size: 18px;
  color: #24292f;
}

/* Clickable ER entities — highlight rect on hover */
.diagram-wrap .er-clickable rect {
  transition: fill 0.12s, stroke-width 0.12s;
}
.diagram-wrap .er-clickable:hover rect {
  fill: #fff7d6 !important;
  stroke: #bf9000 !important;
  stroke-width: 2 !important;
}

/* Fullscreen modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 22, 36, 0.7);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}
.modal-shell {
  background: #f6f8fa;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  width: calc(100vw - 64px);
  height: calc(100vh - 64px);
  max-width: 1800px;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #d1d9e0;
  background: #fff;
  font-size: 14px;
  color: #1f2328;
}
.modal-body {
  flex: 1;
  overflow: auto;
  padding: 16px;
  background: #fff;
  user-select: none;
}
.modal-body.grabbable { cursor: grab; }
.modal-body.grabbing { cursor: grabbing; }
.modal-body.grabbing * { cursor: grabbing !important; }
.modal-body .diagram-wrap {
  border: none;
  padding: 0;
  margin: 0;
  overflow: visible;
}

/* Zoom controls */
.zoom-btn {
  font-size: 14px;
  width: 28px;
  padding: 2px 0;
  text-align: center;
  font-weight: 700;
}
.zoom-label {
  min-width: 44px;
  text-align: center;
  font-size: 13px;
  font-family: "SF Mono", Consolas, monospace;
  color: #57606a;
}

/* SQL button */
.sql-btn {
  display: inline-block;
  padding: 4px 10px;
  font-size: 12px;
  border: 1px solid #d1d9e0;
  border-radius: 4px;
  background: #fff;
  color: #1f2328;
  cursor: pointer;
  font-family: inherit;
  margin-left: 8px;
}
.sql-btn:hover { background: #eaf2fa; border-color: #0b5394; }

/* Toast */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2328;
  color: #fff;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 100;
}
#toast.show { opacity: 0.95; }

/* Empty / loading */
#view-loading, .empty-state {
  text-align: center;
  color: #8c959f;
  margin: 60px 0;
  font-size: 14px;
}

/* Utility */
.muted { color: #8c959f; }
.chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  background: #eaf2fa;
  color: #0b5394;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  margin-left: 6px;
}
.chip.focus { background: #fff2cc; color: #7f6000; }
.chip.light { background: #f0f4f8; color: #57606a; }
