:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --line: #d9dee3;
  --text: #202428;
  --muted: #68717b;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --danger: #b42318;
  --warn: #8a5a00;
  --soft: #eef7f5;
  --shadow: 0 8px 24px rgba(22, 28, 36, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  background: var(--accent-strong);
}

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

button.ghost:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

button.small {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

button.danger {
  background: #fff;
  color: var(--danger);
  border-color: #efb4ad;
}

button.danger:hover {
  border-color: var(--danger);
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

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

textarea {
  min-height: 160px;
  resize: vertical;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(15, 118, 110, 0.18);
  border-color: var(--accent);
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-view[hidden],
.app-view[hidden],
.login-panel[hidden],
form[hidden] {
  display: none !important;
}

.login-panel h1 {
  margin: 0;
  font-size: 25px;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-weight: 800;
}

.message {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  overflow-wrap: anywhere;
}

.app-view {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  height: auto;
  min-height: 64px;
  display: grid;
  grid-template-columns: minmax(160px, 220px) 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 10px 18px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  font-size: 20px;
  font-weight: 850;
}

.session-label {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

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

.tab.active {
  background: var(--soft);
  border-color: var(--accent);
  color: var(--accent-strong);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(360px, 1fr) minmax(300px, 380px);
  gap: 12px;
  padding: 12px;
  min-height: 0;
}

.pane {
  min-width: 0;
  min-height: calc(100vh - 88px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(22, 28, 36, 0.04);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
}

.pane-head {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.pane-head h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0;
}

.filters {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.item-list {
  overflow: auto;
  min-height: 0;
}

.item {
  width: 100%;
  display: grid;
  gap: 5px;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
  color: var(--text);
  padding: 12px;
  min-height: 70px;
}

.item:hover,
.item.active {
  background: var(--soft);
}

.item-title {
  font-weight: 750;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.item-meta {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.editor-body,
.detail-body {
  min-height: 0;
  overflow: auto;
  padding: 14px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

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

.three-cols {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.action-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

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

.empty {
  padding: 18px;
  color: var(--muted);
}

.section {
  display: grid;
  gap: 12px;
}

.block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 10px;
  background: #fff;
}

.block h3 {
  margin: 0;
  font-size: 15px;
}

.step-row,
.keyword-row,
.application-row,
.result-row {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.step-row + .step-row,
.keyword-row + .keyword-row,
.application-row + .application-row,
.result-row + .result-row {
  margin-top: 8px;
}

.node-list,
.edge-list {
  display: grid;
  gap: 6px;
}

.node-list {
  grid-template-columns: repeat(auto-fit, minmax(90px, max-content));
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7faf9;
  font-size: 13px;
}

.edge-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18px minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  padding: 8px;
  border-left: 3px solid var(--line);
  background: #fbfcfc;
  font-size: 13px;
}

.edge-row strong,
.edge-row em {
  grid-column: 1 / -1;
}

.edge-row.linked {
  border-left-color: var(--accent);
}

.recall-box {
  min-height: 160px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #fbfcfc;
}

.keyword-mark {
  background: #fff2cc;
  border-radius: 4px;
  padding: 0 2px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #202428;
  color: #fff;
  box-shadow: var(--shadow);
  z-index: 20;
  overflow-wrap: anywhere;
}

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

  .detail-pane {
    grid-column: 1 / -1;
    min-height: 420px;
  }
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .tab,
  .topbar .ghost {
    min-width: 0;
  }

  .workspace {
    grid-template-columns: 1fr;
    padding: 8px;
  }

  .pane {
    min-height: auto;
  }

  .list-pane {
    max-height: 520px;
  }

  .two-cols,
  .three-cols {
    grid-template-columns: 1fr;
  }
}
