:root {
    --accent: #5a45d6;
    --accent-bg: #2a2655;
    --accent-soft: #7f6cf0;
}

* {
    box-sizing: border-box;
}

*:focus,
*:focus-visible {
    outline: none !important;
    box-shadow: none !important;
}

[x-cloak] {
    display: none !important;
}

html, body {
    margin: 0;
    padding: 0;
    background: #12141a;
    color: #e3e7ef;
    font-family: Inter, system-ui, -apple-system, sans-serif;
    height: 100%;
    overflow: hidden;
}

body {
    min-height: 100vh;
}

* {
    scrollbar-width: thin;
    scrollbar-color: #4a5270 #171b24;
}

*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-track {
    background: #171b24;
    border-radius: 999px;
}

*::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #5f6a8f 0%, #4a5270 100%);
    border: 2px solid #171b24;
    border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #7b88b7 0%, #5f6a8f 100%);
}

*::-webkit-scrollbar-thumb:active {
    background: linear-gradient(180deg, #8f9fd6 0%, #6d7db6 100%);
}

*::-webkit-scrollbar-corner {
    background: #171b24;
}

#app {
    display: grid;
    grid-template-columns: 220px 280px 1fr;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

#app.collapse-dbs {
    grid-template-columns: 52px 280px 1fr;
}

#app.collapse-tables {
    grid-template-columns: 220px 52px 1fr;
}

#app.collapse-dbs.collapse-tables {
    grid-template-columns: 52px 52px 1fr;
}

.sidebar {
    border-right: 1px solid #282c38;
    padding: 12px;
    background: #171a22;
    overflow: hidden;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.sidebar.collapsed {
    width: fit-content;
    padding: 12px 8px;
}

.pane-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

.collapse-btn {
    background: #0f131c;
    color: #dce2f0;
    border: 1px solid #32384a;
    border-radius: 8px;
    width: 30px;
    height: 28px;
    cursor: pointer;
}

.sidebar-content {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
    overflow: hidden;
}

.db-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
}

.db-logout {
    margin-top: 10px;
    background: #0f131c;
    color: #dce2f0;
    border: 1px solid #32384a;
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
}

.pane-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #8d95a8;
    margin: 0;
}

.sidebar input {
    width: 100%;
    background: #10131a;
    color: #dce2f0;
    border: 1px solid #323849;
    border-radius: 8px;
    padding: 8px 10px;
}

.pane-head-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.pane-tab {
    border: 1px solid #32384a;
    background: #0f131c;
    color: #c8cfdd;
    border-radius: 8px;
    padding: 7px 8px;
    font-size: 11px;
    letter-spacing: .08em;
    cursor: pointer;
}

.pane-tab.active {
    border-color: var(--accent);
    background: var(--accent-bg);
    color: #fff;
}

.item {
    width: 100%;
    border: 0;
    background: transparent;
    color: #c8cfdd;
    text-align: left;
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.item.active {
    background: var(--accent);
    color: #fff;
}

.table-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    scrollbar-gutter: stable;
}

.table-filter-wrap {
    position: relative;
    margin-bottom: 10px;
}

.table-filter-wrap input {
    padding-right: 30px;
}

.table-filter-clear {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border: 1px solid #32384a;
    border-radius: 6px;
    background: #0f131c;
    color: #dce2f0;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

.table-item small {
    opacity: 0.75;
    font-size: 11px;
}

.table-item .fuzzy-hit {
    background: #e8d17a;
    color: #151922;
    border-radius: 3px;
    padding: 0 1px;
}

.main {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.main-empty-state {
    border: 1px solid #2b3040;
    background: #171b24;
    border-radius: 10px;
    flex: 1;
    min-height: 0;
    display: grid;
    place-items: center;
    text-align: center;
    padding: 24px;
}

.main-empty-state-content {
    max-width: 420px;
}

.main-empty-state h2 {
    margin: 0 0 8px;
    font-size: 22px;
    color: #eef2ff;
    font-weight: 600;
}

.main-empty-state p {
    margin: 0;
    color: #8d95a8;
    font-size: 14px;
}

.query-tab-btn {
    margin-top: 10px;
    background: #0f131c;
    color: #dce2f0;
    border: 1px solid #32384a;
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
}

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

.table-tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    min-height: 0;
    padding-bottom: 2px;
}

.table-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid #32384a;
    background: #0f131c;
    color: #c8cfdd;
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    white-space: nowrap;
    font-size: 12px;
}

.table-tab.active {
    border-color: var(--accent);
    background: var(--accent-bg);
    color: #fff;
}

.table-tab-close {
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0;
    transform: translateY(1px);
}

.filters {
    border: 1px solid #2b3040;
    background: #171b24;
    border-radius: 10px;
    padding: 8px;
    overflow: auto;
    scrollbar-gutter: stable;
}

.filters-top {
    display: flex;
}

.filters-top > div {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filters-top button {
    display: flex;
    align-items: center;
    justify-content: center;
}

.filters-top .query-tab-btn {
    margin-top: 0;
}

.query-editor {
    margin-top: 8px;
    display: grid;
    gap: 8px;
}

.query-editor textarea {
    width: 100%;
    min-height: 180px;
    resize: vertical;
    border: 1px solid #32384a;
    background: #0f131c;
    color: #dce2f0;
    border-radius: 8px;
    padding: 10px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.query-editor-actions {
    display: flex;
    justify-content: flex-end;
}

.sql-button {
    position: relative;
}

.sql-button.active {
    border-color: var(--accent) !important;
    background-color: var(--accent-bg) !important;
}

.structure-button.active {
    border-color: var(--accent) !important;
    background-color: var(--accent-bg) !important;
}

.sql-button svg {
    width: 12px;
    height: 12px;
    margin-left: 8px;
}

.sql-dot {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: var(--accent);
    border: 1px solid #171b24;
}

.sql-badge {
    display: inline-flex;
    align-items: center;
    border: 1px solid #2f7f5f;
    background: #12392e;
    color: #9be7c9;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 11px;
    letter-spacing: .06em;
    font-weight: 600;
}

.sql-reset {
    border-color: #6e4f8a !important;
    background: #2b1f3e !important;
}

.filters button,
.filters select,
.filters input,
.grid-meta button,
.grid-meta select,
.grid-meta input,
.modal button,
.modal input {
    background: #0f131c;
    color: #dce2f0;
    border: 1px solid #32384a;
    border-radius: 8px;
    padding: 6px 8px;
    cursor: pointer;
}

.filters select,
.grid-meta select,
.modal select {
    padding-right: 28px;
    appearance: none;
    background: #0f131c url(data:image/svg+xml;charset=US-ASCII,%3Csvg%20width%3D%2220%22%20height%3D%2220%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M5%206l5%205%205-5%202%201-7%207-7-7%202-1z%22%20fill%3D%22%23fff%22%2F%3E%3C%2Fsvg%3E) no-repeat right 8px top 55%;
    background-size: 16px 16px;
}

.filters input,
.grid-meta input,
.modal input {
    width: 100%;
    cursor: auto;
}

.grid-meta input {
    min-width: 220px;
}

.filters button.removeFilter,
.filters button.applyFilters {
    width: fit-content;
}

.filter-row {
    width: 100%;
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.filter-row > * {
    width: 100%;
}

.between-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.between-inputs input {
    min-width: 0;
}

.grid-wrap {
    border: 1px solid #2b3040;
    background: #171b24;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    flex: 1;
    overflow: hidden;
}

.grid-meta {
    padding: 8px;
    border-bottom: 1px solid #2b3040;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.grid-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.icon-btn {
    width: 30px;
    height: 30px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.icon-btn svg {
    width: 16px;
    height: 16px;
}

#gridSearchInput {
    min-width: 220px;
}

.grid-holder {
    overflow: auto;
    flex: 1;
    min-width: 0;
    min-height: 0;
    scrollbar-gutter: stable both-edges;
}

.grid-skeleton {
    padding: 12px;
    display: grid;
    gap: 8px;
}

.grid-skeleton-row {
    height: 28px;
    border-radius: 6px;
    background: linear-gradient(90deg, #1c2130 25%, #262c3d 50%, #1c2130 75%);
    background-size: 220% 100%;
    animation: gridSkeletonPulse 1.2s ease-in-out infinite;
}

.grid-empty {
    padding: 16px;
    display: grid;
    gap: 10px;
}

.grid-empty-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.grid-empty-head h3 {
    margin: 0;
    font-size: 18px;
    color: #eef2ff;
}

.grid-empty-head p {
    margin: 4px 0 0;
    color: #8d95a8;
    font-size: 13px;
}

.grid-empty-close {
    width: 28px;
    height: 28px;
    border: 1px solid #32384a;
    background: #0f131c;
    color: #dce2f0;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.grid-structure {
    display: grid;
    gap: 8px;
}

.grid-structure-row {
    border: 1px solid #2b3040;
    border-radius: 8px;
    background: #111522;
    padding: 8px 10px;
    display: grid;
    gap: 6px;
}

.grid-structure-name {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    color: #f2f5ff;
    font-weight: 600;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
}

.structure-copy-btn {
    width: 20px;
    height: 20px;
    border: 1px solid #32384a;
    border-radius: 6px;
    background: #0f131c;
    color: #dce2f0;
    opacity: 0;
    pointer-events: none;
    transition: opacity .12s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
}

.grid-structure-row:hover .structure-copy-btn {
    opacity: 1;
    pointer-events: auto;
}

.structure-copy-btn svg {
    width: 12px;
    height: 12px;
}

.grid-structure-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip {
    display: inline-flex;
    align-items: center;
    border: 1px solid #32384a;
    background: #0f131c;
    color: #c8cfdd;
    border-radius: 999px;
    font-size: 11px;
    padding: 2px 8px;
}

@keyframes gridSkeletonPulse {
    0% {
        background-position: 100% 0;
    }
    100% {
        background-position: 0 0;
    }
}

table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 13px;
}

th, td {
    border-bottom: 1px solid #252b3a;
    border-right: 1px solid #252b3a;
    padding: 8px;
    white-space: nowrap;
}

tbody td {
    cursor: pointer;
}

.cell-value-wrap {
    position: relative;
    padding-right: 26px;
}

.cell-copy-btn {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border: 1px solid #32384a;
    border-radius: 6px;
    background: #0f131c;
    color: #dce2f0;
    opacity: 0;
    pointer-events: none;
    transition: opacity .12s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
}

tbody td:hover .cell-copy-btn {
    opacity: 1;
    pointer-events: auto;
}

.cell-copy-btn svg {
    width: 12px;
    height: 12px;
}

th {
    position: sticky;
    top: 0;
    background: #1c2130;
    cursor: pointer;
    z-index: 2;
}

th .th-label {
    vertical-align: middle;
}

th .th-sort-icon {
    display: inline-flex;
    vertical-align: middle;
    margin-left: 4px;
}

th .th-sort-icon svg {
    width: 14px;
    height: 14px;
}

td.editing {
    background: var(--accent-bg);
    cursor: auto;
}

td input {
    width: 100%;
    border: 1px solid var(--accent-soft);
    background: #111522;
    color: #fff;
    border-radius: 4px;
    padding: 4px 6px;
}

td select {
    width: 100%;
    border: 1px solid var(--accent-soft);
    background: #111522;
    color: #fff;
    border-radius: 4px;
    padding: 4px 6px;
}

td textarea {
    width: 100%;
    min-height: 96px;
    resize: vertical;
    border: 1px solid var(--accent-soft);
    background: #111522;
    color: #fff;
    border-radius: 4px;
    padding: 6px;
}

.cell-editor {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
}

.cell-editor button {
    padding: 4px 6px;
    border-radius: 6px;
    border: 1px solid #32384a;
    background: #0f131c;
    color: #dce2f0;
    cursor: pointer;
    font-size: 11px;
}

.cell-editor .editor-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.cell-editor .editor-save-btn {
    border-color: var(--accent);
    background: var(--accent-bg);
    color: #fff;
}

.row-delete-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid #32384a;
    border-radius: 8px;
    background: #0f131c;
    color: #c7cedf;
    cursor: pointer;
}

.row-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.row-duplicate-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid #32384a;
    border-radius: 8px;
    background: #0f131c;
    color: #c7cedf;
    cursor: pointer;
}

.row-duplicate-btn:hover {
    border-color: var(--accent);
    color: #fff;
}

.row-duplicate-btn svg {
    width: 14px;
    height: 14px;
}

.row-delete-btn:hover {
    border-color: var(--accent);
    color: #fff;
}

.row-delete-btn svg {
    width: 14px;
    height: 14px;
}

.insert-field {
    display: flex;
    gap: 8px;
    align-items: center;
}

.insert-field button {
    border: 1px solid #32384a;
    background: #0f131c;
    color: #dce2f0;
    border-radius: 8px;
    padding: 6px 8px;
    cursor: pointer;
}

.sql-card {
    width: min(1000px, 92vw);
}

.sql-card textarea {
    width: 100%;
    min-height: 180px;
    resize: vertical;
    border: 1px solid #32384a;
    background: #0f131c;
    color: #dce2f0;
    border-radius: 8px;
    padding: 10px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.sql-result {
    margin: 0;
    max-height: 260px;
    overflow: auto;
    border: 1px solid #2b3040;
    border-radius: 8px;
    background: #10141d;
    padding: 10px;
    font-size: 12px;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2;
}

.modal-card {
    width: 520px;
    max-height: 80vh;
    overflow: auto;
    background: #171b24;
    border: 1px solid #2b3040;
    border-radius: 12px;
    padding: 14px;
    display: grid;
    gap: 8px;
    scrollbar-gutter: stable;
}

.modal-card label {
    display: grid;
    gap: 4px;
    font-size: 13px;
}

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

.login-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
}

.login-card {
    width: 380px;
    background: #171b24;
    border: 1px solid #2b3040;
    border-radius: 12px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.login-card form {
    width: 100%;
    margin-top: 20px;
    display: grid;
    gap: 8px;
}

.login-card label {
    font-size: 14px;
}

.login-card input,
.login-card button {
    background: #0f131c;
    color: #dce2f0;
    border: 1px solid #32384a;
    border-radius: 8px;
    padding: 8px 10px;
}

.login-card button {
    margin-top: 10px;
    cursor: pointer;
}

#loginError:empty {
    display: none;
}

.error {
    min-height: 20px;
    margin-top: 10px;
    color: #ff7b7b;
    font-size: 13px;
}

.flatpickr-calendar {
    background: #171b24;
    border: 1px solid #2b3040;
    box-shadow: none;
}

.flatpickr-months .flatpickr-month,
.flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-current-month input.cur-year,
span.flatpickr-weekday,
.flatpickr-weekdays,
.flatpickr-time input,
.flatpickr-time .flatpickr-am-pm {
    color: #dce2f0;
    fill: #dce2f0;
    background: #171b24;
}

.flatpickr-day {
    color: #c8cfdd;
}

.flatpickr-day:hover {
    background: #242b3b;
    border-color: #242b3b;
}

.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange {
    background: var(--accent);
    border-color: var(--accent);
}

#app.prod-theme {
    --accent: #e91e63;
    --accent-bg: #4a1025;
    --accent-soft: #ff5f95;
}

#app.prod-theme .sidebar,
#app.prod-theme .filters,
#app.prod-theme .grid-wrap {
    box-shadow: inset 0 0 0 1px rgba(233, 30, 99, 0.18);
}

mark.fuzzy-hit {
    background-color: #cddc39;
}