body[data-page-kind="ley-graph"] {
  --graph-panel-bg: var(--surface-raised);
  --graph-panel-muted: var(--text-muted);
  --graph-panel-border: var(--border-color);
  --graph-panel-shadow: 0 14px 38px rgba(27, 42, 58, 0.08);
  --graph-node-origin: #c93870;
  --graph-node-origin-border: #8f1f4d;
  --graph-node-articles: #0f8a6b;
  --graph-node-law: #b27a2c;
}

:root[data-theme="dark"] body[data-page-kind="ley-graph"] {
  --graph-panel-shadow: 0 20px 40px rgba(0, 0, 0, 0.28);
  --graph-node-origin: #ea5d93;
  --graph-node-articles: #28b28b;
  --graph-node-law: #d7a25b;
}

.graph-shell {
  width: 100%;
  max-width: 1640px;
  margin: 0 auto;
}

.graph-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
}

.graph-field {
  min-width: 120px;
}

.graph-field label {
  display: block;
  font-size: 0.79rem;
  font-weight: 700;
}

.graph-field--search {
  flex: 1 1 280px;
  min-width: 220px;
}

.graph-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

.graph-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 1rem;
  align-items: start;
}

#cy {
  width: 100%;
  height: calc(100vh - 290px);
  min-height: 620px;
  border: 1px solid var(--graph-panel-border);
  border-radius: 12px;
  background: var(--bg-surface-2);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.graph-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.38rem 0.72rem;
  border-radius: 999px;
  border: 1px solid var(--chip-neutral-border);
  background: var(--chip-neutral-bg);
  color: inherit;
  font-size: 0.8rem;
}

.graph-chip::before {
  content: "";
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 999px;
  background: currentColor;
}

.graph-chip--origin {
  color: var(--graph-node-origin);
}

.graph-chip--articles {
  color: var(--graph-node-articles);
}

.graph-chip--law {
  color: var(--graph-node-law);
}

.graph-sidepanel {
  position: sticky;
  top: 5.5rem;
  max-height: calc(100vh - 6.5rem);
  overflow: auto;
  padding: 1rem;
  border: 1px solid var(--graph-panel-border);
  border-radius: 12px;
  background: var(--graph-panel-bg);
  box-shadow: var(--graph-panel-shadow);
}

.graph-sidepanel__empty {
  min-height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.graph-detail-title,
.graph-relation-card__top,
.graph-linked-item__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.graph-detail-subtitle,
.graph-loading,
.graph-empty {
  color: var(--graph-panel-muted);
  font-size: 0.84rem;
}

.graph-detail-badges,
.graph-linked-actions,
.graph-relation-card__meta,
.graph-relation-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.graph-detail-badge,
.graph-mini-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.2rem;
  padding: 0.28rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--chip-neutral-border);
  background: var(--chip-neutral-bg);
  color: var(--chip-neutral-text);
  font-size: 0.74rem;
}

.graph-detail-badge--origin {
  border-color: var(--chip-info-bg);
  background: var(--chip-info-bg);
  color: var(--chip-info-text);
}

.graph-detail-badge--articles {
  border-color: var(--chip-success-bg);
  background: var(--chip-success-bg);
  color: var(--chip-success-text);
}

.graph-detail-badge--law {
  border-color: var(--chip-warning-bg);
  background: var(--chip-warning-bg);
  color: var(--chip-warning-text);
}

.graph-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin-bottom: 1rem;
}

.graph-stat,
.graph-relation-card {
  padding: 0.72rem 0.78rem;
  border: 1px solid var(--graph-panel-border);
  border-radius: 12px;
  background: rgba(127, 140, 153, 0.05);
}

.graph-stat span {
  display: block;
  margin-top: 0.16rem;
  color: var(--graph-panel-muted);
  font-size: 0.76rem;
}

.graph-action-link,
.graph-neighbor-button {
  display: grid;
  gap: 0.12rem;
  min-width: 0;
  padding: 0.72rem 0.82rem;
  border: 1px solid var(--graph-panel-border);
  border-radius: 10px;
  background: rgba(127, 140, 153, 0.05);
  color: inherit;
}

.graph-action-link:hover,
.graph-action-link:focus,
.graph-neighbor-button:hover,
.graph-neighbor-button:focus {
  border-color: var(--accent-color);
  text-decoration: none;
}

.graph-section + .graph-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--graph-panel-border);
}

.graph-neighbor-list,
.graph-relation-list {
  display: grid;
  gap: 0.55rem;
}

.graph-neighbor-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 0.45rem;
  align-items: center;
}

.mley-modal-ad-shell {
  margin-top: 1rem;
}

@media (max-width: 1419.98px) {
  .graph-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .graph-sidepanel {
    position: static;
    max-height: none;
  }
}

@media (max-width: 991.98px) {
  .graph-shell {
    width: 100%;
    max-width: 100%;
    padding-left: 0;
    padding-right: 0;
  }

  .graph-shell .card {
    border-radius: 0;
  }

  #cy {
    height: calc(100vh - 340px);
    min-height: 500px;
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  .graph-sidepanel {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }
}

/* Compact document graph; article graphs retain their own card styles. */
.norm-graph-card { margin-top:0 !important; }
.norm-graph-header { display:flex; align-items:center; justify-content:space-between; gap:1rem; padding-bottom:.75rem; border-bottom:1px solid var(--graph-panel-border); }
.norm-graph-heading { min-width:0; }
.norm-graph-heading h1 { font-size:1.2rem; line-height:1.35; margin:0 0 .2rem; overflow-wrap:anywhere; }
.norm-graph-law-link { color:var(--text-muted); font-size:.8rem; text-decoration:underline; text-underline-offset:3px; }
.norm-graph-law-link:hover { color:var(--accent-color); }
.norm-graph-modes { display:inline-flex; align-items:center; flex-shrink:0; gap:3px; padding:3px; border:1px solid var(--graph-panel-border); border-radius:10px; background:var(--bg-surface-2); }
.norm-graph-modes a,.norm-graph-modes span { padding:.35rem .6rem; border-radius:7px; font-size:.8rem; white-space:nowrap; color:var(--text-muted); }
.norm-graph-modes [aria-current="page"] { background:var(--surface-raised); color:var(--accent-color); font-weight:600; box-shadow:0 1px 3px rgba(0,0,0,.08); }
.norm-graph-card .graph-toolbar { position:relative; align-items:center; margin:.75rem 0; gap:.5rem; }
.norm-graph-card .btn { min-height:34px; border-radius:8px; font-size:.82rem; }
.norm-graph-search { display:flex; align-items:center; gap:.5rem; min-width:0; margin:0 auto 0 0; flex:1; max-width:600px; }
.norm-graph-search input { min-width:0; width:0; flex:1; height:34px; }
.norm-graph-filters > summary { display:flex; align-items:center; gap:.45rem; list-style:none; cursor:pointer; }
.norm-graph-filters > summary::-webkit-details-marker,.norm-graph-legend-panel > summary::-webkit-details-marker { display:none; }
.norm-graph-filters[open] > summary { border-color:var(--accent-color); color:var(--accent-color); }
.norm-graph-filters:not([open]) .norm-graph-filter-panel { display:none; }
.norm-graph-filter-count { min-width:1.3rem; border-radius:1rem; text-align:center; background:var(--accent-color); color:var(--surface-raised); font-size:.75rem; }
.norm-graph-filter-panel { position:absolute; top:calc(100% + 8px); right:0; z-index:12; width:min(460px,100%); padding:1rem; border:1px solid var(--graph-panel-border); border-radius:12px; background:var(--surface-raised); box-shadow:var(--graph-panel-shadow); }
.norm-graph-panel-heading { display:flex; align-items:center; justify-content:space-between; gap:.75rem; font-size:.9rem; }
.norm-graph-panel-heading button { font-size:1.2rem !important; line-height:1; }
.norm-graph-filter-fields { display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1fr); gap:.75rem; margin:.75rem 0; }
.norm-graph-filter-fields label { font-size:.8rem; min-width:0; margin:0; }
.norm-graph-filter-fields .form-control { min-width:0; max-width:100%; }
.norm-graph-filter-help { grid-column:1 / -1; font-size:.75rem; color:var(--text-muted); margin:-.35rem 0 0; }
.norm-graph-filter-actions { display:flex; flex-wrap:wrap; gap:.5rem; }
.norm-graph-filter-summary,.norm-graph-status { font-size:.78rem; color:var(--text-muted); margin:0 0 .65rem; overflow-wrap:anywhere; }
.norm-graph-status.is-error { color:var(--danger-color,#bb3434); }
.norm-graph-card .graph-workspace { display:block; position:relative; }
.norm-graph-card .graph-stage { position:relative; min-width:0; }
.norm-graph-card #cy { min-height:360px; height:clamp(360px,calc(100dvh - 275px),1100px); border:1px solid var(--graph-panel-border); border-radius:12px; touch-action:none; }
.norm-graph-map-tools { position:absolute; right:12px; bottom:12px; display:flex; gap:2px; padding:3px; border:1px solid var(--graph-panel-border); border-radius:10px; background:var(--surface-raised); box-shadow:0 2px 8px rgba(0,0,0,.08); }
.norm-graph-map-tools .btn { background:transparent; border:0; }
.norm-graph-map-tools #graphZoomIn,.norm-graph-map-tools #graphZoomOut { min-width:34px; font-size:1.1rem; }
.norm-graph-card .graph-sidepanel { position:absolute; top:0; right:0; bottom:0; z-index:8; display:flex; flex-direction:column; width:min(340px,100%); max-height:100%; border:1px solid var(--graph-panel-border); border-radius:12px; padding:0; overflow:hidden; }
.graph-sidepanel > .norm-graph-panel-heading { flex-shrink:0; padding:.7rem .9rem; border-bottom:1px solid var(--graph-panel-border); }
.graph-details-content { overflow:auto; overscroll-behavior:contain; min-height:0; padding:.9rem; overflow-wrap:anywhere; }
.graph-details-content h5 { font-size:1.05rem; }
.graph-details-content .graph-detail-title { flex-wrap:wrap; }
.graph-details-content .graph-stats { margin-top:.75rem; }
.norm-graph-footer { display:flex; align-items:center; flex-wrap:wrap; justify-content:space-between; gap:.4rem 1rem; margin-top:.6rem; }
.norm-graph-counts { font-size:.73rem; color:var(--text-muted); margin:0; }
.norm-graph-legend-panel > summary { display:none; cursor:pointer; list-style:none; font-size:.8rem; color:var(--text-muted); }
.norm-graph-card .graph-legend { gap:.4rem .8rem; }
.norm-graph-card .graph-chip { border:0; background:transparent; padding:0; font-size:.72rem; gap:.35rem; }
.norm-graph-card [hidden] { display:none !important; }
.norm-graph-card :focus-visible { outline:3px solid var(--accent-color); outline-offset:3px; }
@media(max-width:991.98px) {
  body[data-page-kind="ley-graph"] .graph-shell .norm-graph-card { border-radius:12px; }
}
@media(max-width:767px) {
  .norm-graph-header { flex-wrap:wrap; gap:.65rem; }
  .norm-graph-heading h1 { font-size:1.1rem; }
  .norm-graph-card .graph-toolbar { flex-wrap:wrap; }
  .norm-graph-search { flex-basis:100%; max-width:none; margin:0; }
  .norm-graph-filters { margin-left:auto; }
  .norm-graph-card .btn { min-height:38px; }
  .norm-graph-card #cy { min-height:380px; height:clamp(380px,calc(100dvh - 340px),800px); }
  .norm-graph-card .graph-sidepanel { top:auto; left:0; width:100%; height:75%; max-height:75%; }
}
@media(max-width:639px) {
  .norm-graph-filter-fields { grid-template-columns:minmax(0,1fr); }
  .norm-graph-footer { display:block; }
  .norm-graph-legend-panel { margin-top:.3rem; }
  .norm-graph-legend-panel > summary { display:flex; justify-content:space-between; padding:.4rem 0; }
  .norm-graph-legend-panel > summary::after { content:"+"; }
  .norm-graph-legend-panel[open] > summary::after { content:"−"; }
  .norm-graph-legend-panel .graph-legend { padding:.4rem 0; }
}
