/*
 * XFramework Data Explorer — 樣式
 * 重用 Workspace 的設計 token 與按鈕（@import），只補 Explorer 自身版面。
 */
@import url("../xframework-workspace/styles.css");

/* ── App shell：固定頁首、三欄各自捲動 ─────────────────────── */
html, body { height: 100%; }
body {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.xe-header { flex: none; }
.xe-header-nav { display: flex; align-items: center; gap: 0.7rem; margin-left: auto; }
.xe-auth-state { font-size: 0.85rem; color: var(--ink-muted, #5d6f68); }

.xe-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(230px, 0.75fr) minmax(420px, 1.8fr) minmax(320px, 1.25fr);
  gap: 0;
}
.xe-panel {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.9rem 1rem 1.4rem;
  border-right: 1px solid var(--line, #e0ddd2);
}
.xe-panel:last-child { border-right: 0; }
.xe-panel .panel-heading {
  position: sticky; top: -0.9rem; z-index: 2;
  margin: -0.9rem -1rem 0.7rem; padding: 0.8rem 1rem 0.55rem;
  background: var(--canvas, #f4f1e9);
  display: flex; align-items: center; gap: 0.6rem;
  border-bottom: 1px solid var(--line, #e0ddd2);
}
.xe-panel .panel-heading h2 { margin: 0; font-size: 1rem; }

/* ── 登入 gate ─────────────────────────────────────────────── */
.xe-gate { display: none; flex: 1 1 auto; align-items: center; justify-content: center; padding: 2rem; }
.xe-gate-card { max-width: 34rem; text-align: center; display: grid; gap: 0.8rem; justify-items: center; }
.xe-gate-card h1 { margin: 0; font-size: 1.5rem; }
.xe-gate-card p { margin: 0; color: var(--ink-muted, #5d6f68); }
.xe-gate-pending { display: none; color: var(--ink-muted, #5d6f68); }
.xe-gate-cta { display: none; flex-direction: column; align-items: center; gap: 0.55rem; }
.xe-gate-cta p { font-size: 0.83rem; }

body[data-auth="pending"] .xe-shell, body[data-auth="out"] .xe-shell { display: none; }
body[data-auth="pending"] .xe-gate, body[data-auth="out"] .xe-gate { display: flex; }
body[data-auth="pending"] .xe-gate-pending { display: block; }
body[data-auth="out"] .xe-gate-cta { display: flex; }

/* ── 篩選面板 ─────────────────────────────────────────────── */
.xe-filter-group { margin-bottom: 1.2rem; }
.xe-filter-group h3 {
  margin: 0 0 0.45rem; font-size: 0.82rem; letter-spacing: 0.05em;
  display: flex; align-items: baseline; gap: 0.45rem;
}
.xe-filter-group h3 small { font-weight: 400; color: var(--ink-muted, #8fa09a); letter-spacing: 0; }
.xe-field { display: grid; gap: 0.25rem; margin-bottom: 0.6rem; font-size: 0.85rem; }
.xe-field select, .xe-field input {
  border: 1px solid var(--line, #e0ddd2); border-radius: 8px;
  padding: 0.4rem 0.55rem; font: inherit; background: #fff; width: 100%;
}

.xe-chip-row { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.5rem; }
.xe-chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  border: 1px solid var(--line, #e0ddd2); border-radius: 999px;
  padding: 0.14rem 0.6rem; font-size: 0.78rem; background: #fff;
}
.xe-chip button { border: 0; background: none; cursor: pointer; font-size: 0.85rem; padding: 0; color: inherit; }
.xe-chip-action { cursor: pointer; }
.xe-chip-action:hover { border-color: var(--accent, #1e6b56); }

.xe-facet { border: 1px solid var(--line, #e0ddd2); border-radius: 10px; margin-bottom: 0.45rem; background: #fff; }
.xe-facet summary {
  cursor: pointer; padding: 0.45rem 0.65rem; font-size: 0.84rem; font-weight: 600;
  display: flex; align-items: baseline; gap: 0.5rem; list-style: none;
}
.xe-facet summary::-webkit-details-marker { display: none; }
.xe-facet summary small { font-weight: 400; color: var(--ink-muted, #8fa09a); }
.xe-facet-values { padding: 0 0.5rem 0.5rem; display: flex; flex-direction: column; gap: 2px; }
.xe-facet-value {
  display: flex; justify-content: space-between; align-items: center; gap: 0.5rem;
  border: 1px solid transparent; border-radius: 7px; background: none;
  padding: 0.28rem 0.5rem; font: inherit; font-size: 0.82rem; text-align: left; cursor: pointer;
}
.xe-facet-value:hover { background: var(--accent-soft, #e3ede8); }
.xe-facet-value.is-on { background: var(--accent, #1e6b56); color: #fff; }
.xe-facet-value small { color: inherit; opacity: 0.75; }
.xe-facet-value span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── 紀錄清單 ─────────────────────────────────────────────── */
.xe-api-echo {
  display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.6rem;
  background: #fff; border: 1px dashed var(--line, #e0ddd2); border-radius: 8px;
  padding: 0.35rem 0.6rem; font-size: 0.78rem; overflow-x: auto;
}
.xe-api-echo code { white-space: nowrap; }
.xe-table-wrap { overflow-x: auto; }
#record-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; background: #fff; border-radius: 10px; }
#record-table th {
  text-align: left; padding: 0.45rem 0.6rem; border-bottom: 2px solid var(--line, #e0ddd2);
  font-size: 0.78rem; letter-spacing: 0.03em; white-space: nowrap;
}
#record-table th[data-sort] { cursor: pointer; }
#record-table th[data-sort]:hover { color: var(--accent, #1e6b56); }
#record-table td { padding: 0.42rem 0.6rem; border-bottom: 1px solid var(--line-soft, #ebe8de); vertical-align: top; }
#record-table tbody tr { cursor: pointer; }
#record-table tbody tr:hover { background: var(--accent-soft, #e3ede8); }
#record-table tbody tr.is-selected { background: var(--accent-soft, #e3ede8); box-shadow: inset 3px 0 0 var(--accent, #1e6b56); }
.xe-cell-title { max-width: 20rem; }
.xe-cell-id code { font-size: 0.72rem; color: var(--ink-muted, #8fa09a); }
.xe-type-badge {
  display: inline-block; border-radius: 6px; padding: 0.08rem 0.45rem;
  font-size: 0.72rem; font-weight: 700; background: var(--accent-soft, #e3ede8); color: var(--accent, #1e6b56);
  white-space: nowrap;
}
.xe-type-badge[data-kind="uri"] { background: #f5ece1; color: #96652a; }
.xe-vis[data-visibility="shared"]::before { content: "👥 "; }
.xe-vis[data-visibility="private"]::before { content: "🔒 "; }

/* ── Inspector ─────────────────────────────────────────────── */
.xe-trail { font-size: 0.8rem; margin-bottom: 0.7rem; display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem; }
.xe-inspect-group { margin-bottom: 1.15rem; }
.xe-inspect-group h3 {
  margin: 0 0 0.45rem; font-size: 0.82rem; letter-spacing: 0.05em;
  display: flex; align-items: baseline; gap: 0.45rem;
}
.xe-inspect-group h3 small { font-weight: 400; color: var(--ink-muted, #8fa09a); font-family: ui-monospace, monospace; letter-spacing: 0; }
.xe-summary { width: 100%; border-collapse: collapse; font-size: 0.83rem; }
.xe-summary th {
  text-align: left; white-space: nowrap; padding: 0.28rem 0.6rem 0.28rem 0;
  color: var(--ink-muted, #5d6f68); font-weight: 500; vertical-align: top; width: 6.5rem;
}
.xe-summary td { padding: 0.28rem 0; word-break: break-all; }
.xe-summary code { font-size: 0.76rem; }
.xe-open-row { margin-top: 0.6rem; }

.xe-stack { display: flex; flex-direction: column; gap: 0.4rem; }
.xe-row {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--line, #e0ddd2); border-radius: 9px;
  padding: 0.4rem 0.6rem; font-size: 0.82rem;
}
.xe-row code { font-size: 0.75rem; overflow-wrap: anywhere; }
.xe-ref-row { align-items: flex-start; }
.xe-ref-main { flex: 1 1 12rem; min-width: 0; display: grid; gap: 0.15rem; }
.xe-ref-actions { display: flex; gap: 0.35rem; }
.xe-preview {
  flex-basis: 100%; margin: 0.3rem 0 0; max-height: 16rem; overflow: auto;
  background: var(--canvas, #f4f1e9); border-radius: 8px; padding: 0.55rem;
  font-size: 0.72rem; line-height: 1.45; white-space: pre-wrap; word-break: break-all;
}
.xe-mini-button {
  border: 1px solid var(--line, #e0ddd2); background: #fff; border-radius: 7px;
  padding: 0.18rem 0.55rem; font: inherit; font-size: 0.76rem; cursor: pointer; white-space: nowrap;
}
.xe-mini-button:hover:not(:disabled) { border-color: var(--accent, #1e6b56); color: var(--accent, #1e6b56); }
.xe-mini-button:disabled { opacity: 0.45; cursor: not-allowed; }
.xe-mini-link { font-size: 0.78rem; margin-left: auto; white-space: nowrap; }
.xe-muted { color: var(--ink-muted, #8fa09a); font-size: 0.8rem; margin: 0.15rem 0; }
.xe-group-note { margin: 0 0 0.45rem; font-size: 0.74rem; line-height: 1.5; }
.xe-ref-actions .xe-mini-link { margin-left: 0; align-self: center; }
.xe-warn { color: #a33b2e; }

/* ── Structural Relations（x:rel relation tuples） ───────────── */
.xe-relation {
  display: grid; gap: 0.3rem; padding: 0.5rem 0.6rem;
  border: 1px solid var(--line, #e0ddd2); border-radius: 9px; background: #fff;
}
.xe-relation > .xe-row { border: 0; padding: 0.15rem 0; background: transparent; }
.xe-relation-participant { flex-wrap: wrap; }
.xe-relation-arc small { color: var(--accent, #1e6b56); font-weight: 700; white-space: nowrap; }

/* ── 窄視窗 ────────────────────────────────────────────────── */
@media (max-width: 1080px) {
  body { overflow: auto; display: block; }
  .xe-shell { display: block; }
  .xe-panel { border-right: 0; border-bottom: 1px solid var(--line, #e0ddd2); overflow: visible; height: auto; }
}
