/* ===== Design Tokens ===== */
:root {
    --bg-base: #0f172a;
    --bg-surface: #1e293b;
    --bg-elevated: #334155;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-blue: #3b82f6;
    --accent-teal: #0d9488;
    --accent-amber: #f59e0b;
    --accent-red: #ef4444;
    --accent-green: #10b981;
    --radius: 8px;
    --sidebar-width: 240px;
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-base);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== App Layout ===== */
.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-surface);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    border-right: 1px solid rgba(255,255,255,0.06);
}

.sidebar-header {
    padding: 20px 16px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-logo {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: var(--accent-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.sidebar-user {
    padding: 8px 16px 16px;
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-user button {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}
.sidebar-user button:hover { background: var(--bg-elevated); color: var(--text-secondary); }

.sidebar-nav { flex: 1; padding: 0 8px; }

.nav-group { margin-bottom: 16px; }

.nav-group-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding: 8px 12px 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    text-decoration: none;
}

.nav-item:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    text-decoration: none;
}

.nav-item.active {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-blue);
}

.nav-item-icon {
    width: 18px;
    text-align: center;
    font-size: 14px;
    flex-shrink: 0;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px 32px;
    min-width: 0;
}

.page-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 20px;
}

.page-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: -16px;
    margin-bottom: 20px;
}

/* ===== Cards ===== */
.card {
    background: var(--bg-surface);
    border-radius: var(--radius);
    padding: 16px;
}

.card-header {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* ===== Stat Cards ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-surface);
    border-radius: var(--radius);
    padding: 16px;
}

.stat-card .stat-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.stat-card .stat-value {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.stat-card .stat-sub {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.badge-blue { background: rgba(59,130,246,0.15); color: var(--accent-blue); }
.badge-teal { background: rgba(13,148,136,0.15); color: var(--accent-teal); }
.badge-green { background: rgba(16,185,129,0.15); color: var(--accent-green); }
.badge-amber { background: rgba(245,158,11,0.15); color: var(--accent-amber); }
.badge-red { background: rgba(239,68,68,0.15); color: var(--accent-red); }
.badge-slate { background: rgba(100,116,139,0.15); color: var(--text-secondary); }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent-blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #2563eb; }

.btn-secondary { background: var(--bg-elevated); color: var(--text-primary); }
.btn-secondary:hover:not(:disabled) { background: #475569; }

.btn-danger { background: var(--accent-red); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-elevated); color: var(--text-primary); }

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

/* ===== Forms ===== */
.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-base);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    transition: border-color 0.15s;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.form-input::placeholder, .form-textarea::placeholder {
    color: var(--text-muted);
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.5;
}

.form-label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-group { margin-bottom: 16px; }

/* Toggle switch */
.toggle {
    position: relative;
    width: 36px;
    height: 20px;
    background: var(--bg-elevated);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
}
.toggle.active { background: var(--accent-blue); }
.toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
}
.toggle.active::after { transform: translateX(16px); }

/* ===== Tables ===== */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    font-size: 13px;
}

.data-table tr:hover td {
    background: rgba(255,255,255,0.02);
}

/* ===== Tabs ===== */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    margin-bottom: 16px;
}

.tab {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}

.tab:hover { color: var(--text-secondary); }
.tab.active { color: var(--accent-blue); border-bottom-color: var(--accent-blue); }

/* ===== Pagination ===== */
.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 16px;
    justify-content: center;
}

.pagination .page-btn {
    padding: 4px 10px;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 600;
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: none;
    cursor: pointer;
}
.pagination .page-btn:hover { background: var(--bg-elevated); }
.pagination .page-btn.active { background: var(--accent-blue); color: #fff; }
.pagination .page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== Toast Notifications ===== */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    color: #fff;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: opacity 0.3s;
    max-width: 400px;
}

.toast.success { background: var(--accent-green); }
.toast.error { background: var(--accent-red); }
.toast.warning { background: var(--accent-amber); color: #1e293b; }
.toast.info { background: var(--accent-blue); }

/* ===== Confirmation Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal {
    background: var(--bg-surface);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 480px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.modal-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 8px;
}

.modal-message {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ===== Loading / Empty States ===== */
.loading-state {
    text-align: center;
    padding: 48px;
    color: var(--text-muted);
}

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--bg-elevated);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

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

.empty-state .empty-icon {
    font-size: 36px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.empty-state p {
    font-size: 13px;
    max-width: 300px;
    margin: 0 auto;
}

/* ===== Two-Panel Layout (Skills, etc.) ===== */
.panel-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 16px;
    min-height: calc(100vh - 120px);
}

.panel-left {
    background: var(--bg-surface);
    border-radius: var(--radius);
    overflow-y: auto;
}

.panel-right {
    background: var(--bg-surface);
    border-radius: var(--radius);
    overflow-y: auto;
    padding: 16px;
}

.list-item {
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    transition: background 0.15s;
}
.list-item:hover { background: var(--bg-elevated); }
.list-item.active { background: rgba(59,130,246,0.1); }

/* ===== Filters Bar ===== */
.filters-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    align-items: center;
}

.filters-bar .form-input,
.filters-bar .form-select {
    width: auto;
    min-width: 160px;
}

/* ===== Chat UI ===== */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 120px);
    background: var(--bg-surface);
    border-radius: var(--radius);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.chat-message {
    margin-bottom: 16px;
    max-width: 80%;
}

.chat-message.user {
    margin-left: auto;
    background: var(--accent-blue);
    color: #fff;
    padding: 10px 14px;
    border-radius: 12px 12px 4px 12px;
}

.chat-message.assistant {
    background: var(--bg-elevated);
    padding: 10px 14px;
    border-radius: 12px 12px 12px 4px;
    line-height: 1.6;
}

.chat-message.assistant table {
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 12px;
    width: 100%;
}
.chat-message.assistant th,
.chat-message.assistant td {
    padding: 4px 8px;
    border: 1px solid rgba(255,255,255,0.1);
    text-align: left;
}
.chat-message.assistant th {
    background: rgba(255,255,255,0.05);
    font-weight: 600;
}

.chat-message.assistant code {
    background: rgba(0,0,0,0.3);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 12px;
}

.chat-message.assistant pre {
    background: rgba(0,0,0,0.3);
    padding: 8px 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}
.chat-message.assistant pre code {
    background: none;
    padding: 0;
}

.chat-input-bar {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.chat-input-bar input {
    flex: 1;
}

.suggested-chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding: 8px 16px 0;
}

.chip {
    padding: 4px 12px;
    border-radius: 99px;
    font-size: 12px;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    border: none;
    transition: background 0.15s;
}
.chip:hover { background: rgba(59,130,246,0.15); color: var(--accent-blue); }

.chat-thinking {
    color: var(--text-muted);
    font-style: italic;
    font-size: 12px;
}

.chat-tool-badge {
    display: inline-block;
    padding: 3px 10px;
    margin-bottom: 6px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 600;
    background: rgba(13,148,136,0.15);
    color: var(--accent-teal);
}

.chat-message.chat-error {
    background: rgba(239,68,68,0.12);
    border: 1px solid rgba(239,68,68,0.2);
    color: var(--accent-red);
}

/* ===== Section-specific overrides ===== */

/* Skills textarea */
.skill-textarea {
    width: 100%;
    min-height: 200px;
    padding: 12px;
    background: var(--bg-base);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.6;
    resize: vertical;
}
.skill-textarea:focus { outline: none; border-color: var(--accent-blue); }

/* Version history */
.version-timeline { display: flex; flex-direction: column; gap: 8px; }

.history-entry {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}

.history-entry .history-version {
    font-weight: 700;
    font-size: 12px;
    color: var(--accent-blue);
    min-width: 32px;
}

.history-entry .history-body { flex: 1; }

.history-entry .history-date {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

.action-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
}

.action-badge.action-example { background: rgba(16,185,129,0.15); color: var(--accent-green); }
.action-badge.action-rule { background: rgba(59,130,246,0.15); color: var(--accent-blue); }
.action-badge.action-hallucination { background: rgba(239,68,68,0.15); color: var(--accent-red); }
.action-badge.action-manual { background: rgba(245,158,11,0.15); color: var(--accent-amber); }
.action-badge.action-other { background: rgba(100,116,139,0.15); color: var(--text-secondary); }

/* File upload / drop zone */
.drop-zone {
    border: 2px dashed rgba(255,255,255,0.1);
    border-radius: var(--radius);
    padding: 32px;
    text-align: center;
    color: var(--text-muted);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}
.drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--accent-blue);
    background: rgba(59,130,246,0.05);
}

/* Inline code */
code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 11px;
}

/* Warning banner */
.warning-banner {
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.2);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}

.warning-banner h4 {
    color: var(--accent-red);
    font-size: 13px;
    margin-bottom: 4px;
}

.warning-banner p {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ===== Skills list — segmented filter + flat list ===== */
.segmented-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 12px 12px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.segmented-pill {
    flex: 1 1 auto;
    min-width: 0;
    display: inline-flex;
    align-items: baseline;
    justify-content: center;
    gap: 6px;
    padding: 6px 10px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
    white-space: nowrap;
    letter-spacing: 0.01em;
}
.segmented-pill:hover {
    background: rgba(255,255,255,0.03);
    color: var(--text-secondary);
}
.segmented-pill.active {
    background: rgba(59,130,246,0.12);
    color: var(--accent-blue);
    border-color: rgba(59,130,246,0.25);
}
.segmented-pill-label {
    text-transform: none;
}
.segmented-pill-count {
    font-size: 10px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    opacity: 0.65;
}
.segmented-pill.active .segmented-pill-count {
    opacity: 0.85;
}

.skill-search-wrap {
    padding: 10px 12px 8px;
}
.skill-search-wrap .form-input {
    font-size: 12px;
    padding: 7px 10px;
}

.skill-list-scroll {
    overflow-y: auto;
    max-height: calc(100vh - 260px);
    padding: 0 0 8px;
}

.skill-list-meta {
    padding: 8px 16px 10px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.skill-list-meta-type {
    color: var(--accent-blue);
    letter-spacing: 0.04em;
    text-transform: none;
    font-size: 11px;
}

.skill-item {
    display: grid;
    grid-template-columns: 28px 1fr auto auto;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    transition: background 0.1s ease;
}
.skill-item:hover {
    background: rgba(255,255,255,0.025);
}
.skill-item.active {
    background: rgba(59,130,246,0.1);
}

.skill-item-num {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    text-align: center;
}
.skill-item-num-dot {
    opacity: 0.4;
}
.skill-item.active .skill-item-num {
    color: var(--accent-blue);
}

.skill-item-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.skill-item.active .skill-item-name {
    font-weight: 600;
}

.type-tag {
    display: inline-flex;
    align-items: center;
    padding: 1px 6px;
    border-radius: 3px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.04em;
    line-height: 1.5;
}
.type-tag-blue {
    background: rgba(59,130,246,0.14);
    color: var(--accent-blue);
}
.type-tag-slate {
    background: rgba(148,163,184,0.14);
    color: var(--text-secondary);
}
.type-tag-teal {
    background: rgba(13,148,136,0.15);
    color: var(--accent-teal);
}

.skill-item-version {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 10px;
    font-weight: 500;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    min-width: 26px;
    text-align: right;
}

.skill-list-empty {
    padding: 32px 16px;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { padding: 16px; }
    .panel-layout { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
}
