:root {
  color-scheme: light;
  --dw-bg: #f6f7fb;
  --dw-surface: #ffffff;
  --dw-border: #d9dee9;
  --dw-text: #172033;
  --dw-muted: #667085;
  --dw-soft: #eef2f7;
  --dw-blue: #2563eb;
  --dw-blue-dark: #1d4ed8;
  --dw-green: #15803d;
  --dw-amber: #b45309;
  --dw-red: #b91c1c;
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

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

.dw-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.dw-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 22px;
  background: var(--dw-surface);
  border-bottom: 1px solid var(--dw-border);
}

.dw-kicker {
  display: block;
  margin-bottom: 4px;
  color: var(--dw-muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
}

.dw-title-block h1 {
  margin: 0;
  max-width: 980px;
  font-size: clamp(1.05rem, 1.8vw, 1.45rem);
  line-height: 1.25;
}

.dw-title-block p {
  margin: 6px 0 0;
  color: var(--dw-muted);
  font-size: 0.88rem;
}

.dw-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 320px;
}

.dw-status {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--dw-border);
  border-radius: 6px;
  background: var(--dw-soft);
  color: var(--dw-muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.dw-status.generated { color: var(--dw-green); background: #ecfdf3; border-color: #bbf7d0; }
.dw-status.missing { color: var(--dw-amber); background: #fffbeb; border-color: #fde68a; }
.dw-status.error { color: var(--dw-red); background: #fef2f2; border-color: #fecaca; }

.dw-btn {
  min-height: 32px;
  border: 1px solid var(--dw-border);
  border-radius: 6px;
  padding: 0 12px;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
}

.dw-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

.dw-btn-primary {
  background: var(--dw-blue);
  color: #fff;
  border-color: var(--dw-blue);
}

.dw-btn-primary:hover { background: var(--dw-blue-dark); }

.dw-btn-ghost {
  background: #fff;
  color: var(--dw-text);
}

.dw-index {
  flex: 1;
  padding: 18px 22px;
  overflow-y: auto;
}

.dw-index-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.dw-index-toolbar h2 {
  margin: 0;
  font-size: 1.05rem;
}

.dw-index-toolbar p {
  margin: 6px 0 0;
  color: var(--dw-muted);
  font-size: 0.88rem;
}

.dw-index-toolbar input {
  width: min(360px, 100%);
  min-height: 36px;
  border: 1px solid var(--dw-border);
  border-radius: 6px;
  padding: 0 11px;
  background: #fff;
  color: var(--dw-text);
  font: inherit;
  font-size: 0.9rem;
}

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

.dw-index-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--dw-border);
  border-radius: 8px;
  padding: 12px;
  background: var(--dw-surface);
}

.dw-index-doc {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dw-index-doc strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
}

.dw-index-doc span,
.dw-index-meta span {
  color: var(--dw-muted);
  font-size: 0.78rem;
}

.dw-index-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  flex-wrap: wrap;
}

.dw-main {
  flex: 1;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 330px;
  min-height: 0;
}

.dw-sidebar,
.dw-evidence {
  background: var(--dw-surface);
  border-right: 1px solid var(--dw-border);
  padding: 14px;
  overflow-y: auto;
}

.dw-evidence {
  border-right: 0;
  border-left: 1px solid var(--dw-border);
}

.dw-tab {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 10px;
  background: transparent;
  color: var(--dw-text);
  font: inherit;
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
}

.dw-tab:hover,
.dw-tab.active {
  background: #eef4ff;
  border-color: #c7d2fe;
  color: #1e40af;
}

.dw-tab span {
  min-width: 24px;
  border-radius: 999px;
  padding: 2px 7px;
  background: var(--dw-soft);
  color: var(--dw-muted);
  text-align: center;
  font-size: 0.74rem;
  font-weight: 700;
}

.dw-content {
  min-width: 0;
  padding: 18px;
  overflow-y: auto;
}

.dw-map-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.dw-map-tools {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.dw-view-toggle {
  display: inline-flex;
  min-height: 32px;
  border: 1px solid var(--dw-border);
  border-radius: 7px;
  overflow: hidden;
  background: #fff;
}

.dw-view-toggle button {
  min-width: 74px;
  border: 0;
  border-right: 1px solid var(--dw-border);
  padding: 0 10px;
  background: transparent;
  color: var(--dw-muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.dw-view-toggle button:last-child { border-right: 0; }

.dw-view-toggle button.active {
  background: #eef4ff;
  color: #1e40af;
}

.dw-map-head h2,
.dw-evidence h2 {
  margin: 0;
  font-size: 1.05rem;
}

.dw-map-head p,
.dw-evidence p {
  margin: 6px 0 0;
  color: var(--dw-muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.dw-source-list {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.dw-source-list span {
  border: 1px solid var(--dw-border);
  border-radius: 999px;
  padding: 3px 8px;
  background: #fff;
  color: var(--dw-muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.dw-empty {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px;
  border: 1px dashed var(--dw-border);
  border-radius: 8px;
  background: #fff;
  color: var(--dw-muted);
}

.dw-empty strong { color: var(--dw-text); }
.dw-empty.hidden { display: none; }

.dw-entry-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 12px;
}

.dw-graph-panel {
  min-height: 560px;
  border: 1px solid var(--dw-border);
  border-radius: 8px;
  background: #fbfcfe;
  overflow: hidden;
}

.dw-graph-toolbar {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--dw-border);
  color: var(--dw-muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.dw-graph-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.dw-graph-actions .dw-btn {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.78rem;
}

.dw-graph-stage {
  position: relative;
  min-height: 560px;
}

.dw-graph {
  width: 100%;
  height: 560px;
  background: #fbfcfe;
}

.dw-graph-legend {
  position: absolute;
  z-index: 2;
  top: 12px;
  left: 12px;
  width: min(210px, calc(100% - 24px));
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 10px 11px;
  border: 1px solid rgba(148, 163, 184, 0.45);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
  color: #344054;
  font-size: 0.75rem;
  line-height: 1.2;
  backdrop-filter: blur(6px);
}

.dw-graph-legend strong {
  color: var(--dw-text);
  font-size: 0.78rem;
}

.dw-graph-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.dw-graph-legend small {
  margin-top: 2px;
  color: var(--dw-muted);
  font-size: 0.7rem;
  line-height: 1.3;
}

.dw-legend-dot {
  width: 11px;
  height: 11px;
  flex: 0 0 11px;
  border: 2px solid currentColor;
  border-radius: 999px;
  background: currentColor;
}

.dw-legend-concepts { color: #2563eb; }
.dw-legend-authors { color: #16a34a; }
.dw-legend-theories { color: #7c3aed; }
.dw-legend-categories { color: #d97706; }
.dw-legend-tensions { color: #dc2626; }
.dw-legend-actors { color: #db2777; }

.dw-legend-line {
  width: 22px;
  height: 0;
  flex: 0 0 22px;
  border-top: 3px solid #64748b;
}

.dw-entry {
  min-height: 180px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  border: 1px solid var(--dw-border);
  border-radius: 8px;
  padding: 13px;
  background: var(--dw-surface);
  cursor: pointer;
}

.dw-entry:hover,
.dw-entry.active,
.dw-entry.speaking,
.dw-entry.paused {
  border-color: #93c5fd;
  box-shadow: 0 8px 22px rgba(37, 99, 235, 0.12);
}

.dw-entry.speaking {
  border-color: #60a5fa;
  background: #f8fbff;
}

.dw-entry.paused {
  border-color: #fbbf24;
}

.dw-entry-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.dw-entry h3 {
  margin: 0;
  font-size: 0.96rem;
  line-height: 1.35;
}

.dw-entry p {
  margin: 0;
  color: #344054;
  font-size: 0.84rem;
  line-height: 1.5;
}

.dw-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.dw-meta span {
  border-radius: 999px;
  padding: 2px 7px;
  background: var(--dw-soft);
  color: var(--dw-muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.dw-entry-tts {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.dw-entry-tts button {
  min-height: 28px;
  border: 1px solid var(--dw-border);
  border-radius: 6px;
  padding: 0 8px;
  background: #fff;
  color: var(--dw-text);
  font: inherit;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}

.dw-entry-tts button:hover:not(:disabled) {
  border-color: #93c5fd;
  color: #1e40af;
  background: #eef4ff;
}

.dw-entry-tts button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.dw-evidence-item {
  margin-top: 12px;
  border-left: 3px solid #93c5fd;
  padding: 8px 0 8px 10px;
  background: #fff;
}

.dw-evidence-item blockquote {
  margin: 0;
  color: #1f2937;
  font-size: 0.86rem;
  line-height: 1.55;
}

.dw-evidence-translation {
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid #dbeafe;
  background: #eff6ff;
  color: #1e3a8a;
  font-size: 0.82rem;
  line-height: 1.5;
}

.dw-evidence-translation strong {
  display: block;
  margin-bottom: 3px;
  color: #1d4ed8;
  font-size: 0.7rem;
  text-transform: uppercase;
}

.dw-evidence-translation span {
  display: block;
}

.dw-evidence-item p {
  margin: 5px 0 0;
  font-size: 0.76rem;
}

@media (max-width: 980px) {
  .dw-header { flex-direction: column; }
  .dw-actions { width: 100%; justify-content: flex-start; min-width: 0; }
  .dw-index-toolbar { align-items: stretch; flex-direction: column; }
  .dw-index-row { grid-template-columns: 1fr; align-items: stretch; }
  .dw-index-doc strong { white-space: normal; }
  .dw-index-meta { justify-content: flex-start; }
  .dw-main { grid-template-columns: 1fr; }
  .dw-map-head { flex-direction: column; }
  .dw-map-tools { width: 100%; justify-content: flex-start; }
  .dw-graph-toolbar { align-items: flex-start; flex-direction: column; }
  .dw-graph-actions { justify-content: flex-start; }
  .dw-graph-stage { min-height: 640px; }
  .dw-graph { height: 640px; }
  .dw-graph-legend {
    position: static;
    width: 100%;
    border-width: 0 0 1px;
    border-radius: 0;
    box-shadow: none;
    background: #fff;
  }
  .dw-entry-top { flex-direction: column; }
  .dw-entry-tts { width: 100%; }
  .dw-entry-tts button { flex: 1; }
  .dw-sidebar {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--dw-border);
  }
  .dw-tab {
    width: auto;
    min-width: 150px;
    margin-bottom: 0;
    flex: 0 0 auto;
  }
  .dw-evidence {
    border-left: 0;
    border-top: 1px solid var(--dw-border);
    max-height: 360px;
  }
  .dw-graph-panel { min-height: 420px; }
  .dw-graph { height: 420px; }
}
