/* ============================================
   HeliosDB SQL Playground
   Full-viewport split-pane SQL editor + results
   ============================================ */

/* Container: fills viewport below navbar */
.pg-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    padding-top: 64px;
    z-index: 1;
}

/* ---- Top Status Bar ---- */
.pg-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 44px;
    min-height: 44px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-card);
    font-family: var(--font-mono);
    font-size: 12px;
    gap: 16px;
}

.pg-topbar-left,
.pg-topbar-center,
.pg-topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pg-topbar-left { flex: 1; }
.pg-topbar-center { flex: 0 0 auto; }
.pg-topbar-right { flex: 1; justify-content: flex-end; }

.pg-status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-tertiary);
    transition: background 0.3s;
}

.pg-status-indicator.connected {
    background: var(--neon-lime);
    box-shadow: 0 0 8px rgba(196, 240, 66, 0.5);
}

.pg-status-indicator.connecting {
    background: var(--neon-orange);
    animation: pulse-dot 1.2s ease-in-out infinite;
}

.pg-status-indicator.error {
    background: var(--neon-red);
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.pg-status-text {
    color: var(--text-secondary);
    letter-spacing: 0.02em;
}

.pg-session-label {
    color: var(--text-tertiary);
    font-size: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.pg-session-id {
    color: var(--neon-purple);
    font-weight: 500;
}

.pg-stat {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pg-stat-label {
    color: var(--text-tertiary);
    font-size: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.pg-stat-value {
    color: var(--text-secondary);
    font-weight: 500;
}

.pg-stat-value.warning {
    color: var(--neon-orange);
}

.pg-stat-value.critical {
    color: var(--neon-red);
}

.pg-btn-reset {
    background: none;
    border: 1px solid var(--border-card);
    color: var(--text-secondary);
    padding: 4px 6px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: all 0.2s;
}

.pg-btn-reset:hover {
    border-color: var(--neon-purple);
    color: var(--neon-purple);
}

/* ---- Main Split Layout ---- */
.pg-main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* ---- Sidebar ---- */
.pg-sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-card);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.3s ease, min-width 0.3s ease;
}

.pg-sidebar.collapsed {
    width: 0;
    min-width: 0;
    border-right: none;
}

.pg-sidebar.collapsed .pg-sidebar-header,
.pg-sidebar.collapsed .pg-examples-list {
    opacity: 0;
    pointer-events: none;
}

.pg-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px 12px;
    transition: opacity 0.2s;
}

.pg-sidebar-header h3 {
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.pg-sidebar-show {
    display: none;
    background: none;
    border: 1px solid var(--border-card);
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.pg-sidebar-show:hover {
    border-color: var(--neon-purple);
    color: var(--neon-purple);
}

.pg-sidebar-show.visible {
    display: flex;
}

.pg-sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    transition: color 0.2s;
}

.pg-sidebar-toggle:hover {
    color: var(--text-primary);
}

.pg-examples-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: opacity 0.2s;
}

.pg-example-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    background: none;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
    width: 100%;
}

.pg-example-card:hover {
    background: var(--bg-card);
    border-color: var(--border-card);
}

.pg-example-card.active {
    background: rgba(158, 140, 252, 0.08);
    border-color: rgba(158, 140, 252, 0.25);
}

.pg-example-icon {
    font-size: 18px;
    line-height: 1;
    flex-shrink: 0;
    margin-top: 1px;
    filter: grayscale(0.2);
}

.pg-example-title {
    display: block;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
}

.pg-example-desc {
    display: block;
    font-family: var(--font-body);
    font-size: 11px;
    color: var(--text-tertiary);
    line-height: 1.4;
    margin-top: 2px;
}

/* ---- Workspace (editor + results) ---- */
.pg-workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* ---- Editor Panel ---- */
.pg-editor-panel {
    display: flex;
    flex-direction: column;
    flex: 1 1 50%;
    min-height: 120px;
    overflow: hidden;
}

.pg-editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 40px;
    min-height: 40px;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--border-card);
}

.pg-editor-toolbar-left,
.pg-editor-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pg-editor-label {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-tertiary);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.pg-btn-clear {
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 4px 10px;
    background: none;
    border: 1px solid var(--border-card);
    color: var(--text-tertiary);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.pg-btn-clear:hover {
    border-color: var(--text-secondary);
    color: var(--text-secondary);
}

.pg-btn-run {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    padding: 5px 14px;
    background: var(--neon-purple);
    color: #000;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.pg-btn-run:hover {
    background: #b0a4ff;
    box-shadow: 0 0 16px rgba(158, 140, 252, 0.4);
}

.pg-btn-run:active {
    transform: scale(0.97);
}

.pg-btn-run:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pg-btn-run kbd {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 400;
    padding: 1px 5px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
    opacity: 0.7;
}

/* Editor textarea area */
.pg-editor-wrap {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

.pg-line-numbers {
    width: 48px;
    min-width: 48px;
    padding: 12px 8px 12px 0;
    text-align: right;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-tertiary);
    background: rgba(255, 255, 255, 0.01);
    border-right: 1px solid var(--border-card);
    user-select: none;
    overflow: hidden;
}

.pg-line-numbers div {
    line-height: 1.6;
}

.pg-editor-area {
    flex: 1;
    position: relative;
    min-height: 0;
}

.pg-highlight {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    padding: 12px 16px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    white-space: pre;
    tab-size: 4;
    overflow: auto;
    pointer-events: none;
    border: none;
    background: transparent;
}

.pg-highlight code {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
}

.pg-editor {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 12px 16px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    color: transparent;
    caret-color: var(--text-primary);
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    overflow-y: auto;
    tab-size: 4;
    white-space: pre;
    z-index: 1;
}

/* Syntax highlight colors */
.hl-keyword { color: #c792ea; font-weight: 500; }
.hl-type { color: #82aaff; }
.hl-string { color: #c3e88d; }
.hl-number { color: #f78c6c; }
.hl-comment { color: rgba(255, 255, 255, 0.3); font-style: italic; }
.hl-operator { color: #89ddff; }
.hl-default { color: var(--text-primary); }

.pg-editor::placeholder {
    color: var(--text-tertiary);
}

.pg-editor::-webkit-scrollbar {
    width: 6px;
}

.pg-editor::-webkit-scrollbar-track {
    background: transparent;
}

.pg-editor::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

/* ---- Divider / Drag Handle ---- */
.pg-divider {
    height: 6px;
    min-height: 6px;
    cursor: row-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-card);
    border-bottom: 1px solid var(--border-card);
    transition: background 0.2s;
}

.pg-divider:hover {
    background: rgba(158, 140, 252, 0.08);
}

.pg-divider-handle {
    width: 40px;
    height: 2px;
    background: var(--text-tertiary);
    border-radius: 1px;
    opacity: 0.5;
}

/* ---- Results Panel ---- */
.pg-results-panel {
    display: flex;
    flex-direction: column;
    flex: 1 1 50%;
    min-height: 100px;
    overflow: hidden;
}

.pg-results-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 40px;
    min-height: 40px;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--border-card);
}

.pg-results-tabs {
    display: flex;
    gap: 0;
}

.pg-results-tab {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 4px 12px;
    background: none;
    border: 1px solid transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.pg-results-tab:hover {
    color: var(--text-secondary);
}

.pg-results-tab.active {
    color: var(--neon-purple);
    border-color: rgba(158, 140, 252, 0.25);
    background: rgba(158, 140, 252, 0.06);
}

.pg-results-meta {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-tertiary);
}

.pg-results-meta .rows-count {
    color: var(--neon-lime);
}

.pg-results-meta .exec-time {
    color: var(--neon-blue);
}

.pg-results-content,
.pg-history-content {
    flex: 1;
    overflow: auto;
}

/* Empty state */
.pg-results-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 8px;
    color: var(--text-tertiary);
    font-family: var(--font-body);
}

.pg-empty-icon {
    font-size: 36px;
    opacity: 0.2;
    margin-bottom: 8px;
}

.pg-results-empty p {
    font-size: 14px;
    color: var(--text-secondary);
}

.pg-results-empty span {
    font-size: 12px;
}

.pg-results-empty kbd {
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 2px 6px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-card);
    border-radius: 3px;
    color: var(--text-secondary);
}

/* Results table */
.pg-table-wrap {
    width: 100%;
    overflow: auto;
    height: 100%;
}

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

.pg-table thead {
    position: sticky;
    top: 0;
    z-index: 2;
}

.pg-table th {
    padding: 8px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--neon-purple);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-card);
    white-space: nowrap;
}

.pg-table td {
    padding: 6px 14px;
    color: var(--text-secondary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    white-space: nowrap;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pg-table tr:nth-child(even) td {
    background: rgba(255, 255, 255, 0.015);
}

.pg-table tr:hover td {
    background: rgba(158, 140, 252, 0.04);
}

.pg-table td.null-val {
    color: var(--text-tertiary);
    font-style: italic;
}

/* Error display */
.pg-error {
    padding: 16px 20px;
    margin: 12px;
    background: rgba(255, 107, 107, 0.06);
    border: 1px solid rgba(255, 107, 107, 0.2);
    border-radius: 8px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--neon-red);
    line-height: 1.5;
}

.pg-error-label {
    font-weight: 700;
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.1em;
    margin-bottom: 6px;
    display: block;
}

/* Success message (DDL) */
.pg-success {
    padding: 16px 20px;
    margin: 12px;
    background: rgba(196, 240, 66, 0.06);
    border: 1px solid rgba(196, 240, 66, 0.2);
    border-radius: 8px;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--neon-lime);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* History entries */
.pg-history-entry {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-card);
    cursor: pointer;
    transition: background 0.15s;
}

.pg-history-entry:hover {
    background: rgba(255, 255, 255, 0.03);
}

.pg-history-time {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-tertiary);
    margin-bottom: 4px;
}

.pg-history-sql {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pg-history-result {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--neon-lime);
    margin-top: 2px;
}

.pg-history-result.error {
    color: var(--neon-red);
}

/* Loading spinner */
.pg-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 10px;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
    font-size: 12px;
}

.pg-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-card);
    border-top-color: var(--neon-purple);
    border-radius: 50%;
    animation: pg-spin 0.7s linear infinite;
}

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

/* ---- Mobile Responsive ---- */
@media (max-width: 768px) {
    .pg-container {
        padding-top: 60px;
    }

    .pg-sidebar {
        display: none;
    }

    .pg-topbar {
        padding: 0 12px;
        font-size: 11px;
    }

    .pg-topbar-center {
        display: none;
    }

    .pg-btn-run kbd {
        display: none;
    }

    .pg-editor {
        font-size: 12px;
    }

    .pg-table {
        font-size: 11px;
    }

    .pg-table th,
    .pg-table td {
        padding: 5px 8px;
    }
}

@media (max-width: 480px) {
    .pg-stat-label {
        display: none;
    }
}
