:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-2: #fbfcfe;
  --border: #e4e8ee;
  --border-strong: #d4dae3;
  --text: #1b2430;
  --muted: #6b7886;
  --muted-2: #95a0ad;
  --accent: #1f6feb;
  --accent-weak: #e9f1ff;
  --accent-strong: #1559c7;
  --good: #1a7f5a;
  --good-weak: #e4f6ee;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ---- App shell ---- */
.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  height: 60px;
  background: #0f1b2d;
  color: #fff;
  box-shadow: var(--shadow);
}
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(135deg, #2f81f7, #15c08a);
  display: inline-block;
}
.brand { font-weight: 600; font-size: 16px; letter-spacing: 0.2px; }
.brand small { color: #9fb4cf; font-weight: 400; margin-left: 8px; }
.topbar .spacer { flex: 1; }
.topbar .env-pill {
  font-size: 12px; color: #9fb4cf; border: 1px solid #25344a;
  padding: 4px 10px; border-radius: 999px;
}

.main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 28px 24px 60px; }

/* ---- Headings ---- */
.page-head { display: flex; align-items: baseline; gap: 12px; margin: 4px 0 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; font-weight: 650; }
.page-head .sub { color: var(--muted); font-size: 14px; }

.crumb {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font-size: 14px; padding: 0; margin-bottom: 14px;
}
.crumb:hover { text-decoration: underline; }

/* ---- Model list ---- */
.model-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.model-card {
  display: block; text-decoration: none;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); transition: border-color .15s;
  text-align: left; font: inherit; color: inherit;
}
.model-card:hover { border-color: var(--border-strong); }
.model-card .file { font-weight: 620; font-size: 15px; margin-bottom: 4px; }
.model-card .proj { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.model-card .meta { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted-2); }
.model-card .owner { color: var(--text); }

/* ---- Modal ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal { background: var(--panel); border-radius: 12px; box-shadow: 0 12px 40px rgba(16,24,40,.25); padding: 24px; width: 400px; max-width: 92vw; }
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.modal p { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.btn.danger { background: #e5484d; border-color: #e5484d; color: #fff; }
.btn.danger:hover { background: #c93b40; border-color: #c93b40; color: #fff; }

/* ---- Toolbar (scope toggle + filter + export) ---- */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.segmented { display: inline-flex; background: var(--panel); border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.segmented button {
  border: none; background: transparent; padding: 8px 16px; font-size: 13.5px; cursor: pointer; color: var(--muted);
  border-right: 1px solid var(--border); font-family: inherit;
}
.segmented button:last-child { border-right: none; }
.segmented button.active { background: var(--accent-weak); color: var(--accent-strong); font-weight: 600; }

.search { flex: 1; min-width: 200px; }
.search input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: 8px;
  font-size: 14px; background: var(--panel); color: var(--text); font-family: inherit;
}
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }

.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 14px;
  border: 1px solid var(--border-strong); border-radius: 8px; background: var(--panel);
  color: var(--text); font-size: 13.5px; cursor: pointer; font-family: inherit;
}
.btn:hover { border-color: var(--accent); color: var(--accent-strong); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.btn:disabled { opacity: .5; cursor: default; }
a.btn { text-decoration: none; }

/* ---- Stat chips ---- */
.stats { display: flex; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 18px; min-width: 130px; box-shadow: var(--shadow); }
.stat .n { font-size: 22px; font-weight: 680; }
.stat .l { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---- Model hub: report chooser ---- */
.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; margin-bottom: 22px; }
.report-card {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); text-decoration: none; color: inherit;
  transition: border-color .15s, transform .15s;
}
.report-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.report-name { font-size: 16px; font-weight: 640; color: var(--text); }
.report-desc { font-size: 13px; color: var(--muted); line-height: 1.45; flex: 1; }
.report-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.report-count { font-size: 12.5px; color: var(--muted-2); }
.report-go { color: var(--accent); font-size: 16px; font-weight: 700; }
.model-actions { margin-top: 8px; }

.coord-note { color: var(--muted-2); font-size: 12.5px; margin: 0 0 14px; }

/* ---- BoM group (per structure / wire) ---- */
.bom-group { margin-bottom: 24px; }
.group-head { display: flex; align-items: baseline; gap: 11px; margin-bottom: 9px; flex-wrap: wrap; }
.group-name { font-size: 16px; font-weight: 640; }
.group-id { font-size: 11.5px; }
.group-count { color: var(--muted); font-size: 12.5px; margin-left: auto; }

/* ---- Table ---- */
.table-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; padding: 11px 16px; background: var(--panel-2); color: var(--muted);
  font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 11px 16px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Dropper schedule: wide two-tier table with its own horizontal scroll ---- */
.dropper-wrap { overflow-x: auto; }
.dropper-table { min-width: 100%; }
.dropper-table thead th { text-align: center; white-space: nowrap; }
.dropper-table th, .dropper-table td { border-right: 1px solid var(--border); }
.dropper-table th:last-child, .dropper-table td:last-child { border-right: none; }

/* ---- Documents panel + PDF modal ---- */
.doc-list { display: flex; flex-direction: column; gap: 8px; }
.doc-row {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel-2); color: var(--text); cursor: pointer; font-family: inherit;
}
.doc-row:hover { border-color: var(--accent); background: var(--accent-weak); }
.doc-icon {
  flex: none; font-size: 10px; font-weight: 700; letter-spacing: .04em; color: #fff;
  background: #d0362b; border-radius: 4px; padding: 3px 5px;
}
.doc-text { display: flex; flex-direction: column; min-width: 0; }
.doc-title { font-weight: 600; font-size: 13.5px; }
.doc-file { font-size: 11.5px; color: var(--muted-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.doc-modal-backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(16,24,40,.55);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.doc-modal {
  background: var(--panel); border-radius: 12px; box-shadow: 0 24px 64px rgba(16,24,40,.35);
  width: min(1000px, 96vw); height: min(88vh, 1000px); display: flex; flex-direction: column; overflow: hidden;
}
.doc-modal-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.doc-modal-title { font-weight: 640; font-size: 15px; }
.doc-modal-link { margin-left: auto; font-size: 13px; color: var(--accent-strong); text-decoration: none; white-space: nowrap; }
.doc-modal-link:hover { text-decoration: underline; }
.doc-modal-close { border: none; background: none; font-size: 16px; cursor: pointer; color: var(--muted); padding: 2px 6px; }
.doc-modal-close:hover { color: var(--text); }
.doc-modal-frame { flex: 1; width: 100%; border: none; background: var(--panel-2); }
.mono { font-family: "Cascadia Code", "Consolas", ui-monospace, monospace; font-size: 12.5px; color: var(--muted); }
.asm-name { font-weight: 600; color: var(--text); }
.asm-id { font-size: 11px; color: var(--muted-2); margin-top: 2px; }

.role-tag { display: inline-block; padding: 2px 9px; border-radius: 999px; background: var(--accent-weak); color: var(--accent-strong); font-size: 12px; font-weight: 600; }
.scope-tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.scope-tag.structure { background: #eef0fb; color: #4b4fc4; }
.scope-tag.wire { background: var(--good-weak); color: var(--good); }
.qty { font-weight: 680; }

/* ---- States ---- */
.empty, .loading, .error { padding: 56px 24px; text-align: center; color: var(--muted); }
.empty .big { font-size: 17px; color: var(--text); margin-bottom: 6px; font-weight: 600; }
.error { color: #b42318; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; margin: 0 auto 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Topbar account ---- */
.topbar-user { color: #cdd9ea; font-size: 13px; }
.topbar form { margin: 0; }
.topbar-signout { background: #1b2a40; border: 1px solid #2b3d57; color: #cdd9ea; padding: 6px 12px; border-radius: 7px; font-size: 12.5px; cursor: pointer; font-family: inherit; }
.topbar-signout:hover { border-color: var(--accent); color: #fff; }

/* ---- Login ---- */
.login-page { min-height: 72vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 32px 30px; width: 380px; max-width: 92vw; }
.login-brand { display: flex; align-items: center; gap: 9px; font-weight: 600; color: var(--muted); font-size: 14px; margin-bottom: 18px; }
.login-card h1 { font-size: 22px; margin: 0 0 6px; }
.login-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 18px; }
.login-form label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; }
.login-input { width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 8px; font-size: 14px; background: var(--panel); color: var(--text); font-family: inherit; }
.login-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.login-btn { width: 100%; margin-top: 18px; padding: 11px; background: var(--accent); color: #fff; border: none; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit; }
.login-btn:hover { background: var(--accent-strong); }
.login-error { background: #fdecea; border: 1px solid #f5c2bc; color: #b42318; padding: 9px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 6px; }
.login-qr { display: block; width: 190px; height: 190px; margin: 6px auto 12px; border: 1px solid var(--border); border-radius: 8px; }
.login-manual { font-size: 12px; color: var(--muted); text-align: center; margin-bottom: 6px; word-break: break-all; }
.login-manual code { background: var(--panel-2); padding: 2px 6px; border-radius: 5px; font-family: "Cascadia Code", Consolas, monospace; }

/* ============================================================
   Catalogue explorer
   ============================================================ */

/* ---- Topbar nav ---- */
.topbar-nav { display: flex; align-items: center; gap: 4px; margin-left: 18px; }
.topbar-link {
  color: #9fb4cf; text-decoration: none; font-size: 13.5px; padding: 6px 12px; border-radius: 7px;
}
.topbar-link:hover { color: #fff; background: #1b2a40; }
.topbar-link.active { color: #fff; background: #1b2a40; font-weight: 600; }

/* ---- Catalogue picker cards (anchor variant of model-card) ---- */
.cat-card { text-decoration: none; display: block; }
.cat-card .proj { min-height: 18px; }

.access-tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.access-tag.public { background: var(--good-weak); color: var(--good); }
.access-tag.restricted { background: #fdf0e6; color: #b5713c; }

/* ---- Browse: role rail + item list ---- */
.browse { display: grid; grid-template-columns: 230px 1fr; gap: 22px; align-items: start; }

.role-rail { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 16px; }
.role-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; text-align: left; background: none; border: none; cursor: pointer;
  padding: 9px 12px; border-radius: 8px; font-size: 14px; color: var(--text); font-family: inherit;
}
.role-item:hover { background: var(--panel); }
.role-item.active { background: var(--accent-weak); color: var(--accent-strong); font-weight: 600; }
.role-count { font-size: 12px; color: var(--muted-2); font-variant-numeric: tabular-nums; }
.role-item.active .role-count { color: var(--accent-strong); }

.role-items { min-width: 0; }
.role-items .search { margin-bottom: 14px; }

.item-list { display: flex; flex-direction: column; gap: 8px; }
.item-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 13px 16px; text-decoration: none; color: inherit; box-shadow: var(--shadow);
  transition: border-color .12s;
}
.item-row:hover { border-color: var(--accent); }
.item-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.item-name { font-weight: 620; font-size: 14.5px; }
.item-id { font-size: 11px; color: var(--muted-2); }
.item-tags { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ---- Status tags ---- */
.status-tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.status-tag.live { background: var(--good-weak); color: var(--good); }
.status-tag.deprecated { background: #fdeede; color: #a4620a; }

/* ---- Item detail ---- */
.detail-head { margin: 4px 0 20px; }
.detail-head h1 { font-size: 24px; margin: 0 0 8px; font-weight: 650; }
.detail-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.detail-layout { display: grid; grid-template-columns: 1fr 340px; gap: 24px; align-items: start; }
.detail-main { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.detail-side { display: flex; flex-direction: column; gap: 18px; position: sticky; top: 16px; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 14px; font-weight: 600; }
.panel .table-wrap { box-shadow: none; }

/* ---- Parameter grid ---- */
.param-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 24px; }
.param { display: flex; flex-direction: column; gap: 3px; }
.param-label { font-size: 12px; color: var(--muted); }
.param-value { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.param-schema { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.param-schema span { color: var(--text); font-weight: 600; }
.param-schema em { font-style: normal; color: var(--muted-2); font-weight: 400; margin-right: 5px; text-transform: uppercase; font-size: 10.5px; letter-spacing: .04em; }

/* ---- Relationship groups ---- */
.rel-group { margin-bottom: 14px; }
.rel-group:last-child { margin-bottom: 0; }
.rel-head { font-size: 13px; font-weight: 640; margin-bottom: 8px; display: flex; align-items: baseline; gap: 8px; }
.rel-count { font-size: 11px; color: var(--muted-2); font-weight: 500; font-variant-numeric: tabular-nums; }
.rel-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-block; padding: 4px 10px; border-radius: 7px; font-size: 12.5px;
  background: var(--accent-weak); color: var(--accent-strong); text-decoration: none; border: 1px solid transparent;
}
a.chip:hover { border-color: var(--accent); }
.chip.static { background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }

/* ---- 3D preview frame ---- */
.preview-frame {
  aspect-ratio: 16 / 10; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  background: linear-gradient(160deg, #f0f4fa, #e6ecf5); box-shadow: var(--shadow);
}
.preview-empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; }
.preview-badge { width: 44px; height: 44px; border-radius: 12px; background: var(--panel); color: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; box-shadow: var(--shadow); }
.preview-note { font-size: 13px; color: var(--muted); }
.preview-sub { font-size: 12px; color: var(--muted-2); max-width: 80%; }

/* ---- Small utilities ---- */
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.link { color: var(--accent); text-decoration: none; }
.link:hover { text-decoration: underline; }

/* ---- Home landing ---- */
.home { max-width: 880px; margin: 0 auto; padding: 20px 0; }
.home-hero { text-align: center; margin: 28px 0 40px; }
.home-hero h1 { font-size: 30px; font-weight: 680; margin: 0 0 8px; }
.home-sub { color: var(--muted); font-size: 15px; margin: 0; }
.home-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.home-card {
  display: flex; flex-direction: column; gap: 12px; text-decoration: none; color: inherit;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 26px 24px;
  box-shadow: var(--shadow); transition: border-color .15s, transform .15s;
}
.home-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.home-card-head { display: flex; align-items: center; gap: 12px; }
.home-card-badge {
  width: 40px; height: 40px; border-radius: 11px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-weak); color: var(--accent-strong); font-size: 19px;
}
.home-card h2 { font-size: 18px; margin: 0; font-weight: 640; }
.home-card p { color: var(--muted); font-size: 13.5px; line-height: 1.55; margin: 0; flex: 1; }
.home-card-go { color: var(--accent); font-size: 13.5px; font-weight: 600; }

@media (max-width: 860px) {
  .home-cards { grid-template-columns: 1fr; }
  .browse { grid-template-columns: 1fr; }
  .role-rail { flex-direction: row; flex-wrap: wrap; position: static; }
  .role-item { width: auto; }
  .detail-layout { grid-template-columns: 1fr; }
  .detail-side { position: static; }
  .param-grid { grid-template-columns: 1fr; }
}

/* Blazor reconnection + error UI */
#blazor-error-ui {
  background: #fff3cd; color: #664d03; bottom: 0; box-shadow: 0 -1px 4px rgba(0,0,0,.1);
  display: none; left: 0; padding: 10px 16px; position: fixed; width: 100%; z-index: 1000; font-size: 13px;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 12px; top: 8px; }
