:root {
    --bg: #0d1117;
    --panel: #161b22;
    --panel-alt: #1f2631;
    --text: #e6edf3;
    --muted: #9da7b3;
    --border: #30363d;
    --accent: #58a6ff;
    --success: #2ea043;
    --danger: #da3633;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Inter", "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.4rem;
    border-bottom: 1px solid var(--border);
    background: #0f141b;
}

.brand h1 {
    margin: 0;
    font-size: 1.4rem;
}

.subtitle {
    margin: 0.2rem 0 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.subtitle-credit {
    color: #b9c3cf;
    font-size: 0.92rem;
    line-height: 1.35;
}

.subtitle-credit a,
.subtitle-credit a:visited {
    color: #8ab4ff;
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 2px;
    font-weight: 600;
}

.subtitle-credit a:hover,
.subtitle-credit a:focus-visible {
    color: #a8c7ff;
}

.pill {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.35rem 0.7rem;
    font-size: 0.85rem;
}

.nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.8rem 1.2rem;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}

.nav a {
    color: var(--text);
    text-decoration: none;
    background: #222b37;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.45rem 0.7rem;
    font-size: 0.9rem;
}

.nav a.active {
    color: #ffffff;
    background: #1f6feb;
    border-color: #58a6ff;
    box-shadow: 0 0 0 1px rgba(88, 166, 255, 0.28);
}

.container {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 1rem 1.2rem 2rem;
}

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.grid {
    display: grid;
    gap: 1rem;
}

.stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.card.chat-panel > p {
    font-size: 1rem;
    line-height: 1.5;
}

.chat-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.chat-response {
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    overflow-wrap: anywhere;
}

.chat-response > p {
    white-space: pre-line;
}

.chat-comparison {
    line-height: 1.6;
}

#chatDepth {
    width: 5rem;
}

.chat-panel button:disabled {
    opacity: 0.6;
    cursor: wait;
}

.two-columns {
    grid-template-columns: repeat(auto-fit, minmax(460px, 1fr));
}

.card h2, .card h3, .card p {
    margin-top: 0;
}

.card p:last-child {
    margin-bottom: 0;
}

.card > p {
    font-size: 1.8rem;
}

.form,
.inline-form {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.inline-form {
    flex-direction: row;
    align-items: center;
}

.stacked-mobile {
    flex-wrap: wrap;
}

input,
textarea,
button,
select {
    border: 1px solid var(--border);
    background: var(--panel-alt);
    color: var(--text);
    border-radius: 8px;
    padding: 0.55rem 0.7rem;
    font: inherit;
}

button,
.btn {
    cursor: pointer;
    background: #238636;
    border-color: #2ea043;
    color: #fff;
    font-weight: 600;
}

button:hover,
.btn:hover {
    filter: brightness(1.06);
}

button.danger {
    background: #b62324;
    border-color: #da3633;
}

.delete-password-dialog {
    width: min(440px, calc(100% - 2rem));
    padding: 1.4rem;
    border: 1px solid var(--border);
    border-top: 3px solid var(--danger);
    border-radius: 12px;
    background: var(--panel);
    color: var(--text);
    box-shadow: 0 20px 60px #0008;
}

.delete-password-dialog::backdrop {
    background: #000b;
    backdrop-filter: blur(3px);
}

.delete-password-dialog h2,
.delete-password-dialog p {
    margin: 0 0 0.5rem;
}

.delete-password-dialog input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.delete-password-field {
    position: relative;
}

.delete-password-field input {
    width: 100%;
    padding-right: 3rem;
}

button.delete-password-toggle {
    position: absolute;
    top: 50%;
    right: 0.35rem;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    background: transparent;
    border-color: transparent;
    color: var(--muted);
}

button.delete-password-toggle:hover {
    color: var(--text);
    background: var(--panel);
}

button.delete-password-toggle:focus-visible {
    outline: 2px solid var(--accent);
}

.delete-password-eye-slash {
    display: none;
}

.delete-password-toggle[aria-pressed="true"] .delete-password-eye-slash {
    display: block;
}

.delete-password-hint {
    font-size: 0.85rem;
}

.delete-password-dialog .delete-password-actions {
    justify-content: flex-end;
    margin-top: 0.5rem;
}

button.delete-password-cancel {
    background: var(--panel-alt);
    border-color: var(--border);
    color: var(--text);
}

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

table {
    width: 100%;
    border-collapse: collapse;
}

.card {
    overflow-x: auto;
}

th, td {
    padding: 0.55rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.experience-list,
.regions {
    display: grid;
    gap: 0.8rem;
}

.preview-list {
    display: grid;
    gap: 0.8rem;
}

.preview-item {
    background: #111822;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.8rem;
}

.preview-item pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    color: #c9d1d9;
    background: #0d1117;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
}

.editor-container {
    display: grid;
    grid-template-columns: 64px 1fr;
    height: clamp(180px, calc(100vh - 430px), 720px);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: #0d1117;
}

.line-numbers {
    margin: 0;
    padding: 0.75rem 0.5rem;
    background: #111822;
    color: var(--muted);
    border-right: 1px solid var(--border);
    text-align: right;
    user-select: none;
    overflow: hidden;
    line-height: 1.4;
    font-family: "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.9rem;
}

.dataset-editor {
    border: 0;
    border-radius: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
    resize: none;
    overflow: auto;
    background: #0d1117;
    color: #c9d1d9;
    line-height: 1.4;
    font-family: "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.9rem;
}

.dataset-editor:focus {
    outline: none;
}

.link-btn {
    display: inline-flex;
    align-items: center;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    background: #222b37;
    font-weight: 600;
}

.visible-link {
    color: #7ab7ff;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.visible-link:hover,
.visible-link:focus-visible {
    color: #9cd0ff;
}

.table-action-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 72px;
    padding: 0.35rem 0.6rem;
    border-radius: 8px;
    border: 1px solid transparent;
    font-weight: 700;
    text-decoration: none;
    line-height: 1;
}

.table-action-link:visited {
    color: inherit;
}

.table-action-edit {
    background: linear-gradient(90deg, #6366f1, #7c3aed);
    border-color: #7c3aed;
    color: #ffffff;
}

.table-action-download {
    background: linear-gradient(90deg, #0ea5e9, #0284c7);
    border-color: #0284c7;
    color: #ffffff;
}

.table-action-edit:hover,
.table-action-edit:focus-visible,
.table-action-download:hover,
.table-action-download:focus-visible {
    filter: brightness(1.08);
}

.toolbar,
.editor-tools {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.toolbar {
    margin-bottom: 0.4rem;
}

.editor-tools {
    margin-bottom: 0.7rem;
}

.format-status {
    margin: 0 0 0.5rem;
    font-weight: 600;
}

.toolbar button,
.editor-tools button {
    border-radius: 10px;
}

.btn-op-save {
    background: linear-gradient(90deg, #6366f1, #8b5cf6);
    border-color: #7c3aed;
}

.btn-op-validate {
    background: linear-gradient(90deg, #16a34a, #22c55e);
    border-color: #22c55e;
}

.btn-op-quality {
    background: linear-gradient(90deg, #0ea5e9, #06b6d4);
    border-color: #06b6d4;
}

.btn-op-strict-qa {
    background: linear-gradient(90deg, #f59e0b, #fbbf24);
    border-color: #f59e0b;
    color: #0f172a;
}

.btn-op-strict-sentence {
    background: linear-gradient(90deg, #818cf8, #6366f1);
    border-color: #6366f1;
}

.btn-op-convert-qa {
    background: linear-gradient(90deg, #fb7185, #f43f5e);
    border-color: #f43f5e;
}

.btn-op-convert-sentence {
    background: linear-gradient(90deg, #34d399, #10b981);
    border-color: #10b981;
}

.btn-op-convert-tinyllama {
    background: linear-gradient(90deg, #d946ef, #a21caf);
    border-color: #a21caf;
}

.btn-op-preview {
    background: linear-gradient(90deg, #334155, #1e293b);
    border-color: #334155;
}

button:disabled,
.toolbar button:disabled,
.editor-tools button:disabled {
    background: #2a3241;
    border-color: #404a5c;
    color: #92a0b5;
    cursor: not-allowed;
    filter: none;
    opacity: 0.75;
}

.tool-input {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--muted);
    font-size: 0.88rem;
}

.tool-input input {
    width: 150px;
}

.tool-report {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    color: #c9d1d9;
    background: #0d1117;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
}

.experience,
.region {
    background: #111822;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.8rem;
}

.experience header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.path {
    font-size: 0.95rem;
    color: var(--text);
}

.graph-frame {
    width: 100%;
    height: 780px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #0f141b;
}

.graph-3d-frame {
    width: 100%;
    height: min(82vh, 920px);
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #0f141b;
    overflow: hidden;
}

.graph-3d-wrap {
    --inspector-space: calc(min(360px, 36vw) + 16px);
    position: relative;
    padding-right: var(--inspector-space);
}

.node-info-panel {
    position: absolute;
    top: 14px;
    right: 0;
    width: min(360px, 36vw);
    max-height: calc(100% - 28px);
    overflow: auto;
    z-index: 5;
    background: rgba(17, 24, 34, 0.92);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem 0.85rem;
    backdrop-filter: blur(3px);
}

.node-info-panel h3,
.node-info-panel h4 {
    margin: 0 0 0.45rem 0;
}

.node-info-content {
    margin-bottom: 0.6rem;
}

.node-search {
    margin-bottom: 0.7rem;
    padding-bottom: 0.55rem;
    border-bottom: 1px dashed rgba(157, 167, 179, 0.25);
}

.node-search-actions {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

#findNodeButton {
    padding: 0.42rem 0.65rem;
}

#nodeSearchStatus {
    font-size: 0.85rem;
}

.node-info-row {
    display: flex;
    justify-content: space-between;
    gap: 0.8rem;
    padding: 0.2rem 0;
    border-bottom: 1px dashed rgba(157, 167, 179, 0.25);
}

.node-info-row span {
    color: var(--muted);
    font-size: 0.9rem;
}

.node-info-row strong {
    font-size: 0.92rem;
    text-align: right;
    word-break: break-word;
}

.node-info-links {
    margin: 0;
    padding-left: 1rem;
}

.node-info-links li {
    margin-bottom: 0.35rem;
    font-size: 0.9rem;
}

.node-info-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin: 0.35rem 0;
}

.node-info-field > span {
    color: var(--muted);
    font-size: 0.86rem;
}

.node-info-field input,
.node-info-field select {
    padding: 0.42rem 0.52rem;
    font-size: 0.9rem;
}

.node-info-actions {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin: 0.55rem 0 0.75rem;
}

#saveNodeButton {
    padding: 0.45rem 0.65rem;
}

#nodeSaveStatus {
    font-size: 0.85rem;
}

.node-move {
    margin: 0.35rem 0 0.85rem;
}

.node-legend {
    margin: 0.25rem 0 0.8rem;
    padding-top: 0.45rem;
    border-top: 1px dashed rgba(157, 167, 179, 0.25);
}

.node-legend-list {
    margin: 0.4rem 0 0;
    padding-left: 0;
    list-style: none;
    display: grid;
    gap: 0.28rem;
}

.node-legend-list li {
    display: flex;
    align-items: center;
    gap: 0.42rem;
    font-size: 0.86rem;
}

.node-legend-swatch {
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 50%;
    background: var(--legend-color, #58a6ff);
    border: 1px solid rgba(230, 237, 243, 0.35);
    flex: 0 0 auto;
}

.node-move-grid {
    margin-top: 0.4rem;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-areas:
        ". up ."
        "left down right";
    gap: 0.35rem;
}

#moveUpButton { grid-area: up; }
#moveLeftButton { grid-area: left; }
#moveDownButton { grid-area: down; }
#moveRightButton { grid-area: right; }

.node-move-btn {
    min-height: 2.1rem;
    font-size: 1rem;
    line-height: 1;
    padding: 0.3rem 0.45rem;
}

.flash-wrap {
    margin-bottom: 1rem;
}

.flash {
    border-radius: 8px;
    padding: 0.7rem 0.8rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border);
}

.flash-success {
    background: rgba(46, 160, 67, 0.18);
    border-color: rgba(46, 160, 67, 0.7);
}

.flash-error {
    background: rgba(218, 54, 51, 0.18);
    border-color: rgba(218, 54, 51, 0.7);
}

.file-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 0.8rem;
}

.file-list li {
    background: #111822;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.7rem;
}

.actions {
    margin-top: 0.6rem;
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.actions form {
    margin: 0;
}

.import-progress-wrap {
    display: grid;
    gap: 0.4rem;
    margin-top: 0.4rem;
}

.import-progress-bar {
    width: 100%;
    height: 0.7rem;
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: #0f141b;
}

.import-progress-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #1f6feb, #2ea043);
    transition: width 0.2s ease;
}

.import-progress-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

@media (max-width: 700px) {
    .inline-form {
        flex-direction: column;
        align-items: stretch;
    }
}

@media (max-width: 1100px) {
    .graph-3d-wrap {
        padding-right: 0;
    }

    .node-info-panel {
        position: static;
        width: 100%;
        max-height: none;
        margin-top: 0.8rem;
    }
}

.readme-content {
    line-height: 1.6;
    overflow-wrap: anywhere;
}

.readme-content h1,
.readme-content h2,
.readme-content h3,
.readme-content h4 {
    margin: 1.4rem 0 0.6rem;
    padding-bottom: 0.3rem;
}

.readme-content h1,
.readme-content h2 {
    border-bottom: 1px solid var(--border);
}

.readme-content > :first-child {
    margin-top: 0;
}

.readme-content a {
    color: var(--accent);
}

.readme-content code {
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.1rem 0.35rem;
    font-size: 0.9em;
}

.readme-content pre {
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.8rem 1rem;
    overflow-x: auto;
}

.readme-content pre code {
    background: none;
    border: none;
    padding: 0;
    overflow-wrap: normal;
}

.readme-content table {
    border-collapse: collapse;
    margin: 0.8rem 0;
    display: block;
    overflow-x: auto;
}

.readme-content th,
.readme-content td {
    border: 1px solid var(--border);
    padding: 0.4rem 0.7rem;
    text-align: left;
}

.readme-content th {
    background: var(--panel-alt);
}

.readme-content blockquote {
    margin: 0.8rem 0;
    padding: 0.2rem 1rem;
    border-left: 3px solid var(--accent);
    color: var(--muted);
}

.readme-content hr {
    border: none;
    border-top: 1px solid var(--border);
}
