:root {
  color-scheme: dark;
  --bg: #090d19;
  --panel: rgba(17, 24, 39, 0.78);
  --panel-solid: #111827;
  --panel-2: #182133;
  --panel-3: #202b40;
  --text: #f7f8fb;
  --muted: #9ca8bb;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --accent: #78e3c3;
  --accent-2: #7aa7ff;
  --accent-soft: rgba(120, 227, 195, 0.13);
  --warning: #f5c76d;
  --danger: #ff7f91;
  --success: #63d7a7;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
  --sidebar: 250px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  background:
    radial-gradient(circle at 90% 0%, rgba(72, 110, 255, 0.12), transparent 34rem),
    radial-gradient(circle at 0% 20%, rgba(72, 220, 181, 0.08), transparent 30rem),
    var(--bg);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent-2); outline-offset: 2px;
}
.hidden { display: none !important; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); padding: 24px 18px;
  border-right: 1px solid var(--line); background: rgba(10, 15, 28, 0.9); backdrop-filter: blur(24px);
  display: flex; flex-direction: column; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 26px; }
.brand.compact { padding: 0; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; position: relative;
  background: linear-gradient(145deg, rgba(120,227,195,.22), rgba(122,167,255,.2)); border: 1px solid rgba(120,227,195,.35);
  box-shadow: inset 0 0 22px rgba(120, 227, 195, 0.08);
}
.brand-mark span:first-child { font-weight: 800; font-size: 20px; transform: translateX(-4px); }
.brand-mark span:last-child { position: absolute; font-size: 8px; font-weight: 900; letter-spacing: -.5px; transform: translate(8px, 6px); color: var(--accent); }
.brand strong { display: block; font-size: 15px; letter-spacing: .2px; }
.brand small { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; }

.nav-list { display: grid; gap: 6px; }
.nav-item {
  width: 100%; border: 0; background: transparent; color: var(--muted); border-radius: 12px; padding: 11px 12px;
  display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 8px; text-align: left;
}
.nav-item span { font-size: 18px; text-align: center; }
.nav-item b { font-size: 13px; font-weight: 650; }
.nav-item em { font-style: normal; min-width: 21px; padding: 2px 6px; text-align: center; border-radius: 99px; background: rgba(255,127,145,.14); color: var(--danger); font-size: 10px; }
.nav-item:hover { color: var(--text); background: rgba(255,255,255,.04); }
.nav-item.is-active { color: var(--text); background: linear-gradient(90deg, rgba(120,227,195,.12), rgba(122,167,255,.06)); box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-footer { margin-top: auto; padding: 14px 8px 0; border-top: 1px solid var(--line); display: grid; gap: 12px; }
.offline-state { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.offline-state i { width: 7px; height: 7px; border-radius: 50%; background: var(--warning); box-shadow: 0 0 12px currentColor; }
.offline-state i.online { background: var(--success); }

.workspace { margin-left: var(--sidebar); min-height: 100vh; padding: 26px 34px 56px; }
.topbar { max-width: 1440px; margin: 0 auto 26px; display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.eyebrow { margin: 0 0 7px; color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: 1.8px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(26px, 3vw, 38px); letter-spacing: -1.2px; }
h2 { font-size: 21px; letter-spacing: -.4px; }
h3 { font-size: 15px; }
.topbar-actions { display: flex; gap: 10px; }
.view { max-width: 1440px; margin: 0 auto; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.primary-button, .secondary-button, .danger-button, .icon-button {
  border-radius: 11px; min-height: 40px; border: 1px solid transparent; color: var(--text); padding: 0 15px; font-weight: 700; font-size: 12px;
}
.primary-button { background: linear-gradient(135deg, #4fcba6, #648ff7); color: #06121b; box-shadow: 0 9px 25px rgba(75, 194, 176, .18); }
.primary-button:hover { filter: brightness(1.08); }
.secondary-button { background: rgba(255,255,255,.045); border-color: var(--line); }
.secondary-button:hover { background: rgba(255,255,255,.08); }
.danger-button { background: rgba(255,127,145,.12); color: var(--danger); border-color: rgba(255,127,145,.22); }
.icon-button { width: 40px; padding: 0; background: rgba(255,255,255,.05); border-color: var(--line); font-size: 21px; }
.icon-button.primary { background: linear-gradient(135deg, #4fcba6, #648ff7); color: #06121b; }

.hero {
  position: relative; overflow: hidden; display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(300px, .55fr); gap: 24px;
  border: 1px solid var(--line); border-radius: 24px; background: linear-gradient(135deg, rgba(24,33,51,.92), rgba(12,18,32,.92)); padding: 30px; box-shadow: var(--shadow);
}
.hero::after { content: ""; position: absolute; width: 360px; height: 360px; border-radius: 50%; right: -170px; top: -230px; border: 1px solid rgba(120,227,195,.25); box-shadow: 0 0 0 40px rgba(120,227,195,.025), 0 0 0 90px rgba(122,167,255,.02); }
.hero h2 { max-width: 780px; font-size: clamp(24px, 3vw, 42px); margin: 0 0 12px; line-height: 1.08; letter-spacing: -1.6px; }
.hero p { color: var(--muted); line-height: 1.7; max-width: 720px; }
.hero-actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.health-ring { width: 190px; aspect-ratio: 1; border-radius: 50%; margin: auto; display: grid; place-items: center; position: relative; background: conic-gradient(var(--accent) calc(var(--health) * 1%), rgba(255,255,255,.07) 0); }
.health-ring::before { content: ""; width: 150px; height: 150px; border-radius: 50%; position: absolute; background: #111929; box-shadow: inset 0 0 34px rgba(0,0,0,.24); }
.health-ring div { position: relative; text-align: center; }
.health-ring strong { display: block; font-size: 42px; letter-spacing: -2px; }
.health-ring span { display: block; color: var(--muted); font-size: 11px; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; margin: 18px 0; }
.stat-card, .panel, .entity-card, .issue-card, .timeline-card, .setting-card {
  border: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(18px); border-radius: var(--radius); box-shadow: 0 12px 34px rgba(0,0,0,.12);
}
.stat-card { padding: 18px; }
.stat-card small { color: var(--muted); font-size: 11px; }
.stat-card strong { display: block; margin-top: 9px; font-size: 29px; letter-spacing: -1px; }
.stat-card .trend { margin-top: 8px; color: var(--accent); font-size: 10px; }
.dashboard-grid { display: grid; grid-template-columns: 1.15fr .85fr; gap: 18px; }
.panel { padding: 22px; }
.panel-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; margin-bottom: 16px; }
.panel-header h2, .panel-header h3 { margin-bottom: 4px; }
.panel-header p { color: var(--muted); font-size: 11px; margin-bottom: 0; }

.type-strip { display: grid; gap: 9px; }
.type-row { display: grid; grid-template-columns: 110px 1fr 34px; gap: 12px; align-items: center; }
.type-row label { color: var(--muted); font-size: 11px; }
.progress { height: 7px; background: rgba(255,255,255,.06); border-radius: 99px; overflow: hidden; }
.progress span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.type-row b { font-size: 11px; text-align: right; }

.recent-list { display: grid; gap: 8px; }
.recent-item { width: 100%; background: rgba(255,255,255,.025); border: 1px solid var(--line); border-radius: 12px; padding: 12px; color: inherit; text-align: left; display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; }
.recent-item:hover { background: rgba(255,255,255,.05); }
.recent-item .meta { min-width: 0; }
.recent-item strong { display: block; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-item small { color: var(--muted); font-size: 10px; }
.recent-item time { color: var(--muted); font-size: 9px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.search-box { flex: 1 1 260px; position: relative; }
.search-box input { width: 100%; min-height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 0 14px 0 40px; }
.search-box::before { content: "⌕"; position: absolute; left: 14px; top: 9px; color: var(--muted); font-size: 20px; }
.filter-select { min-height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-solid); color: var(--text); padding: 0 12px; }
.entity-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; }
.entity-card { padding: 17px; transition: transform .18s ease, border-color .18s ease; }
.entity-card:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.entity-card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.entity-card h3 { margin-bottom: 8px; }
.entity-card p { color: var(--muted); line-height: 1.55; font-size: 11px; min-height: 52px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.entity-card-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.entity-card-footer small { color: var(--muted); font-size: 9px; }
.text-button { border: 0; background: transparent; color: var(--accent); font-size: 10px; font-weight: 800; padding: 5px; }

.badge, .type-badge, .status-badge, .severity-badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 99px; padding: 5px 8px; font-size: 9px; font-weight: 800; letter-spacing: .3px; }
.type-badge { background: rgba(122,167,255,.1); color: #a9c5ff; border: 1px solid rgba(122,167,255,.16); }
.status-badge { background: rgba(255,255,255,.05); color: var(--muted); border: 1px solid var(--line); }
.status-badge.active, .status-badge.approved, .status-badge.validated { color: var(--success); background: rgba(99,215,167,.09); }
.status-badge.review, .status-badge.proposed { color: var(--warning); background: rgba(245,199,109,.09); }
.status-badge.invalidated, .status-badge.archived { color: var(--danger); background: rgba(255,127,145,.09); }

.empty-state { border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 50px 22px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; color: var(--text); margin-bottom: 7px; }
.empty-state .symbol { font-size: 38px; color: var(--accent); margin-bottom: 12px; }

.issue-summary { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; margin-bottom: 18px; }
.issue-summary .stat-card { display: flex; align-items: center; gap: 14px; }
.issue-summary .stat-card strong { margin: 0; }
.issue-list { display: grid; gap: 10px; }
.issue-card { padding: 15px; display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: flex-start; }
.issue-card.error { border-left: 3px solid var(--danger); }
.issue-card.warning { border-left: 3px solid var(--warning); }
.issue-card.info { border-left: 3px solid var(--accent-2); }
.issue-card h3 { margin: 0 0 5px; font-size: 13px; }
.issue-card p { color: var(--muted); margin: 0; font-size: 11px; line-height: 1.5; }
.issue-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); font-size: 9px; }
.severity-badge.error { color: var(--danger); background: rgba(255,127,145,.1); }
.severity-badge.warning { color: var(--warning); background: rgba(245,199,109,.1); }
.severity-badge.info { color: var(--accent-2); background: rgba(122,167,255,.1); }

.graph-shell { position: relative; min-height: 650px; overflow: auto; border: 1px solid var(--line); border-radius: 22px; background: rgba(7,11,20,.62); }
.graph-canvas { position: relative; min-width: 1100px; min-height: 650px; }
.graph-canvas svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.graph-edge { stroke: rgba(145,160,190,.36); stroke-width: 1.4; fill: none; marker-end: url(#arrow); }
.graph-edge-label { fill: #748198; font-size: 9px; }
.graph-node { position: absolute; width: 180px; min-height: 84px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: #141d2d; color: var(--text); box-shadow: 0 12px 30px rgba(0,0,0,.22); text-align: left; }
.graph-node:hover { border-color: rgba(120,227,195,.45); }
.graph-node strong { display: block; margin-top: 8px; font-size: 11px; line-height: 1.35; }
.graph-legend { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

.timeline { position: relative; padding-left: 24px; }
.timeline::before { content: ""; position: absolute; left: 7px; top: 5px; bottom: 5px; width: 1px; background: var(--line-strong); }
.timeline-card { position: relative; padding: 15px; margin-bottom: 10px; }
.timeline-card::before { content: ""; position: absolute; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); left: -22px; top: 19px; box-shadow: 0 0 0 5px var(--bg); }
.timeline-card h3 { margin: 0 0 5px; }
.timeline-card p { color: var(--muted); font-size: 11px; margin-bottom: 7px; }
.timeline-card time { color: var(--muted); font-size: 9px; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.setting-card { padding: 20px; }
.setting-card p { color: var(--muted); font-size: 11px; line-height: 1.6; }
.setting-actions { display: flex; gap: 9px; flex-wrap: wrap; }
.file-button { position: relative; overflow: hidden; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.about-list { display: grid; grid-template-columns: 1fr auto; gap: 9px; font-size: 11px; }
.about-list span { color: var(--muted); }

.modal, .detail-panel { border: 1px solid var(--line-strong); background: #111827; color: var(--text); box-shadow: 0 28px 100px rgba(0,0,0,.55); }
.modal { width: min(680px, calc(100vw - 26px)); border-radius: 20px; padding: 0; }
.modal.small { width: min(500px, calc(100vw - 26px)); }
.modal.tiny { width: min(410px, calc(100vw - 26px)); padding: 20px; }
.modal::backdrop, .detail-panel::backdrop { background: rgba(3,7,15,.72); backdrop-filter: blur(5px); }
.modal form { padding: 22px; }
.modal-header { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 18px; }
.modal-header h2 { margin-bottom: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid.one-column { grid-template-columns: 1fr; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { color: var(--muted); font-size: 10px; font-weight: 700; display: grid; gap: 7px; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; background: #0d1422; color: var(--text); padding: 11px; resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }

.detail-panel { width: min(680px, 100vw); height: 100vh; max-height: 100vh; margin: 0 0 0 auto; border-radius: 20px 0 0 20px; padding: 0; }
.detail-wrap { min-height: 100%; display: flex; flex-direction: column; }
.detail-header { padding: 24px; border-bottom: 1px solid var(--line); }
.detail-header-top { display: flex; justify-content: space-between; gap: 12px; }
.detail-header h2 { margin: 14px 0 8px; font-size: 26px; }
.detail-header p { color: var(--muted); line-height: 1.6; font-size: 12px; }
.detail-body { padding: 22px 24px 40px; overflow-y: auto; }
.detail-section { margin-bottom: 24px; }
.detail-section h3 { color: var(--muted); font-size: 10px; letter-spacing: 1px; text-transform: uppercase; }
.relation-list { display: grid; gap: 8px; }
.relation-item { border: 1px solid var(--line); background: rgba(255,255,255,.025); border-radius: 12px; padding: 11px; display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.relation-item small { display: block; color: var(--accent); font-size: 9px; margin-bottom: 4px; }
.relation-item strong { font-size: 11px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.kv-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 9px; }
.kv { border: 1px solid var(--line); border-radius: 11px; padding: 11px; }
.kv small { display: block; color: var(--muted); font-size: 9px; margin-bottom: 5px; }
.kv strong { font-size: 11px; }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: grid; gap: 8px; }
.toast { min-width: 240px; max-width: 360px; border: 1px solid var(--line-strong); border-radius: 12px; padding: 12px 14px; background: #172033; box-shadow: var(--shadow); animation: toast-in .2s ease; font-size: 11px; }
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }

.mobile-header, .mobile-nav { display: none; }

@media (max-width: 1100px) {
  .entity-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .stats-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .hero { grid-template-columns: 1fr; }
  .health-ring { width: 160px; }
  .health-ring::before { width: 125px; height: 125px; }
}

@media (max-width: 760px) {
  :root { --radius: 16px; }
  body { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .sidebar, .topbar { display: none; }
  .workspace { margin: 0; padding: 16px 14px 30px; }
  .mobile-header { height: 70px; padding: 12px 15px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); background: rgba(9,13,25,.88); backdrop-filter: blur(18px); position: sticky; top: 0; z-index: 12; }
  .mobile-nav { position: fixed; display: grid; grid-template-columns: repeat(5,1fr); bottom: 0; left: 0; right: 0; min-height: 66px; padding-bottom: env(safe-area-inset-bottom); background: rgba(10,15,28,.95); border-top: 1px solid var(--line); backdrop-filter: blur(22px); z-index: 30; }
  .mobile-nav .nav-item { grid-template-columns: 1fr; grid-template-rows: 25px 17px; gap: 0; text-align: center; place-items: center; padding: 8px 2px; border-radius: 0; position: relative; }
  .mobile-nav .nav-item span { font-size: 18px; }
  .mobile-nav .nav-item b { font-size: 9px; }
  .mobile-nav .nav-item em { position: absolute; top: 5px; right: calc(50% - 20px); }
  .mobile-nav .nav-item.is-active { box-shadow: inset 0 2px 0 var(--accent); }
  .view { margin-top: 4px; }
  .hero { padding: 22px 18px; border-radius: 20px; }
  .hero h2 { font-size: 27px; }
  .hero p { font-size: 12px; }
  .stats-grid { grid-template-columns: repeat(2,1fr); gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-card strong { font-size: 24px; }
  .dashboard-grid, .settings-grid { grid-template-columns: 1fr; }
  .panel { padding: 17px; }
  .entity-grid { grid-template-columns: 1fr; }
  .issue-summary { grid-template-columns: 1fr; }
  .issue-card { grid-template-columns: auto 1fr; }
  .issue-card .text-button { grid-column: 2; justify-self: start; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .detail-panel { border-radius: 0; width: 100vw; }
  .kv-grid { grid-template-columns: 1fr; }
  .toast-region { left: 12px; right: 12px; bottom: 80px; }
  .toast { max-width: none; }
}
