:root {
  --bg: #eef3f4;
  --surface: #ffffff;
  --surface-2: #edf2f3;
  --ink: #142126;
  --muted: #617179;
  --line: #d9e2e5;
  --navy: #10282f;
  --teal: #0f766e;
  --green: #15803d;
  --gold: #b7791f;
  --red: #b42318;
  --blue: #2563eb;
  --shadow: 0 18px 48px rgba(16, 40, 47, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255,255,255,.88), rgba(238,243,244,.94)),
    radial-gradient(circle at 78% 4%, rgba(15,118,110,.12), transparent 34%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 276px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  background: var(--navy);
  color: #e7f0f1;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 6px 18px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: #e7f0f1;
  color: var(--navy);
  font-weight: 900;
}

.brand p, .eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand p { color: #9fb3b8; }
.brand strong { display: block; margin-top: 2px; font-size: 15px; }

.nav-list { display: grid; gap: 6px; }

.nav-item {
  min-height: 44px;
  border: 0;
  background: transparent;
  color: #cbdade;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  text-align: left;
}

.nav-item span {
  width: 24px;
  color: #86efac;
  font-size: 12px;
  font-weight: 900;
}

.nav-item:hover, .nav-item.active {
  background: rgba(255,255,255,.09);
  color: #fff;
}

.sidebar-panel {
  margin-top: auto;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.1);
  padding: 16px;
}

.panel-label {
  color: #a9bdc2;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.meter {
  height: 8px;
  margin: 12px 0 10px;
  background: rgba(255,255,255,.16);
}

.meter span { display: block; height: 100%; background: #86efac; }
.sidebar-panel small { color: #c5d7db; }

.main {
  min-width: 0;
  padding: 28px;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(30px, 4vw, 46px); line-height: 1.05; letter-spacing: 0; }
h2 { margin-bottom: 0; font-size: 21px; letter-spacing: 0; }
.lead, .view-subtitle { margin: 0; color: var(--muted); line-height: 1.45; max-width: 820px; }
.view-subtitle { margin-top: 8px; }

.top-actions, .status-actions, .row-actions, .detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.primary-button, .ghost-button, .danger-button, .inline-button, .icon-button {
  min-height: 40px;
  border: 1px solid transparent;
  padding: 0 13px;
  font-weight: 850;
  background: #fff;
}

.primary-button { background: var(--teal); color: #fff; }
.ghost-button, .inline-button { color: var(--navy); border-color: var(--line); }
.danger-button { margin-right: auto; color: var(--red); background: #fff0ed; border-color: #ffd1c8; }
.inline-button { min-height: 32px; padding: 0 10px; font-size: 13px; }
.icon-button { width: 40px; padding: 0; font-size: 20px; border-color: var(--line); }

.status-strip {
  margin: 22px 0;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 14px;
}

.connection-status span {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--green);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric-card, .workspace, .data-table, .pipeline-card, .insight-card {
  background: var(--surface);
  border: 1px solid var(--line);
}

.metric-card { padding: 18px; box-shadow: 0 10px 32px rgba(16,40,47,.06); }
.metric-card span, .metric-card small { color: var(--muted); font-size: 13px; }
.metric-card strong { display: block; margin: 8px 0 2px; font-size: 33px; line-height: 1; }

.workspace { padding: 18px; box-shadow: 0 16px 48px rgba(16,40,47,.08); }

.workspace-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 16px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 170px 210px 170px 210px;
  gap: 10px;
  margin-bottom: 14px;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  background: #fff;
  padding-left: 12px;
}

.search-field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

input, select, textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

.search-field input { border: 0; }
textarea { min-height: 104px; padding-top: 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(15,118,110,.18); border-color: var(--teal); }

.auxiliary-view {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}
.auxiliary-view:empty { display: none; }

.insight-grid, .pipeline-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.pipeline-grid { grid-template-columns: repeat(8, minmax(132px, 1fr)); }

.pipeline-card, .insight-card {
  padding: 14px;
  text-align: left;
}

.pipeline-card span, .insight-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.pipeline-card strong, .insight-card strong {
  display: block;
  margin-top: 8px;
  font-size: 27px;
  line-height: 1;
}

.overview-board {
  display: grid;
  grid-template-columns: minmax(340px, 1fr) minmax(320px, .85fr);
  gap: 14px;
}

.matrix-panel,
.quality-panel,
.kanban-column {
  border: 1px solid var(--line);
  background: #fff;
  padding: 14px;
}

.matrix-grid {
  display: grid;
  grid-template-columns: 80px repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: stretch;
}

.matrix-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
  align-self: center;
}

.matrix-cell {
  min-height: 86px;
  border: 1px solid var(--line);
  background: #f9fbfb;
  padding: 10px;
}

.matrix-cell strong {
  display: block;
  font-size: 22px;
}

.matrix-cell small {
  color: var(--muted);
}

.matrix-cell.focus {
  border-color: rgba(15,118,110,.45);
  background: #ecfdf8;
}

.quality-list {
  display: grid;
  gap: 10px;
}

.quality-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.quality-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.kanban-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(220px, 1fr));
  gap: 12px;
  overflow-x: auto;
}

.kanban-column h3 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
}

.kanban-card {
  border: 1px solid var(--line);
  padding: 10px;
  margin-top: 8px;
  background: #f9fbfb;
}

.kanban-card strong {
  display: block;
  font-size: 14px;
  line-height: 1.3;
}

.kanban-card small {
  color: var(--muted);
}

.data-table {
  overflow: auto;
  --table-columns: minmax(260px,1.5fr) 96px 110px 118px 118px minmax(220px,1fr) 150px;
}

.table-head, .table-row {
  display: grid;
  grid-template-columns: var(--table-columns);
  gap: 12px;
  align-items: center;
}

.table-head {
  min-height: 44px;
  padding: 0 14px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.table-row {
  border-top: 1px solid var(--line);
  padding: 14px;
  background: #fff;
}

.table-row:hover { background: #f8fbfb; }

.cell-title { display: grid; gap: 6px; min-width: 0; }
.cell-title strong { font-size: 15px; line-height: 1.3; }
.cell-title small, .muted { color: var(--muted); font-size: 13px; line-height: 1.35; }

.badge {
  display: inline-flex;
  width: max-content;
  min-height: 26px;
  align-items: center;
  justify-content: center;
  padding: 0 9px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 850;
}

.badge.critical { color: var(--red); background: #fff0ed; border-color: #ffd1c8; }
.badge.high { color: #8a4b00; background: #fff6db; border-color: #f4dd9b; }
.badge.transformative { color: #6d28d9; background: #f5f0ff; border-color: #ded0ff; }
.badge.medium { color: var(--blue); background: #eff6ff; border-color: #c9dcff; }
.badge.low { color: var(--green); background: #ecfdf3; border-color: #b7efca; }
.badge.open { color: var(--gold); background: #fff6db; border-color: #f4dd9b; }
.badge.done, .badge.accepted, .badge.published, .badge.accept, .badge.logged { color: var(--green); background: #ecfdf3; border-color: #b7efca; }
.badge.strong, .badge.high-quality { color: var(--green); background: #ecfdf3; border-color: #b7efca; }
.badge.moderate { color: var(--blue); background: #eff6ff; border-color: #c9dcff; }
.badge.weak, .badge.high-risk { color: var(--red); background: #fff0ed; border-color: #ffd1c8; }
.badge.revisit, .badge.pause { color: var(--gold); background: #fff6db; border-color: #f4dd9b; }

.score {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.score span {
  width: 76px;
  height: 8px;
  background: var(--surface-2);
}

.score i { display: block; height: 100%; background: var(--teal); }

.tag-list, .link-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { background: var(--surface-2); color: #33444a; padding: 6px 9px; font-size: 12px; font-weight: 800; }

.research-link {
  display: grid;
  gap: 2px;
  color: var(--teal);
  text-decoration: none;
  font-weight: 850;
  line-height: 1.25;
}
.research-link:hover { text-decoration: underline; }
.research-link small { color: var(--muted); font-weight: 600; }

.topic-dialog, .detail-dialog, .database-dialog {
  width: min(980px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  border: 0;
  padding: 0;
  box-shadow: 0 30px 80px rgba(0,0,0,.28);
  overflow: auto;
}

.detail-dialog { width: min(1100px, calc(100vw - 28px)); }
.database-dialog { width: min(760px, calc(100vw - 28px)); }
.topic-dialog::backdrop, .detail-dialog::backdrop, .database-dialog::backdrop { background: rgba(16,40,47,.56); }
.topic-dialog form, .detail-content, .database-dialog form { padding: 22px; background: #fff; }

.dialog-header, .dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.form-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.lookup-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.span-2 { grid-column: span 2; }
.dialog-actions { justify-content: flex-end; }

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 18px;
  margin-top: 18px;
}

.detail-section {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  margin-top: 16px;
}

.detail-section h3 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  text-transform: uppercase;
}

.detail-card {
  border: 1px solid var(--line);
  padding: 12px;
  margin-top: 8px;
}

.risk-list {
  display: grid;
  gap: 8px;
}

.risk-item {
  border-left: 3px solid var(--gold);
  background: #fffdf4;
  padding: 10px 12px;
}

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

.chart-panel,
.synthesis-card,
.graph-panel {
  border: 1px solid var(--line);
  background: #fff;
  padding: 14px;
}

.bar-row {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) 44px;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}

.bar-row span:first-child {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.bar-track {
  height: 9px;
  background: var(--surface-2);
}

.bar-track i {
  display: block;
  height: 100%;
  background: var(--teal);
}

.graph-panel {
  overflow: auto;
  padding: 0;
  background: #fbfdfd;
}

.knowledge-map {
  min-width: 1120px;
  display: grid;
  background:
    linear-gradient(#f3f7f8 1px, transparent 1px),
    linear-gradient(90deg, #f3f7f8 1px, transparent 1px),
    #fbfdfd;
  background-size: 40px 40px;
}

.map-header,
.map-row {
  display: grid;
  grid-template-columns: minmax(220px, .75fr) minmax(320px, 1fr) minmax(420px, 1.25fr);
  gap: 24px;
  align-items: stretch;
}

.map-header {
  position: sticky;
  top: 0;
  z-index: 2;
  min-height: 48px;
  padding: 0 18px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.map-row {
  position: relative;
  min-height: 128px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.map-row:last-child {
  border-bottom: 0;
}

.map-tags,
.map-papers {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-content: center;
}

.map-chip,
.map-paper,
.map-topic {
  position: relative;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.96);
  box-shadow: 0 8px 22px rgba(16,40,47,.06);
}

.map-chip {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 850;
}

.map-chip::before,
.map-paper::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  flex: 0 0 auto;
}

.map-chip::before {
  background: var(--gold);
}

.map-topic-wrap {
  display: flex;
  align-items: center;
}

.map-topic {
  width: 100%;
  min-height: 72px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
}

.map-topic-dot {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: var(--teal);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.map-topic strong,
.map-paper strong {
  display: block;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.3;
}

.map-topic small,
.map-paper small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.map-paper {
  min-height: 50px;
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 10px;
  width: min(100%, 320px);
}

.map-paper::before {
  margin-top: 5px;
  background: var(--blue);
}

.map-empty {
  color: var(--muted);
  font-size: 13px;
  align-self: center;
}

.database-status {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  padding: 12px;
  margin-bottom: 14px;
  font-size: 14px;
}

.database-status.connected {
  background: #ecfdf3;
  color: var(--green);
  border-color: #b7efca;
}

.database-status.error {
  background: #fff0ed;
  color: var(--red);
  border-color: #ffd1c8;
}
}

.synthesis-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.synthesis-card ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.45;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: 420px;
  display: none;
  background: var(--navy);
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.toast.show {
  display: block;
}

.toast button {
  margin-left: 12px;
  min-height: 30px;
  border: 1px solid rgba(255,255,255,.28);
  background: transparent;
  color: #fff;
  font-weight: 850;
}

@media (max-width: 1220px) {
  .metrics-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .data-table { overflow-x: auto; }
  .table-head, .table-row { min-width: 1100px; }
  .pipeline-grid { grid-template-columns: repeat(4, minmax(0,1fr)); }
}

@media (max-width: 860px) {
  body { height: auto; overflow: auto; }
  .app-shell { display: block; }
  .sidebar { height: auto; min-height: auto; padding: 12px; flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .main { height: auto; overflow: visible; }
  .brand { border: 0; padding: 0; min-width: 210px; }
  .nav-list { display: flex; min-width: max-content; }
  .sidebar-panel { display: none; }
  .main { padding: 18px; }
  .topbar, .status-strip, .workspace-header { display: grid; }
  .toolbar, .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .metrics-grid, .insight-grid, .pipeline-grid, .detail-grid, .overview-board, .kanban-board, .chart-grid, .synthesis-grid, .lookup-row { grid-template-columns: 1fr; }
}
