@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --bg: #1e1e1e;
    --surface: #262626;
    --surface-variant: #303030;
    --font-interface: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-text: var(--font-interface);
    --primary: #7f6df2;
    --primary-hover: #6f5ce0;
    --danger: #e45858;
    --danger-hover: #c94444;
    --text: #dcddde;
    --text-light: #999999;
    --hover: rgba(255, 255, 255, 0.05);
    --hover-strong: rgba(255, 255, 255, 0.08);
    --border: rgba(255, 255, 255, 0.07);
    --elevation-1: none;
    --elevation-2: none;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font-interface);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

::selection { background: rgba(138,92,245,0.35); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ── Transitions ── */

button, a, .tab, .btn, .settings-rail-item, .tool-chip {
    transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

/* ── Header ── */

.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 6px 16px;
    display: flex;
    align-items: center;
    gap: 24px;
}

.header h1 {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
}

.tabs {
    display: flex;
    gap: 2px;
}

.tab {
    padding: 6px 13px;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    border-radius: 6px;
    color: var(--text-light);
    font-size: 14px;
}

.tab:hover { background: var(--hover); }
.tab.active {
    background: transparent;
    color: var(--text);
    border-bottom: 2px solid var(--primary);
    border-radius: 0;
}
.tab.settings-muted-active {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}

.header-logout-btn {
    margin-left: auto;
    padding: 5px 10px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 6px;
    color: var(--text-light);
    font-size: 13px;
    transition: background-color 120ms ease, color 120ms ease;
}

.header-logout-btn:hover {
    background: rgba(220, 70, 90, 0.18);
    color: var(--text);
}

.settings-btn {
    padding: 6px 10px;
    border: none;
    background: transparent;
    color: var(--text-light);
    font-size: 15px;
    border-radius: 6px;
    cursor: pointer;
}

.settings-btn:hover { background: var(--hover); }
.settings-btn.active { background: transparent; color: var(--primary); }
.settings-btn.active:hover { background: var(--hover); color: var(--primary); }

/* ── Settings page ── */

.settings-page {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 24px;
    max-width: 1400px;
    margin: 20px auto;
    padding: 0 24px;
}

.settings-rail {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    height: fit-content;
}

.settings-rail h2 {
    font-size: 15px;
    margin: 4px 4px 12px;
}

.settings-rail-item {
    display: block;
    width: 100%;
    padding: 9px 10px;
    border: none;
    background: transparent;
    color: var(--text-light);
    text-align: left;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

.settings-rail-item:hover { background: var(--hover); }
.settings-rail-item.active { background: var(--primary); color: white; }

.settings-close-btn {
    width: 100%;
    margin-top: 14px;
}

.settings-pane {
    min-width: 0;
}

/* ── Login ── */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 32px;
    width: 400px;
}

.login-card h1 {
    font-size: 20px;
    margin-bottom: 8px;
}

.login-subtitle {
    color: var(--text-light);
    font-size: 14px;
    margin-bottom: 20px;
}

.login-card .form-group {
    margin-bottom: 14px;
}

.login-btn {
    width: 100%;
    padding: 10px;
    margin-top: 4px;
    background: var(--primary, #4f46e5);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

.login-btn:hover {
    opacity: 0.9;
}

.login-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    border-radius: 6px;
    padding: 8px 12px;
    margin-bottom: 14px;
    font-size: 13px;
}

/* ── Content ── */

.content {
    max-width: 1200px;
    margin: 20px auto;
    padding: 0 24px;
}

.content-wide {
    max-width: none;
}

.content-markdown {
    margin: 0;
    padding: 0;
}

/* ── Tables ── */

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: 8px;
    overflow: hidden;
}

th, td {
    padding: 10px 14px;
    text-align: left;
    line-height: 1.5;
    border-bottom: 1px solid var(--border);
    word-break: break-word;
    overflow-wrap: anywhere;
}

th {
    background: var(--surface-variant);
    font-weight: 600;
    font-size: 13px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.03); }

.actions { white-space: nowrap; }

/* ── Buttons ── */

button { cursor: pointer; font-family: inherit; color: var(--text); }

.btn {
    padding: 7px 14px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 14px;
}

.btn:hover { background: var(--hover-strong); }

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

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

.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.btn-danger:hover { background: var(--danger-hover); }

.btn-sm { padding: 4px 10px; }

.btn-icon {
    padding: 4px 8px;
    border: none;
    background: transparent;
    font-size: 15px;
    border-radius: 4px;
}

.btn-icon:hover { background: var(--hover); }
.btn-icon.edit:hover { color: var(--primary); }
.btn-icon.delete:hover { color: var(--danger); }

/* ── Toolbar ── */

.toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    align-items: center;
}

.toolbar .spacer { flex: 1; }

/* ── Forms ── */

.form-card {
    background: var(--surface);
    padding: 18px;
    border-radius: 8px;
    margin-bottom: 14px;
}

.form-row {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
    align-items: flex-start;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

input, select, textarea {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    background: var(--bg);
    color: var(--text);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(138,92,245,0.15);
}

textarea {
    min-height: 80px;
    resize: vertical;
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.credential-status-card {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    padding: 14px;
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}

.credential-status-card h4 {
    margin: 0 0 4px;
}

.credential-status-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(106,192,144,0.2);
    color: #6ac090;
    font-weight: 700;
    flex: 0 0 auto;
}

.credential-warning {
    color: var(--danger);
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 12px;
}

/* ── Status badges ── */

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
}

.badge-pending { background: rgba(224,180,72,0.15); color: #e0b448; }
.badge-running { background: rgba(138,92,245,0.15); color: #8A5CF5; }
.badge-completed { background: rgba(106,192,144,0.15); color: #6ac090; }
.badge-failed { background: rgba(228,88,88,0.15); color: #e45858; }

/* ── Utilities ── */

.error-msg {
    color: var(--danger);
    padding: 8px 0;
    font-size: 14px;
}

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

.truncate {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.truncate-sm { max-width: 180px; }

.cell-wrap {
    display: block;
    max-width: 400px;
}

.tool-list {
    margin-top: 8px;
    padding: 12px;
    background: var(--bg);
    border-radius: 6px;
}

.tool-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    font-size: 13px;
    margin: 2px 4px 2px 0;
}

.tool-chip button {
    border: none;
    background: transparent;
    color: var(--danger);
    font-size: 14px;
    padding: 0 2px;
}

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

.note {
    color: var(--text-light);
    font-size: 13px;
    font-style: italic;
    margin-top: 16px;
}

/* ── Teach ── */

.graph-page {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: calc(100vh - 140px);
}

.graph-page > .toolbar {
    margin-bottom: 0;
}

.graph-search {
    min-width: 320px;
}

.graph-force-controls {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.graph-force-slider {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    align-items: center;
    background: var(--surface);
    border-radius: 8px;
    padding: 4px 12px;
}

.graph-force-label,
.graph-force-value {
    font-size: 13px;
    color: var(--text-light);
}

.graph-force-slider input {
    width: 100%;
}

.graph-status {
    color: #6ac090;
    font-size: 13px;
}

.graph-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 440px 440px;
    gap: 16px;
    align-items: start;
    flex: 1;
    min-height: 0;
}

.graph-graph-card {
    background: var(--surface);
    border-radius: 8px;
    padding: 12px;
    min-height: 0;
    height: calc(100vh - 200px);
}

.graph-graph {
    display: block;
    width: 100%;
    height: 100%;
}

.graph-inspector {
    position: sticky;
    top: 20px;
}

.graph-inspector .form-card {
    margin-bottom: 0;
    min-height: calc(100vh - 200px);
}

/* ── Chat ── */

.graph-chat-panel {
    position: sticky;
    top: 20px;
}

.graph-chat {
    background: var(--surface);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 200px);
    max-height: calc(100vh - 200px);
}

.graph-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
}

.graph-chat-header h3 {
    font-size: 15px;
}

.graph-chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.graph-chat-typing {
    padding: 6px 16px;
    font-size: 13px;
    color: var(--text-light);
    font-style: italic;
    border-top: 1px solid var(--border);
}

.graph-chat-error {
    padding: 10px 16px;
    font-size: 13px;
    color: var(--error, #e53e3e);
    text-align: center;
}

.chat-msg {
    max-width: 88%;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 14px;
    word-wrap: break-word;
    white-space: pre-wrap;
    line-height: 1.4;
}

.chat-msg-user {
    align-self: flex-end;
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 2px;
}

.chat-msg-assistant {
    align-self: flex-start;
    background: var(--surface-variant);
    color: var(--text);
    border-bottom-left-radius: 2px;
}

.chat-msg-error {
    align-self: center;
    background: rgba(228,88,88,0.12);
    color: var(--danger);
    font-size: 13px;
    max-width: 100%;
    text-align: center;
}

.graph-chat-input {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    align-items: flex-end;
}

.graph-chat-input textarea {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    resize: none;
    font-size: 14px;
}

.graph-chat-input button {
    flex-shrink: 0;
    align-self: flex-end;
}

.graph-chat-input button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── SQL Markdown workspace ── */

.markdown-workspace {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    gap: 0;
    height: calc(100vh - 51px);
}

.markdown-sidebar,
.markdown-editor-pane {
    border-radius: 0;
    min-height: 0;
}

.markdown-sidebar {
    padding: 12px;
    overflow: auto;
    background: var(--surface);
    border-right: 1px solid var(--border);
}

.markdown-editor-pane {
    background: var(--bg);
}

.markdown-sidebar-header,
.markdown-folder-row,
.markdown-editor-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.markdown-sidebar-header {
    justify-content: space-between;
    margin-bottom: 12px;
}

.markdown-sidebar-header h2,
.markdown-editor-header h2 {
    font-size: 16px;
}

.markdown-search-form {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.markdown-search {
    min-width: 0;
    flex: 1;
}

.markdown-search-results-block {
    margin-bottom: 10px;
}

.markdown-search-summary,
.markdown-search-empty {
    margin: 0 0 6px;
    color: var(--text-light);
    font-size: 12px;
}

.markdown-search-results {
    max-height: 220px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    padding: 4px;
    outline: none;
}

.markdown-search-results:focus {
    border-color: var(--primary);
}

.markdown-search-result {
    display: block;
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text-light);
    text-align: left;
    border-radius: 6px;
    padding: 6px 8px;
}

.markdown-search-result:hover,
.markdown-search-result.active {
    background: var(--hover-strong);
    color: var(--text);
}

.markdown-tree {
    margin-top: 12px;
}

.markdown-source,
.markdown-folder-group {
    margin-bottom: 8px;
}

.markdown-tree-children {
    margin-left: 12px;
    border-left: 1px solid var(--border);
    padding-left: 8px;
}

.markdown-folder,
.markdown-entry {
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text-light);
    text-align: left;
    border-radius: 6px;
}

.markdown-folder {
    flex: 1;
    min-width: 0;
    padding: 7px 8px;
    font-weight: 600;
}

.markdown-folder:hover,
.markdown-entry:hover,
.markdown-folder.active,
.markdown-entry.active {
    background: var(--hover-strong);
    color: var(--text);
}

.markdown-folder-label:hover {
    background: transparent;
    color: var(--text-light);
}

.markdown-entry-list {
    margin-left: 12px;
    border-left: 1px solid var(--border);
    padding-left: 8px;
}

.markdown-field-list {
    margin: 6px 0 8px 20px;
    color: var(--text-light);
    font-size: 12px;
}

.markdown-field-list-form {
    margin: 0 0 14px 0;
}

.markdown-field-list-label {
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
}

.markdown-field-chips,
.markdown-properties-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.markdown-field-chip {
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-variant);
    padding: 3px 8px;
}

.markdown-checkbox-list {
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    max-height: 180px;
    overflow: auto;
    padding: 6px 8px;
}

.form-group .markdown-checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
    font-size: 14px;
    font-weight: 400;
    color: var(--text);
    text-transform: none;
    letter-spacing: normal;
}

.markdown-checkbox-row input {
    margin: 0;
}

.markdown-filter-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 8px 0;
}

.markdown-filter-row {
    display: flex;
    flex: 1 1 240px;
    max-width: 280px;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-variant);
}

.markdown-filter-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    color: var(--text-light);
    font-size: 13px;
}

.markdown-filter-control {
    gap: 3px;
}

.markdown-filter-control input,
.markdown-filter-control select {
    width: 100%;
    box-sizing: border-box;
}

.markdown-entry {
    display: block;
    padding: 6px 8px;
    margin: 2px 0;
}

.markdown-entry-title,
.markdown-entry-path {
    display: block;
}

.markdown-entry-path,
.markdown-editor-header p {
    color: var(--text-light);
    font-size: 12px;
}

.markdown-editor-pane {
    padding: 16px 28px;
    overflow: auto;
}

.markdown-editor,
.markdown-textarea {
    height: 100%;
}

.markdown-editor {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

.markdown-editor-header {
    justify-content: space-between;
}

.markdown-properties {
    border: none;
    border-radius: 0;
    padding: 8px 0;
    background: var(--bg);
}

.markdown-properties-title {
    margin: 0 12px 6px;
    color: var(--text-light);
    font-size: 12px;
    font-weight: 600;
}

.markdown-properties-grid {
    display: block;
}

.markdown-property-row {
    display: grid;
    grid-template-columns: minmax(120px, 220px) minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    padding: 5px 12px;
}

.markdown-property-row:hover {
    background: var(--hover);
}

.markdown-property-name {
    color: var(--text-light);
    font-weight: 500;
}

.markdown-property-input {
    width: 100%;
    min-width: 0;
    border: 1px solid transparent;
    border-radius: 5px;
    background: transparent;
    color: var(--text);
    font: inherit;
    outline: none;
    padding: 3px 6px;
}

.markdown-property-input:hover,
.markdown-property-input:focus {
    border-color: var(--border);
    background: var(--bg);
}

.markdown-property-input:disabled {
    color: var(--text-light);
}

.markdown-textarea {
    min-height: 520px;
    resize: none;
    font-family: var(--font-text);
    line-height: 1.55;
    background: var(--bg);
    border: none;
    border-radius: 0;
    padding: 0;
}

.markdown-textarea:focus {
    border-color: transparent;
    box-shadow: none;
}

.empty-state {
    padding: 40px;
    color: var(--text-light);
    text-align: center;
}

/* ── Bases ── */

.bases-pane {
    padding: 16px;
}

.bases-table-wrap {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
    overflow: auto;
}

.bases-table {
    min-width: max-content;
    border-radius: 0;
}

.bases-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    white-space: nowrap;
}

.bases-table td {
    padding: 4px;
    min-width: 160px;
    max-width: 320px;
    cursor: cell;
    user-select: none;
}

.bases-table tr.dirty td {
    background: rgba(127, 109, 242, 0.08);
}

.bases-table td.bases-selected-cell {
    background: rgba(127, 109, 242, 0.18);
    outline: 1px solid var(--primary);
    outline-offset: -1px;
}

.bases-table tr.dirty td.bases-selected-cell {
    background: rgba(127, 109, 242, 0.26);
}

.bases-table td.bases-editing-cell {
    cursor: text;
    user-select: text;
    outline: 2px solid var(--primary);
    outline-offset: -2px;
}

.bases-cell-input {
    width: 100%;
    min-width: 140px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: var(--text);
    padding: 6px 8px;
    font: inherit;
}

.bases-cell-input:focus {
    border-color: transparent;
    background: transparent;
    outline: none;
}

.bases-editing-cell .bases-cell-input:focus {
    border-color: var(--primary);
    background: var(--bg);
}

.bases-cell-input:disabled {
    color: var(--text-light);
    cursor: not-allowed;
}
