:root {
    --bg-deep: #020617;
    --bg-elevated: #0f172a;
    --bg-card: #111827;
    --bg-input: #1e293b;
    --fg-primary: #f8fafc;
    --fg-secondary: #cbd5e1;
    --fg-muted: #94a3b8;
    --accent-pink: #ec4899;
    --accent-pink-glow: rgba(236, 72, 153, 0.2);
    --accent-violet: #8b5cf6;
    --accent-violet-glow: rgba(139, 92, 246, 0.2);
    --accent-emerald: #10b981;
    --accent-emerald-glow: rgba(16, 185, 129, 0.2);
    --accent-red: #ef4444;
    --accent-amber: #f59e0b;
    --accent-amber-glow: rgba(245, 158, 11, 0.2);
    --border-color: #1e293b;
    --border-light: #334155;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-card: 0 4px 24px rgba(0,0,0,0.3), 0 1px 4px rgba(0,0,0,0.2);
    --transition: 200ms ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-deep);
    color: var(--fg-primary);
    min-height: 100vh;
    background-image:
        radial-gradient(ellipse at 20% 0%, rgba(139,92,246,0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 100%, rgba(236,72,153,0.04) 0%, transparent 50%);
}

.app-wrapper {
    max-width: 1000px;
    margin: 0 auto;
    padding: 32px 24px 60px;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    padding: 20px 24px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
}

.app-header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.app-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    flex-shrink: 0;
}

.app-header-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--accent-violet), var(--accent-pink));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    color: #fff;
    box-shadow: 0 4px 16px var(--accent-violet-glow);
}

.app-header h1 {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--fg-primary), var(--fg-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.app-header p {
    font-size: 13px;
    color: var(--fg-muted);
    margin-top: 2px;
}

.header-link {
    color: var(--fg-muted);
    text-decoration: none;
    font-size: 13px;
    transition: color var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.header-link:hover { color: var(--accent-violet); }

/* Section Card */
.section-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    margin-bottom: 24px;
    transition: border-color var(--transition);
    position: relative;
}

.section-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: linear-gradient(135deg, rgba(139,92,246,0.08) 0%, var(--bg-elevated) 60%);
    border-bottom: 1px solid var(--border-color);
    border-top: 2px solid rgba(139,92,246,0.25);
    border-radius: var(--radius) var(--radius) 0 0;
    position: relative;
}

.section-card-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 18px;
    font-weight: 700;
    color: var(--fg-primary);
}

.section-card-title i {
    color: var(--accent-violet);
    font-size: 20px;
}

.section-card-body {
    padding: 24px;
}

/* Tips */
.tips-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(139, 92, 246, 0.12);
    border: 1px solid rgba(139, 92, 246, 0.25);
    color: #8b5cf6;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
}

.tips-btn:hover {
    background: rgba(139, 92, 246, 0.25);
    border-color: #8b5cf6;
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.3);
    transform: scale(1.08);
}

.tips-btn:active { transform: scale(0.95); }

.tips-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
    z-index: 100;
}
.tips-backdrop.active { display: block; }

.tips-popover {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 600px;
    width: 600px;
    max-width: calc(100vw - 48px);
    resize: horizontal;
    overflow: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.3);
    z-index: 200;
    animation: tipsEnter 250ms ease;
}
.tips-popover.active { display: block; }

.tips-popover::before {
    content: '';
    position: absolute;
    top: -8px;
    right: 20px;
    width: 14px;
    height: 14px;
    background: var(--bg-card);
    border-top: 1px solid var(--border-light);
    border-left: 1px solid var(--border-light);
    transform: rotate(45deg);
}

.tips-popover-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
}

.tips-popover-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--fg-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}
.tips-popover-title i { color: #8b5cf6; font-size: 15px; }

.tips-popover-close {
    width: 28px;
    height: 28px;
    border: none;
    background: var(--bg-input);
    color: var(--fg-muted);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}
.tips-popover-close:hover { background: var(--accent-red); color: #fff; }

.tips-popover-body {
    padding: 18px;
    font-size: 12px;
    color: var(--fg-secondary);
    line-height: 1.6;
    max-height: 400px;
    overflow-y: auto;
}
.tips-popover-body p { margin-bottom: 10px; }
.tips-popover-body p:last-child { margin-bottom: 0; }

.tips-placeholder {
    font-size: 12px;
    color: var(--fg-muted);
    line-height: 1.6;
    font-style: italic;
}

@keyframes tipsEnter {
    from { opacity: 0; transform: translateY(-8px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Button */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    height: 42px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn-violet {
    background: linear-gradient(135deg, var(--accent-violet), #7c3aed);
    color: #fff;
    box-shadow: 0 2px 12px var(--accent-violet-glow);
}
.btn-violet:hover { box-shadow: 0 4px 20px var(--accent-violet-glow); }

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* SQL Panel */
.sql-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.sql-toolbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-export {
    background: linear-gradient(135deg, var(--accent-emerald), #059669);
    color: #fff;
    box-shadow: 0 2px 12px var(--accent-emerald-glow);
    text-decoration: none;
    margin-left: auto;
}
.btn-export:hover { box-shadow: 0 4px 20px var(--accent-emerald-glow); }
.btn-export[disabled], .btn-export[disabled]:hover {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.sql-textbox {
    width: 100%;
    padding: 16px;
    font-family: 'JetBrains Mono', 'Consolas', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    background: var(--bg-deep);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--fg-primary);
    resize: vertical;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
    color-scheme: dark;
}

.sql-textbox:focus {
    border-color: var(--accent-violet);
    box-shadow: 0 0 0 3px var(--accent-violet-glow);
}

.sql-textbox::placeholder {
    color: var(--fg-muted);
}

/* Results */
.sql-result-wrap {
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin-top: 16px;
}

.sql-result-table {
    width: 100%;
    border-collapse: collapse;
}

.sql-result-table th {
    background: var(--bg-elevated);
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent-violet);
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.sql-result-table td {
    padding: 10px 16px;
    font-size: 13px;
    color: var(--fg-secondary);
    border-bottom: 1px solid rgba(30,41,59,0.5);
}

.sql-result-table tr:last-child td { border-bottom: none; }
.sql-result-table tbody tr:hover td { background: rgba(139,92,246,0.04); }
.sql-result-table tbody tr:nth-child(even) td { background: rgba(15,23,42,0.3); }
.sql-result-table tbody tr:nth-child(even):hover td { background: rgba(139,92,246,0.06); }

/* Result info bar */
.sql-result-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: linear-gradient(135deg, rgba(139,92,246,0.08) 0%, var(--bg-elevated) 60%);
    border-top: 1px solid var(--border-color);
    font-size: 13px;
    color: var(--fg-muted);
    font-weight: 600;
}

.sql-result-count {
    color: var(--accent-violet);
}

/* Pagination pills */
.sql-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
}

.sql-page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    padding: 0 10px;
    border-radius: 10px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    font-weight: 700;
    color: var(--fg-secondary);
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

.sql-page-btn:hover {
    background: rgba(139,92,246,0.15);
    border-color: var(--accent-violet);
    color: var(--accent-violet);
}

.sql-page-current {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    padding: 0 10px;
    border-radius: 10px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-violet), var(--accent-pink));
    color: #fff;
    border-color: transparent;
    box-shadow: 0 2px 12px var(--accent-violet-glow);
    cursor: default;
}

/* Rows select */
.sql-rows-select {
    padding: 8px 32px 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--fg-primary);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    color-scheme: dark;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 12px;
    outline: none;
    transition: border-color var(--transition);
}

.sql-rows-select:focus {
    border-color: var(--accent-violet);
    box-shadow: 0 0 0 3px var(--accent-violet-glow);
}

.sql-rows-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--fg-muted);
}

/* Messages */
.sql-message {
    display: block;
    margin-top: 16px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
}

.sql-message-success { background: rgba(16,185,129,0.15); color: #6ee7b7; border-left: 4px solid var(--accent-emerald); }
.sql-message-error { background: rgba(239,68,68,0.15); color: #fca5a5; border-left: 4px solid var(--accent-red); }
.sql-message-warning { background: rgba(245,158,11,0.15); color: #fcd34d; border-left: 4px solid var(--accent-amber); }

.tips-markdown {
    font-size: 12px;
    color: var(--fg-secondary);
    line-height: 1.6;
}

.tips-markdown h2 {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent-violet);
    margin: 0 0 10px 0;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-color);
}

.tips-markdown h3 {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent-pink);
    margin: 14px 0 8px 0;
}

.tips-markdown strong {
    color: var(--accent-violet);
    font-weight: 700;
}

.tips-markdown em {
    color: var(--fg-primary);
    font-style: italic;
}

.tips-markdown code {
    font-family: 'JetBrains Mono', 'Consolas', 'Courier New', monospace;
    font-size: 11px;
    background: var(--bg-deep);
    color: var(--accent-emerald);
    padding: 1px 5px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    white-space: nowrap;
}

/* Markdown Tables */
.tips-table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 12px;
}

.tips-table tr:first-child {
    background: var(--bg-elevated);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 11px;
    color: var(--accent-violet);
}

.tips-table tr:first-child td {
    border-bottom: 2px solid var(--accent-violet);
    padding: 8px 12px;
}

.tips-table tr {
    border-bottom: 1px solid var(--border-color);
    transition: background var(--transition);
}

.tips-table tr:hover {
    background: rgba(139, 92, 246, 0.04);
}

.tips-table tr:nth-child(even) {
    background: rgba(15, 23, 42, 0.3);
}

.tips-table tr:nth-child(even):hover {
    background: rgba(139, 92, 246, 0.06);
}

.tips-table td {
    padding: 8px 12px;
    vertical-align: top;
    color: var(--fg-secondary);
    word-wrap: normal;
    overflow-wrap: normal;
    white-space: normal;
}

.tips-table td:first-child {
    font-weight: 700;
    color: var(--fg-primary);
    width: 40px;
    text-align: center;
    max-width: none;
    word-wrap: normal;
    overflow-wrap: normal;
}

.tips-table tr:not(:first-child) td:nth-child(2) {
    font-weight: 600;
    color: var(--fg-primary);
}

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

/* Responsive */
@media (max-width: 768px) {
    .app-wrapper { padding: 20px 16px 40px; }
    .app-header { flex-direction: column; align-items: flex-start; gap: 14px; }
    .app-header-right { flex-wrap: wrap; }
    .sql-toolbar { flex-direction: column; align-items: flex-start; }
    .sql-result-table th, .sql-result-table td { padding: 8px 10px; font-size: 12px; }
}
