:root {
    --bg: #0e0f12;
    --panel: #111217;
    --panel-2: #181a20;
    --muted: #9aa0a6;
    --accent: #6fc3ff;
    --line: #23252c;
    --ink: #e7eef6;
}

* {
    box-sizing: border-box
}

html,
body,
#app {
    height: 100%
}

html,
body {
    overscroll-behavior: none;
}

html {
    background: #0a0d14;
}

body {
    margin: 0;
    font-family: Inter, Segoe UI, Roboto, system-ui, -apple-system, "Helvetica Neue", Arial;
    color: var(--ink);
    background: linear-gradient(180deg, #0a0d14 0%, #0b0c10 100%);
}

body {
    padding:
        env(safe-area-inset-top)
        env(safe-area-inset-right)
        env(safe-area-inset-bottom)
        env(safe-area-inset-left);
}

body,
#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

#app {
    background: inherit;
}

/* Top bar */
#topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 18px;
    background: var(--panel-2);
    border-bottom: 1px solid var(--line);
}

#topbar h1 {
    margin: 0;
    font-size: 16px;
    letter-spacing: .02em;
}

/* Auth bar (right side in header) */
#authbar {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

#logout-btn {
    padding: 6px 12px;
    border: 1px solid #3a3e47;
    border-radius: 8px;
    background: #1b1e24;
    color: var(--ink);
    cursor: pointer;
}

#logout-btn:hover {
    background: #22262e
}

/* Main split layout */
main {
    display: flex;
    flex: 1;
    min-height: 0;
    gap: 12px;
    padding: 12px;
}

/* Sidebar */
aside#left {
    width: 300px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow: auto;
}

aside#left h3 {
    margin: 0 0 8px 0;
    font-size: 13px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: .06em;
}

ul {
    list-style: none;
    margin: 0;
    padding: 0
}

li {
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer
}

li:hover {
    background: #1b1e24
}

/* Main pane */
#mainPane {
    flex: 1;
    min-width: 0;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow: auto;
}

#meta {
    font-size: 13px;
    color: var(--muted);
}

#schemaQuery {
    display: flex;
    gap: 12px;
    min-height: 0;
}

#schema,
#rows {
    background: #12151b;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    overflow: auto;
    position: relative;
}

#schemaWrap {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

#schemaWrap.collapsed {
    flex: none;
}

#schemaWrap.collapsed #schema {
    display: none;
}

#schema {
    max-height: 320px;
}

#rows {
    flex: 1;
    min-height: 150px;
}

.schema-controls {
    position: sticky;
    bottom: 0;
    background: #0f141b;
    padding: 10px 0;
    margin-top: 12px;
    border-top: 1px solid var(--line);
    z-index: 5;
}

.sc-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.sc-title {
    font-size: 12px;
    color: var(--muted);
    min-width: 110px;
}

.sc-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.sc-input {
    height: 34px;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid #2a2e37;
    background: #0f141b;
    color: #d9eefc;
    font-size: 13px;
}

.sc-label {
    display: inline-flex;
    gap: 6px;
    align-items: center;
    color: var(--muted);
    font-size: 12px;
    user-select: none;
}

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

.sc-btn {
    height: 34px;
    padding: 0 12px;
    border-radius: 8px;
    border: 1px solid #3a3e47;
    background: #1b1e24;
    color: var(--ink);
    cursor: pointer;
    font-weight: 600;
}

.sc-btn:hover {
    filter: brightness(1.15);
}

.sc-btn.danger {
    border-color: #6b2a2a;
}


#rows table {
    border-collapse: separate;
    width: max-content;
    border-spacing: 0;
    min-width: 100%;
}

#rows th.actions,
#rows td.actions {
    position: sticky;
    right: 0;
    z-index: 11;
    background: #1b1e24;
    box-shadow: -2px 0 4px rgba(0, 0, 0, 0.4);
}

#rows td.actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

#rows thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #202633;
    font-weight: 600;
    text-transform: none;
    padding: 6px 10px;
    border-bottom: 1px solid #353b48;
}

.th-inner {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.pin-btn {
    width: 26px;
    height: 22px;
    margin-right: 6px;
    border: 1px solid #3a3e47;
    border-radius: 6px;
    background: #1b1e24;
    color: var(--ink);
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", system-ui;
}

.pin-btn:hover {
    filter: brightness(1.15);
}

#rows th.pinned-col,
#rows td.pinned-col {
    position: sticky;
    background: #1b1e24;
    box-shadow: 2px 0 6px rgba(0, 0, 0, 0.45);
}

#rows thead th.pinned-col {
    background: #202633;
}

#rows thead tr {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}


/* Table styling */
table {
    border-collapse: collapse;
    width: 100%
}

th {
    padding: 6px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 13px;
    text-align: left;
}


.login-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: var(--panel);
}

.card {
    width: 360px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 22px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

.card h1 {
    margin: 0 0 8px 0;
    font-size: 18px
}

.card p {
    margin: 0 0 16px 0;
    color: var(--muted)
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: #5865F2;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

.btn:hover {
    filter: brightness(0.95)
}

.hint {
    margin-top: 14px;
    font-size: 12px;
    color: var(--muted)
}

tr[data-new="true"] th {
    background-color: #202b3d;
    color: #e0e0e0;
}

/* Paging controls */
#controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

#controls button,
#exportBtn {
    padding: 8px 14px;
    font-weight: 600;
    transition: background-color 0.2s, color 0.2s, filter 0.15s ease;
    border-radius: 6px;
    border: 1px solid #3a3e47;
    background: #1b1e24;
    color: var(--ink);
    cursor: pointer;
}

#controls button:hover,
#exportBtn:hover {
    filter: brightness(1.2);
}

.toggle-edit.on {
    background-color: #2ed573 !important;
    color: #1e1e1e !important;
}


/* Collapsible panel headers */
.panel-hd {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--line);
}

.panel-hd:hover {
    opacity: 0.85;
}

.panel-caret {
    font-size: 12px;
    color: var(--muted);
    transition: transform 0.15s;
    display: inline-block;
    flex-shrink: 0;
}

.collapsed .panel-caret {
    transform: rotate(-90deg);
}

/* Query box */
#queryBox {
    flex: 0 0 320px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#queryBox.collapsed {
    flex: none;
}

#queryBox.collapsed > *:not(.panel-hd) {
    display: none;
}

#queryResult {
    flex: 1;
    overflow: auto;
    margin: 0;
    padding: 8px;
    background: #0f141b;
    border: 1px solid #2a2e37;
    border-radius: 8px;
    font-size: 12px;
    color: #d9eefc;
    white-space: pre-wrap;
    word-break: break-all;
}

#queryBox h3 {
    margin: 0;
    font-size: 16px;
    color: var(--accent);
}

#queryBox textarea {
    width: 100%;
    height: 120px;
    background: #0f141b;
    border-radius: 8px;
    border: 1px solid #2a2e37;
    color: #d9eefc;
    padding: 10px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 13px;
    resize: vertical;
}

#queryBox .run,
#runQuery {
    margin-top: 10px;
    background: #0b63ff;
    border: none;
    color: #fff;
    padding: 8px 14px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

#queryBox .run:hover,
#runQuery:hover {
    background: #084fd1
}

/* Footer */
#footer {
    background: var(--panel-2);
    border-top: 1px solid var(--line);
    text-align: right;
    font-size: 12px;
    color: #9aa0a6;
    padding: 8px 12px;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px
}

::-webkit-scrollbar-thumb {
    background: #2b313b;
    border-radius: 4px
}

::-webkit-scrollbar-thumb:hover {
    background: #343a45
}

.tbl-group {
    padding: 0;
    cursor: default;
}

.tbl-group-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
}

.tbl-group-header:hover {
    background: #1b1e24;
}

.tbl-caret {
    width: 0;
    height: 0;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    border-left: 6px solid var(--muted);
    transition: transform 0.15s ease;
}

.tbl-group.expanded .tbl-caret {
    transform: rotate(90deg);
}

.tbl-children {
    margin: 2px 0 0 18px;
    padding-left: 10px;
    border-left: 1px solid var(--line);
    display: none;
}

.tbl-group.expanded .tbl-children {
    display: block;
}

.tbl-child {
    padding: 6px 10px;
}

.db-group {
    padding: 0;
    cursor: default;
}

.db-group-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
}

.db-group-header:hover {
    background: #1b1e24;
}

.db-node {
    padding: 0;
    cursor: default;
    border-radius: 8px;
}

.db-node-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
}

.db-node-header:hover {
    background: #1b1e24;
}

.db-node.active>.db-node-header {
    background: rgba(111, 195, 255, .12);
}

.db-caret {
    width: 0;
    height: 0;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    border-left: 6px solid var(--muted);
    transition: transform 0.15s ease;
}

.db-group.expanded>.db-group-header .db-caret,
.db-node.expanded>.db-node-header .db-caret {
    transform: rotate(90deg);
}

.db-children {
    margin: 2px 0 0 18px;
    padding-left: 10px;
    border-left: 1px solid var(--line);
    display: none;
}

.db-group.expanded>.db-children {
    display: block;
}

.db-tables {
    margin: 2px 0 0 18px;
    padding-left: 10px;
    border-left: 1px solid var(--line);
    display: none;
}

.db-node.expanded>.db-tables {
    display: block;
}

.db-table {
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
}

.db-table:hover {
    background: #1b1e24;
}

.db-table.active {
    background: rgba(111, 195, 255, .12);
}

/* Mobile sidebar toggle — hidden on desktop */
#sidebar-toggle {
    display: none;
}

/* ── Mobile layout ────────────────────────────────── */
@media (max-width: 767px) {
    #sidebar-toggle {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 7px 12px;
        border: 1px solid #3a3e47;
        border-radius: 8px;
        background: #1b1e24;
        color: var(--ink);
        cursor: pointer;
        font-size: 14px;
        font-weight: 600;
        white-space: nowrap;
    }

    #topbar h1 {
        font-size: 14px;
    }

    main {
        flex-direction: column;
        padding: 8px;
        gap: 8px;
    }

    aside#left {
        display: none;
        width: 100%;
        max-height: 50vh;
        border-radius: 8px;
    }

    main.sidebar-open aside#left {
        display: flex;
    }

    #mainPane {
        padding: 12px;
        gap: 10px;
    }

    #schemaQuery {
        flex-direction: column;
    }

    #queryBox {
        flex: none;
    }

    #schema {
        max-height: 40vh;
    }

    #rows {
        max-height: 45vh;
        flex: none;
    }

    #controls {
        flex-wrap: wrap;
        gap: 8px;
    }

    #controls button,
    #exportBtn {
        padding: 10px 12px;
        font-size: 14px;
    }

    #queryBox textarea {
        height: 100px;
    }

    td, th {
        font-size: 12px;
        padding: 6px 8px;
    }
}