:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #647184;
  --line: #d5dce6;
  --soft-line: #e7ebf0;
  --accent: #0b6f8f;
  --accent-dark: #084f66;
  --accent-soft: #e5f4f8;
  --green: #2f855a;
  --orange: #b26a00;
  --warn-bg: #fff7dd;
  --warn-line: #dfbd52;
  --shadow: 0 12px 28px rgba(23, 32, 42, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.app {
  max-width: 1360px;
  margin: 0 auto;
  padding: 24px;
}

.toolbar,
.result-header,
.panel-head,
.actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.toolbar,
.result-header,
.panel-head {
  justify-content: space-between;
}

.toolbar {
  margin-bottom: 16px;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  font-size: 17px;
  line-height: 1.3;
}

h3 {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  text-transform: uppercase;
}

p {
  margin: 8px 0 0;
  color: var(--muted);
}

.file-button,
button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.file-button input {
  display: none;
}

button:disabled {
  border-color: #a8b3c0;
  background: #a8b3c0;
  cursor: not-allowed;
}

button:hover:not(:disabled),
.file-button:hover {
  background: var(--accent-dark);
}

button.secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.warning {
  border: 1px solid var(--warn-line);
  background: var(--warn-bg);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 16px;
  line-height: 1.5;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.summary-card {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 12px;
  min-width: 0;
}

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

.summary-card strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 0.8fr) minmax(420px, 1.2fr);
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 16px;
}

form,
.form-section,
.package-panel {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
  min-width: 0;
}

textarea {
  resize: vertical;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
}

fieldset label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

fieldset input {
  width: auto;
}

legend {
  color: var(--muted);
  font-size: 13px;
  padding: 0 4px;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.purpose-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.purpose-card {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--text);
  cursor: pointer;
}

.purpose-card:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.purpose-card input {
  width: auto;
}

.advanced-filters {
  border-top: 1px solid var(--soft-line);
  padding-top: 10px;
}

.advanced-filters summary {
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.advanced-filters[open] summary {
  margin-bottom: 10px;
}

.status {
  min-height: 22px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  margin-top: 12px;
}

.tab {
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 0;
  padding: 10px 4px 9px;
}

.tab:hover,
.tab.is-active {
  background: transparent;
  color: var(--text);
  border-bottom-color: var(--accent);
}

.result-panel {
  display: none;
}

.result-panel.is-active {
  display: block;
}

.graph-viewport {
  position: relative;
  min-height: 520px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  background:
    linear-gradient(#eef2f6 1px, transparent 1px),
    linear-gradient(90deg, #eef2f6 1px, transparent 1px),
    #fbfcfe;
  background-size: 28px 28px;
}

.graph-svg {
  display: block;
  min-width: 100%;
  min-height: 520px;
}

.graph-edge {
  fill: none;
  stroke: #7c8794;
  stroke-width: 1.8;
}

.graph-edge.local {
  stroke: var(--accent);
  stroke-width: 2.2;
}

.graph-edge.external-in {
  stroke: var(--green);
}

.graph-edge.external-out {
  stroke: var(--orange);
}

.edge-arrow {
  fill: currentColor;
  color: #7c8794;
}

.edge-label,
.graph-empty {
  fill: var(--muted);
  font-size: 12px;
}

.graph-node {
  cursor: pointer;
  outline: none;
}

.graph-node rect {
  fill: #fff;
  stroke: var(--line);
  stroke-width: 1.5;
}

.graph-node:hover rect,
.graph-node:focus rect {
  stroke: var(--accent);
}

.graph-node.is-selected rect {
  fill: var(--accent-soft);
  stroke: var(--accent);
}

.node-label {
  fill: var(--text);
  font-size: 14px;
  font-weight: 800;
}

.node-value {
  fill: var(--muted);
  font-size: 12px;
}

.node-detail {
  position: absolute;
  z-index: 3;
  width: min(360px, calc(100% - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 12px;
}

.node-detail.is-hidden {
  display: none;
}

.detail-title {
  margin-bottom: 8px;
  font-weight: 800;
}

.detail-rows {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 6px 10px;
  margin: 0 0 12px;
  font-size: 12px;
}

.detail-rows dt {
  color: var(--muted);
}

.detail-rows dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 14px;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #eef2f7;
  color: #334155;
  position: sticky;
  top: 0;
}

tr:last-child td {
  border-bottom: 0;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  overflow-wrap: anywhere;
}

.muted {
  color: var(--muted);
}

@media (max-width: 980px) {
  .app {
    padding: 16px;
  }

  .toolbar,
  .result-header,
  .panel-head,
  .workspace {
    display: grid;
    grid-template-columns: 1fr;
  }

  .summary-grid,
  .workspace,
  fieldset,
  .two-col,
  .purpose-grid {
    grid-template-columns: 1fr;
  }

  .actions {
    flex-wrap: wrap;
  }
}
