:root {
    --bg: #0b0f17;
    --surface: #111827;
    --surface-2: #182234;
    --border: #263248;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --accent: #38bdf8;
    --ok: #10b981;
    --err: #ef4444;
    --warn: #f59e0b;
    --mono: 'Cascadia Code', 'Consolas', 'Courier New', monospace;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

code, pre, .kpi-mono {
    font-family: var(--mono);
}

.topbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 16px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.subtitle {
    margin: 2px 0 0;
    font-size: 12px;
    color: var(--muted);
}

.pulse-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--ok);
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.2);
}

.pulse-dot.err {
    background: var(--err);
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.2);
}

.topbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.btn {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    color: var(--text);
    background: var(--surface-2);
    transition: border-color 0.15s, background 0.15s;
}

.btn:hover {
    border-color: var(--accent);
}

.btn-primary {
    background: #0284c7;
    border-color: #0ea5e9;
    color: #fff;
}

.btn-primary:hover {
    background: #0369a1;
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.45);
    color: #fca5a5;
}

.btn-ghost {
    background: transparent;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px 24px 40px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 12px;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.kpi-label {
    font-size: 12px;
    color: var(--muted);
}

.kpi-value {
    font-size: 24px;
    font-weight: 700;
}

.kpi-ok .kpi-value { color: var(--ok); }
.kpi-err .kpi-value { color: var(--err); }

.kpi-mono {
    font-size: 13px;
    color: var(--accent);
    margin-top: 6px;
}

.main-grid {
    display: grid;
    grid-template-columns: 1.55fr 1fr;
    gap: 16px;
}

.bottom-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 1024px) {
    .main-grid, .bottom-grid {
        grid-template-columns: 1fr;
    }
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.panel-header h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid transparent;
}

.badge-ok { background: rgba(16, 185, 129, 0.14); color: #34d399; border-color: rgba(16, 185, 129, 0.35); }
.badge-err { background: rgba(239, 68, 68, 0.14); color: #f87171; border-color: rgba(239, 68, 68, 0.35); }
.badge-warn { background: rgba(245, 158, 11, 0.14); color: #fbbf24; border-color: rgba(245, 158, 11, 0.35); }
.badge-muted { background: rgba(148, 163, 184, 0.12); color: var(--muted); border-color: var(--border); }

.instances-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.instance-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.instance-card.offline {
    opacity: 0.65;
}

.inst-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.inst-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.inst-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 6px 12px;
    font-size: 12px;
    color: var(--muted);
}

.inst-meta b {
    color: var(--text);
    font-weight: 500;
}

.inst-error {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: #fecaca;
    border-radius: 6px;
    padding: 8px 10px;
    font-family: var(--mono);
    font-size: 12px;
    word-break: break-word;
}

.inst-query-ok {
    background: rgba(16, 185, 129, 0.08);
    border: 1px solid rgba(16, 185, 129, 0.25);
    color: #a7f3d0;
    border-radius: 6px;
    padding: 6px 10px;
    font-family: var(--mono);
    font-size: 12px;
    word-break: break-word;
}

.inst-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.sql-input {
    flex: 1;
    min-width: 220px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    color: var(--text);
    font-family: var(--mono);
    font-size: 12px;
}

.config-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.config-form label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--muted);
}

.config-form input, .config-form select {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 7px 10px;
    color: var(--text);
    font-size: 13px;
}

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

.form-feedback {
    font-size: 12px;
    min-height: 18px;
    color: var(--ok);
}

.feed-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 360px;
    overflow-y: auto;
}

.feed-item {
    background: var(--surface-2);
    border-left: 3px solid var(--accent);
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 12px;
}

.feed-item.error { border-left-color: var(--err); }
.feed-item.success { border-left-color: var(--ok); }

.feed-head {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 11px;
    margin-bottom: 2px;
}

.feed-detail {
    margin-top: 4px;
    font-family: var(--mono);
    font-size: 11px;
    color: #cbd5e1;
    white-space: pre-wrap;
    word-break: break-word;
}

.cmd-results {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 140px;
    overflow-y: auto;
}

.log-box {
    margin: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px;
    font-size: 11px;
    color: #cbd5e1;
    max-height: 220px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.empty-state {
    color: var(--muted);
    padding: 16px;
    border: 1px dashed var(--border);
    border-radius: 8px;
    text-align: center;
}

.db-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.db-box-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
}

.db-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.db-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 9px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-family: var(--mono);
    font-size: 12px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.db-chip:hover:not(:disabled) {
    border-color: var(--accent);
}

.db-chip.active {
    border-color: var(--ok);
    background: rgba(16, 185, 129, 0.14);
    color: #6ee7b7;
}

.db-chip .db-state {
    font-size: 10px;
    color: var(--muted);
}

.btn-sm {
    padding: 3px 8px;
    font-size: 11px;
}

.result-table-wrap {
    margin-top: 6px;
    max-height: 180px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 4px;
}

.result-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--mono);
    font-size: 11px;
}

.result-table th, .result-table td {
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

.result-table th {
    background: var(--surface);
    color: var(--accent);
    position: sticky;
    top: 0;
}

.ws-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}

.ws-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--muted);
    min-width: 220px;
}

.ws-field select {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 7px 10px;
    color: var(--text);
    font-size: 13px;
}

.ws-quick-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ws-tables-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    max-height: 130px;
    overflow-y: auto;
}

.ws-sql-textarea {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    color: var(--text);
    font-family: var(--mono);
    font-size: 13px;
    resize: vertical;
}

.ws-sql-textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.ws-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.ws-result-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
}

.ws-result-box .result-table-wrap {
    max-height: 320px;
}
