:root {
    --background: #ffffff;
    --foreground: #0a0a0a;
    --muted: #737373;
    --muted-foreground: #8b8b8b;
    --border: #e5e5e5;
    --accent: #ea580c;
    --accent-light: #fb923c;
    --card: #ffffff;
    --card-hover: #fafafa;
    --radius: 12px;
    --column-width: 384px;
    --header-height: 60px;
    --selection-bg: rgba(234, 88, 12, 0.1);
    --selection-border: rgba(234, 88, 12, 0.3);

    /* Entity colors */
    --entity-date: #3b82f6;
    --entity-place: #10b981;
    --entity-event: #f59e0b;
    --entity-org: #8b5cf6;
    --entity-person: #ef4444;
    --entity-default: #6b7280;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--background);
    color: var(--foreground);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    height: var(--header-height);
    border-bottom: 1px solid var(--border);
    background: var(--card);
    flex-shrink: 0;
}

.header-content {
    max-width: 100%;
    height: 100%;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.header-brand:hover {
    opacity: 0.8;
}

.header-logo {
    height: 32px;
    width: auto;
}

.header-divider {
    width: 1px;
    height: 24px;
    background: var(--border);
}

.header-title {
    font-size: 16px;
    font-weight: 500;
    color: var(--muted);
    letter-spacing: -0.01em;
}

.header-controls {
    display: flex;
    gap: 8px;
}

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: var(--card-hover);
    color: var(--foreground);
    border-color: var(--accent);
}

.main-content {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.columns-container {
    height: 100%;
    overflow: auto;
    padding: 24px;
    position: relative;
    scroll-behavior: smooth;
}

.columns-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.columns-container::-webkit-scrollbar-track {
    background: var(--background);
}

.columns-container::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.columns-container::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

.columns-container::-webkit-scrollbar-corner {
    background: var(--background);
}

.initial-search {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: 600px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.search-card {
    width: 100%;
    padding: 48px;
    text-align: center;
}

.search-title {
    font-size: 32px;
    font-weight: 600;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--foreground) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.search-subtitle {
    font-size: 16px;
    color: var(--muted);
    margin-bottom: 32px;
}

.search-form {
    width: 100%;
}

.search-input-wrapper {
    position: relative;
    width: 100%;
}

.search-input {
    width: 100%;
    padding: 16px 52px 16px 20px;
    font-size: 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--foreground);
    transition: all 0.2s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.1);
}

.search-button {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border: none;
    border-radius: calc(var(--radius) - 2px);
    background: var(--accent);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.search-button:hover {
    background: var(--accent-light);
}

.knowledge-column {
    flex-shrink: 0;
    width: var(--column-width);
    min-height: 200px;
    max-height: calc(100vh - var(--header-height) - 96px);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s ease;
    position: absolute;
}

.knowledge-column.highlight {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.1);
}

.column-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.column-search-wrapper {
    flex: 1;
    margin-right: 12px;
}

.column-search-form {
    display: flex;
    align-items: center;
    gap: 8px;
}

.column-search-input {
    flex: 1;
    padding: 8px 12px;
    font-size: 14px;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    background: var(--background);
    color: var(--foreground);
}

.column-search-input:focus {
    outline: none;
    border-color: var(--accent);
}

.column-search-button {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: calc(var(--radius) - 2px);
    background: var(--accent);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.column-search-button:hover {
    background: var(--accent-light);
}

.column-close {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.column-close:hover {
    background: var(--card-hover);
    color: var(--foreground);
    border-color: var(--accent);
}

.column-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    font-size: 15px;
    line-height: 1.7;
    color: var(--foreground);
    user-select: text;
}

.column-content-no-header {
    padding-top: 30px;
}

.column-content::-webkit-scrollbar {
    width: 6px;
}

.column-content::-webkit-scrollbar-track {
    background: transparent;
}

.column-content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.column-content::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

.column-content p {
    margin-bottom: 16px;
}

.column-content h3 {
    font-size: 18px;
    font-weight: 600;
    margin: 24px 0 12px;
    color: var(--foreground);
}

.column-content ul,
.column-content ol {
    margin-bottom: 16px;
    padding-left: 24px;
}

.column-content li {
    margin-bottom: 8px;
}

.column-content blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 16px;
    margin: 16px 0;
    color: var(--muted);
    font-style: italic;
}

.column-content code {
    background: var(--card-hover);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
}

.column-content pre {
    background: var(--card-hover);
    padding: 16px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin-bottom: 16px;
}

.column-content pre code {
    background: transparent;
    padding: 0;
}

.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.text-highlight {
    padding: 2px 4px;
    border-radius: 3px;
    border-bottom: 2px solid;
    cursor: pointer;
    transition: all 0.2s ease;
}

.text-highlight:hover {
    filter: brightness(1.2);
}

.selection-tooltip {
    position: fixed;
    z-index: 10000;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    padding: 0;
    min-width: 280px;
    max-width: 400px;
    animation: tooltipFadeIn 0.2s ease;
}

@keyframes tooltipFadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.selection-tooltip.hidden {
    display: none;
}

.tooltip-content {
    padding: 16px;
}

.tooltip-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tooltip-input {
    padding: 10px 12px;
    font-size: 14px;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    background: var(--background);
    color: var(--foreground);
    width: 100%;
}

.tooltip-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(234, 88, 12, 0.1);
}

.tooltip-input::placeholder {
    color: var(--muted);
    font-size: 13px;
}

.tooltip-button-primary {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: calc(var(--radius) - 2px);
    background: var(--accent);
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}

.tooltip-button-primary:hover {
    background: var(--accent-light);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(234, 88, 12, 0.3);
}

.tooltip-button-primary:active {
    transform: translateY(0);
}

.tooltip-arrow {
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 12px;
    background: var(--card);
    border-left: 1px solid var(--border);
    border-top: 1px solid var(--border);
    transform: translateX(-50%) rotate(45deg);
}

.connections-svg {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 100;
    transform-origin: 0 0;
}

.connection-line {
    stroke: var(--accent);
    stroke-width: 2;
    fill: none;
    opacity: 0.3;
    stroke-dasharray: 5, 5;
    animation: dashAnimation 20s linear infinite;
    pointer-events: stroke;
    cursor: pointer;
}

@keyframes dashAnimation {
    to {
        stroke-dashoffset: -100;
    }
}

.connection-line:hover {
    opacity: 0.6;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--muted);
}

.empty-state svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state-text {
    font-size: 14px;
    text-align: center;
}

.typing-indicator {
    display: inline-block;
    padding: 8px 12px;
    background: var(--card-hover);
    border-radius: var(--radius);
    margin-bottom: 12px;
}

.typing-indicator::after {
    content: '...';
    animation: typing 1.5s infinite;
}

@keyframes typing {
    0%, 60% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

/* Graph styles */
.graph-container {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
    background: radial-gradient(circle, var(--background) 1px, transparent 1px);
    background-size: 20px 20px;
    transform-origin: 0 0;
    transition: transform 0.15s ease;
}

.graph-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    transform-origin: 0 0;
    overflow: visible;
}

.graph-node {
    position: absolute;
    width: 450px;
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    z-index: 10;
    cursor: move;
}

.graph-node:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
}

.graph-node.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.2);
}

.node-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: move;
}

.node-query {
    font-size: 14px;
    font-weight: 500;
    color: var(--foreground);
    flex: 1;
    margin-right: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.node-close {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.node-close:hover {
    background: var(--card-hover);
    color: var(--accent);
}

.node-content {
    padding: 16px;
    overflow-y: auto;
    max-height: 70vh;
    font-size: 14px;
    line-height: 1.6;
    color: var(--foreground);
    cursor: text;
    user-select: text;
}

.node-content p {
    margin: 0 0 12px;
}

.node-content p:last-child {
    margin-bottom: 0;
}

.node-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

/* Entity styles - subtle and reference-like */
.node-entities {
    padding: 12px 16px;
    border-top: 1px solid rgba(229, 231, 235, 0.5);
    background: rgba(249, 250, 251, 0.3);
    animation: slideUpFadeIn 0.4s ease-out;
    transform-origin: top center;
}

@keyframes slideUpFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
        max-height: 0;
    }
    to {
        opacity: 1;
        transform: translateY(0);
        max-height: 200px;
    }
}

.entity-type-section {
    margin-bottom: 8px;
}

.entity-type-section:last-child {
    margin-bottom: 0;
}

.entity-type-header {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
    font-size: 10px;
    font-weight: 500;
    color: var(--muted-foreground);
    opacity: 0.6;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.entity-type-label {
    font-size: 10px;
}

.entity-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.entity-chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    background: var(--entity-color, var(--entity-default));
    color: #374151;
    border: 1px solid rgba(0, 0, 0, 0.04);
    border-radius: calc(var(--radius) * 0.4);
    font-size: 11px;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    max-width: 180px;
    position: relative;
    box-shadow: none;
    opacity: 0.5;
}

.entity-chip:after {
    content: attr(title);
    position: absolute;
    visibility: hidden;
    pointer-events: none;
}

.entity-chip:hover {
    transform: scale(1.02);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    opacity: 0.7;
}

.entity-chip:active {
    transform: scale(0.99);
    opacity: 0.9;
}

/* Active entity chip (has child nodes) */
.entity-chip.active {
    opacity: 1;
    font-weight: 500;
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    animation: pulseActive 2s ease-in-out infinite;
}

@keyframes pulseActive {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.85;
    }
}

/* Handle text overflow with gradient fade */
.entity-chip span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.graph-edge {
    stroke-width: 2;
    fill: none;
    opacity: 0.4;
    stroke-dasharray: 5, 5;
    animation: dashAnimation 20s linear infinite;
    pointer-events: none;
}

.zoom-indicator {
    position: fixed;
    top: 80px;
    right: 20px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--foreground);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 10000;
    display: none;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.zoom-controls {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    gap: 8px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 1000;
}

.zoom-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: calc(var(--radius) - 2px);
    transition: all 0.2s ease;
}

.zoom-btn:hover {
    background: var(--card-hover);
    color: var(--foreground);
}

.zoom-btn:active {
    transform: scale(0.95);
}

.zoom-level {
    min-width: 50px;
    text-align: center;
    font-size: 13px;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
}



@media (max-width: 768px) {
    .header-content {
        padding: 0 16px;
    }

    .columns-container {
        padding: 16px;
        gap: 16px;
    }

    .knowledge-column {
        width: calc(100vw - 32px);
    }

    .search-card {
        padding: 24px;
    }

    .search-title {
        font-size: 24px;
    }

    .zoom-controls {
        bottom: 10px;
        right: 10px;
    }
}

/* Контейнер и кнопка */
.ds-dropdown {
  position: relative;
}
.ds-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  line-height: 1;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px;
  background: var(--card, #fff);
  cursor: pointer;
}

.ds-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 240px;
  max-width: 420px;
  width: max-content;
  z-index: 1000;

  border: 1px solid var(--border, #e5e7eb);
  border-radius: 10px;
  background: var(--popover, #fff);
  box-shadow: 0 12px 40px rgba(0,0,0,.12);

  max-height: 320px;
  overflow-y: auto;
}
.ds-menu.hidden { display: none; }

.ds-menu .ds-search {
  position: sticky;
  top: 0;
  background: inherit;
  padding: 8px;
  border-bottom: 1px solid var(--border, #e5e7eb);
}
.ds-menu .ds-search input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px;
  outline: none;
}

.ds-item {
  display: flex;
  align-items: center;
  justify-content: space-between;

  gap: 6px;
  padding: 8px 12px;
  cursor: pointer;
}

.ds-item .ds-title {
  flex: 1 1 auto;                
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;        
}

.ds-item .ds-del {
  flex: 0 0 auto;                
  border: 0;
  background: transparent;
  color: #6b7280;
  cursor: pointer;
  padding: 2px 6px;
}

.ds-item .ds-del:hover {
  color: #ef4444;
}

.ds-empty {
  padding: 12px;
  color: #6b7280;
}

@media (max-width: 480px) {
  .ds-menu { min-width: 200px; max-width: 90vw; }
}

/* Сделаем header-btn чуть компактнее и по центру */
.header .header-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  line-height: 1;        /* не распирает по высоте */
  padding: 6px 10px;     /* чуть компактнее */
  font-weight: 600;      /* читаемый, как на скрине хочется */
}

/* Состояние "включено" через aria-pressed */
.header-btn[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(234, 88, 12, 0.08);
}

/* Hover для консистентности */
.header-btn:hover {
  background: var(--card-hover);
}

#openModelSettings.btn-secondary{
  height:36px;padding:0 12px;border-radius:var(--radius);
  border:1px solid var(--border); background:var(--card); color:var(--foreground);
}
#openModelSettings.btn-secondary:hover{
  border-color: var(--accent); color: var(--accent);
}
#modelSettingsPanel,
#modelSettingsPanel * {
  font: inherit;
  line-height: inherit;
}

/* чтобы поля и кнопки не подменяли системный шрифт */
#modelSettingsPanel input,
#modelSettingsPanel textarea,
#modelSettingsPanel button {
  font: inherit;
}

/* Sources section styles */
.node-sources {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: rgba(249, 250, 251, 0.5);
}

.sources-header {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 8px;
}

.sources-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.source-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
  transition: all 0.2s ease;
}

.source-item:hover {
  border-color: var(--accent);
  background: var(--card-hover);
}

.source-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.source-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-pages {
  font-size: 11px;
  color: var(--muted);
}

.source-download-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  margin-left: 8px;
}

.source-download-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(234, 88, 12, 0.08);
}

.source-download-btn:active {
  transform: scale(0.95);
}