:root {
  color-scheme: dark;
  --bg: #101112;
  --bg-2: #151719;
  --panel: #191c1f;
  --panel-2: #202428;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f5f2ec;
  --muted: #a9aaa6;
  --faint: #757974;
  --out: #1fc7b6;
  --in: #f1a23c;
  --mutual: #df5b51;
  --steel: #7e95a0;
  --focus: #e8d66b;
  --shadow: rgba(0, 0, 0, 0.34);
  font-family:
    Inter, "SF Pro Display", "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Yu Gothic", "Meiryo", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  color: var(--text);
  border: 1px solid var(--line);
  background: #22272b;
  cursor: pointer;
}

button:hover {
  border-color: rgba(255, 255, 255, 0.28);
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-rows: 72px minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0) 160px),
    var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 17, 18, 0.94);
}

.hidden {
  display: none !important;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background:
    linear-gradient(135deg, rgba(31, 199, 182, 0.88), rgba(31, 199, 182, 0) 54%),
    linear-gradient(315deg, rgba(241, 162, 60, 0.86), rgba(241, 162, 60, 0) 56%),
    #202428;
}

h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 760;
  letter-spacing: 0;
  line-height: 1.2;
}

.brand p,
.detail-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: min(330px, 28vw);
  min-width: 230px;
  gap: 6px;
}

.mode-switch button {
  min-height: 36px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 760;
}

.mode-switch button.active {
  border-color: rgba(31, 199, 182, 0.78);
  background: linear-gradient(180deg, rgba(31, 199, 182, 0.24), rgba(31, 199, 182, 0.12));
  color: #e9fffb;
}

.top-stats {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  min-width: 320px;
  color: var(--muted);
  font-size: 12px;
}

.stat-pill {
  min-width: 92px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
}

.stat-pill strong {
  display: block;
  color: var(--text);
  font-size: 14px;
  line-height: 1.1;
}

.workspace {
  display: grid;
  grid-template-columns: 318px minmax(460px, 1fr) 360px;
  min-height: 0;
}

.panel {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.detail-panel {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.control-panel,
.detail-panel {
  padding: 16px;
}

section + section {
  margin-top: 18px;
}

.section-title,
label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 8px;
}

input,
select {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: #111315;
  color: var(--text);
}

input[type="search"] {
  height: 38px;
  padding: 0 11px;
}

select {
  height: 36px;
  padding: 0 9px;
}

.icon-button,
.canvas-toolbar button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.search-results {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.result-row,
.edge-row,
.sector-row {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.035);
  text-align: left;
}

.result-row {
  display: grid;
  gap: 3px;
}

.result-row strong,
.edge-main strong {
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 720;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-row span,
.edge-meta,
.sector-row span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.segmented button,
.tabs button {
  min-height: 34px;
  padding: 7px 9px;
  font-size: 12px;
  font-weight: 720;
}

.segmented button.active,
.tabs button.active {
  border-color: rgba(31, 199, 182, 0.72);
  background: rgba(31, 199, 182, 0.16);
  color: #e9fffb;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 30px;
  margin: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 620;
}

.check-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--out);
}

.range-label,
.select-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 8px;
}

.range-label output {
  color: var(--text);
  font-size: 12px;
}

.range {
  width: 100%;
  accent-color: var(--out);
}

.select-label {
  margin-top: 14px;
}

.selected-card {
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #141719;
}

.selected-card h2,
.detail-head h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
  letter-spacing: 0;
}

.selected-card .code,
.detail-head .code {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  margin-top: 8px;
  padding: 3px 7px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--muted);
  font-size: 11px;
}

.canvas-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    #0d0f10;
  background-size: 42px 42px;
}

#networkCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.canvas-toolbar {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 6px;
}

.canvas-toolbar button {
  background: rgba(18, 20, 22, 0.88);
  box-shadow: 0 12px 28px var(--shadow);
}

.legend {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  background: rgba(16, 17, 18, 0.84);
  color: var(--muted);
  font-size: 12px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  width: 20px;
  height: 3px;
  display: inline-block;
}

.legend-out {
  background: var(--out);
}

.legend-in {
  background: var(--in);
}

.legend-mutual {
  background: var(--mutual);
}

.hover-card {
  position: absolute;
  z-index: 3;
  display: none;
  max-width: 260px;
  padding: 10px 11px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(20, 22, 24, 0.96);
  box-shadow: 0 18px 40px var(--shadow);
  pointer-events: none;
}

.hover-card strong {
  display: block;
  margin-bottom: 5px;
  font-size: 13px;
}

.hover-card span {
  color: var(--muted);
  font-size: 11px;
}

.detail-head {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.metric-card {
  min-height: 68px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: rgba(255, 255, 255, 0.035);
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  color: var(--text);
  font-size: 18px;
  line-height: 1.15;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}

.edge-list {
  display: grid;
  gap: 7px;
}

.edge-row {
  display: grid;
  gap: 5px;
}

.edge-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: baseline;
}

.edge-main em {
  color: var(--text);
  font-style: normal;
  font-size: 12px;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  padding: 2px 5px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--muted);
  font-size: 10px;
}

.badge.out {
  border-color: rgba(31, 199, 182, 0.42);
  color: #b9fff6;
}

.badge.in {
  border-color: rgba(241, 162, 60, 0.48);
  color: #ffe3bd;
}

.badge.mutual {
  border-color: rgba(223, 91, 81, 0.54);
  color: #ffd0ca;
}

.badge.major {
  border-color: rgba(139, 182, 255, 0.5);
  color: #d8e7ff;
}

.sector-block {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.sector-list {
  display: grid;
  gap: 7px;
}

.sector-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.sector-bar {
  grid-column: 1 / -1;
  height: 4px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
}

.sector-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--out), var(--in));
}

.trend-card {
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: rgba(255, 255, 255, 0.035);
}

.trend-card + .trend-card {
  margin-top: 8px;
}

.trend-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 12px;
}

.trend-head strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trend-svg {
  display: block;
  width: 100%;
  height: 56px;
}

.empty {
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

@media (max-width: 1180px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    grid-template-rows: auto auto;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .mode-switch {
    width: 100%;
  }

  .top-stats {
    width: 100%;
    min-width: 0;
    justify-content: flex-start;
    overflow-x: auto;
  }

  .workspace {
    grid-template-columns: 300px minmax(360px, 1fr);
    grid-template-rows: minmax(620px, 72vh) auto;
  }

  .detail-panel {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 760px) {
  .workspace {
    display: block;
  }

  .panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .canvas-stage {
    height: 62vh;
    min-height: 430px;
  }

  .topbar {
    padding: 12px;
  }

  .control-panel,
  .detail-panel {
    padding: 12px;
  }

  .top-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}
