:root {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --ink: #1c2330;
    --muted: #6b7484;
    --line: #dde1e8;
    --accent: #0f6e6e;
    --accent-ink: #ffffff;
    --accent-soft: #e3f1f0;
    --danger: #b3261e;
    --danger-soft: #fbe9e7;
    --good: #1c7a43;
    --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
    display: flex;
    flex-direction: column;
}

h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 10px; }
code { font-family: var(--mono); font-size: 13px; word-break: break-all; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
    display: flex; align-items: center; gap: 8px;
    padding: 0 20px; height: 48px; flex: none;
    background: #18212f; color: #fff;
}
.brand { font-weight: 600; letter-spacing: .2px; margin-right: auto; white-space: nowrap; }
.db-name { font-weight: 400; color: #9fb0c6; margin-left: 4px; }
.topbar nav a {
    color: #c5d0de; text-decoration: none; padding: 6px 12px; border-radius: 6px; margin-left: 4px;
}
.topbar nav a:hover { color: #fff; }
.topbar nav a.active { background: rgba(255,255,255,.12); color: #fff; }

/* ---------- layout ---------- */
.layout { flex: 1; display: flex; min-height: 0; }

.sidebar {
    width: 270px; flex: none; display: flex; flex-direction: column;
    background: var(--panel); border-right: 1px solid var(--line);
}
.sidebar input { margin: 12px; width: auto; }

.table-list { list-style: none; margin: 0; padding: 0 6px 12px; overflow-y: auto; flex: 1; }
.table-list button {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    width: 100%; padding: 7px 10px; border: 0; border-radius: 6px;
    background: none; font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.table-list button:hover { background: var(--bg); }
.table-list button.current { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.table-list .tname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-list .schema { color: var(--muted); font-weight: 400; }
.table-list .count { color: var(--muted); font-size: 12px; font-weight: 400; font-variant-numeric: tabular-nums; }
.table-list .none { padding: 10px; color: var(--muted); }

.content { flex: 1; min-width: 0; padding: 20px; overflow: auto; }

.empty { text-align: center; color: var(--muted); margin-top: 18vh; }
.empty h2 { font-size: 18px; color: var(--ink); }

/* ---------- controls ---------- */
input[type=text], input[type=search], input[type=password], select, textarea {
    width: 100%; padding: 7px 10px; font: inherit; color: inherit;
    background: #fff; border: 1px solid var(--line); border-radius: 6px;
}
textarea { font-family: var(--mono); font-size: 13px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input:disabled, textarea:disabled { background: var(--bg); color: var(--muted); }

.btn {
    padding: 7px 14px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
    color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 6px;
}
.btn:hover { border-color: #b9c0cc; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #0b5a5a; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
dialog.confirm { width: min(440px, 94vw); padding: 20px; }
dialog.confirm p { word-break: break-word; }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); }
.btn:disabled { opacity: .5; cursor: default; }

.link { border: 0; background: none; padding: 2px 4px; font: inherit; color: var(--accent); cursor: pointer; }
.link:hover { text-decoration: underline; }
.link.danger { color: var(--danger); }

/* ---------- table view ---------- */
.toolbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar > div:first-child { margin-right: auto; }
.search { display: flex; gap: 6px; }
.search input { width: 220px; }
.search select { width: auto; max-width: 190px; }

.grid-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: auto; }
.grid { border-collapse: collapse; width: 100%; }
.grid th, .grid td {
    padding: 8px 12px; text-align: left; white-space: nowrap;
    border-bottom: 1px solid var(--line);
}
.grid th { background: #fafbfc; position: sticky; top: 0; vertical-align: bottom; }
.grid td { font-family: var(--mono); font-size: 13px; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover td { background: #f8fafb; }
.grid .cname { font-weight: 600; }
.grid .ctype { font-weight: 400; font-size: 11px; color: var(--muted); }
.grid .pk {
    font-size: 10px; font-weight: 700; color: var(--accent); background: var(--accent-soft);
    padding: 1px 4px; border-radius: 3px; margin-right: 5px;
}
.grid td.null { color: #a3abb8; font-style: italic; }
.grid td.none { text-align: center; color: var(--muted); padding: 28px; font-family: inherit; }
.grid .actions-col { font-family: inherit; width: 1%; }
.foot { margin-top: 8px; font-size: 12px; }

/* ---------- banners / toast ---------- */
.banner { padding: 10px 14px; border-radius: 6px; margin: 0 0 14px; }
.banner.error { background: var(--danger-soft); color: var(--danger); }
.banner.success { background: #e5f4ea; color: var(--good); }

.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 20;
    max-width: 80vw; padding: 10px 18px; border-radius: 8px;
    background: #18212f; color: #fff; box-shadow: 0 6px 24px rgba(0,0,0,.2);
}
.toast.error { background: var(--danger); }

/* ---------- dialog ---------- */
dialog {
    width: min(640px, 94vw); max-height: 90vh; padding: 0;
    border: 0; border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.3); color: var(--ink);
}
dialog::backdrop { background: rgba(20, 28, 40, .45); }
dialog form { display: flex; flex-direction: column; max-height: 90vh; padding: 20px; }
dialog h2 { font-size: 17px; margin-bottom: 2px; }
dialog p { margin: 0 0 12px; font-size: 13px; }

.fields { overflow-y: auto; margin: 0 -20px; padding: 0 20px; }
.field { padding: 8px 0; }
.field > label { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.fname { font-weight: 600; }
.ftags { font-size: 12px; color: var(--muted); }
.finput { display: flex; gap: 10px; align-items: flex-start; }
.nullcheck { display: flex; align-items: center; gap: 4px; padding-top: 7px; font-size: 12px; color: var(--muted); white-space: nowrap; }

.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 16px; }

/* ---------- settings page ---------- */
.settings { width: min(820px, 100%); margin: 0 auto; padding: 24px 20px 40px; overflow: auto; flex: 1; }
.settings h1 { margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 18px 20px; margin-bottom: 16px; }
.card p { margin: 0 0 12px; }
.card .banner { margin: 12px 0 0; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; }
.good { color: var(--good); font-weight: 600; }
.bad { color: var(--danger); }
.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ---------- login page ---------- */
.login { flex: 1; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; padding: 28px; margin: 0; }
.login-card h1 { font-size: 22px; }
.login-card p { margin: 0; }
.login-card .banner { margin: 0; }
.login-card input { padding: 10px 12px; font-size: 16px; }
.login-card .btn { padding: 10px 14px; }
.small { font-size: 12px; }

/* ---------- small screens ---------- */
.menu-btn {
    display: none; flex: none; padding: 4px 9px; border: 0; border-radius: 6px;
    background: none; color: #fff; font-size: 20px; line-height: 1; cursor: pointer;
}
.menu-btn:hover { background: rgba(255,255,255,.12); }
.backdrop { display: none; }

@media (max-width: 760px) {
    .menu-btn { display: block; }
    .topbar { padding: 0 10px; }
    .db-name { display: none; }
    .topbar nav a { padding: 6px 8px; margin-left: 0; }

    /* table list becomes a slide-in menu, hidden until the menu button is tapped */
    .layout { position: relative; overflow: hidden; }
    .sidebar {
        position: absolute; top: 0; bottom: 0; left: 0; z-index: 15;
        width: min(300px, 85vw);
        transform: translateX(-100%); visibility: hidden;
        transition: transform .2s ease, visibility .2s;
        box-shadow: 4px 0 24px rgba(0,0,0,.18);
    }
    body.menu-open .sidebar { transform: none; visibility: visible; }
    body.menu-open .backdrop {
        display: block; position: absolute; inset: 0; z-index: 14; background: rgba(20, 28, 40, .45);
    }
    .table-list button { padding: 10px; }

    .content { padding: 14px 12px; }
    .empty { margin-top: 10vh; }
    h1 { font-size: 18px; overflow-wrap: anywhere; }

    .toolbar { gap: 10px; }
    .toolbar > div:first-child { flex: 1 1 100%; margin-right: 0; }
    .search { flex: 1 1 100%; flex-wrap: wrap; }
    .search select { flex: 1 1 100%; max-width: none; }
    .search input { flex: 1 1 120px; width: auto; }
    .toolbar > .btn.primary { flex: 1 1 100%; }
    .btn, .search select, .search input { padding-top: 9px; padding-bottom: 9px; }
    input[type=text], input[type=search], input[type=password], select, textarea { font-size: 16px; } /* stops iOS zooming in on focus */

    .grid th, .grid td { padding: 8px 10px; }
    .grid td { max-width: 220px; }

    dialog form { padding: 16px; }
    .fields { margin: 0 -16px; padding: 0 16px; }
    .field > label { flex-direction: column; gap: 0; }

    .settings { padding: 16px 12px 32px; }
    .card { padding: 14px; }
    .kv { grid-template-columns: 1fr; gap: 2px 0; }
    .kv dd { margin-bottom: 8px; }
    .actions .btn { flex: 1 1 auto; }
}
