:root {
    --bg: #0e1116;
    --bg-soft: #161b22;
    --bg-card: #1c232d;
    --border: #2a3340;
    --border-strong: #3a4654;
    --fg: #e6edf3;
    --fg-muted: #8b949e;
    --accent: #7ee787;
    --accent-soft: #2d4a35;
    --danger: #f85149;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--fg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    overflow: hidden;
}

body {
    display: flex;
    flex-direction: column;
}

/* ---------- Top bar (model + balance) ---------- */

.topbar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
    height: 44px;
}

.topbar .brand {
    font-weight: 500;
    font-size: 13px;
    color: var(--fg);
    letter-spacing: -0.01em;
}

.topbar-spacer { flex: 1; }

.model-picker {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--fg-muted);
}

.model-picker .model-label {
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 10px;
}

#model-select {
    background: var(--bg-card);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 3px 6px;
    font-size: 12px;
    font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
    max-width: 320px;
}

#model-select:disabled { opacity: 0.5; cursor: wait; }

.model-popular-only {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--fg-muted);
    cursor: pointer;
}

.model-popular-only input { margin: 0; cursor: pointer; }

.topup-btn {
    background: var(--bg-card);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0;
    font-size: 16px;
    line-height: 1;
    width: 26px;
    height: 26px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

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

.balance {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 10px;
    font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
    font-size: 12px;
    transition: border-color 200ms ease, background 200ms ease;
}

.balance.charged {
    /* krótka pulse-animacja gdy saldo spadło — przyciąga oko bez krzyczenia */
    animation: balance-pulse 600ms ease-out;
}

.balance.topup {
    animation: balance-topup 600ms ease-out;
}

.balance-icon { color: var(--accent); }

@keyframes balance-pulse {
    0%   { background: rgba(248, 81, 73, 0.18); border-color: var(--danger); }
    100% { background: var(--bg-card);          border-color: var(--border); }
}

@keyframes balance-topup {
    0%   { background: rgba(126, 231, 135, 0.18); border-color: var(--accent); }
    100% { background: var(--bg-card);            border-color: var(--border); }
}

code, .mono {
    font-family: "JetBrains Mono", "Fira Code", "SF Mono", Menlo, Consolas, monospace;
}

.app {
    display: grid;
    grid-template-columns: 1fr 380px;
    flex: 1;
    min-height: 0;  /* pozwól dzieciom z overflow:auto kurczyć się */
}

@media (max-width: 768px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 240px;
    }
}

/* ---------- Tables area ---------- */

.tables-area {
    position: relative;
    overflow: auto;
    background:
        radial-gradient(circle at 1px 1px, rgba(255,255,255,0.04) 1px, transparent 0)
        0 0 / 24px 24px,
        var(--bg);
}

.empty-hint {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    color: var(--fg-muted);
    padding: 32px;
    pointer-events: none;
}

.empty-hint h1 {
    font-size: 28px;
    margin: 0 0 12px;
    color: var(--fg);
    font-weight: 500;
    letter-spacing: -0.01em;
}

.empty-hint p {
    margin: 4px 0;
    max-width: 520px;
    line-height: 1.5;
}

.hint-subtle code {
    background: var(--bg-soft);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    margin: 0 2px;
}

/* ---------- Table card (floating window) ---------- */

.table-card {
    position: absolute;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    min-width: 320px;
    max-width: 90%;
    max-height: 80%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    user-select: none;
}

.table-card.focused {
    border-color: var(--border-strong);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
    cursor: move;
    flex-shrink: 0;
}

.card-title {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-meta {
    font-size: 11px;
    color: var(--fg-muted);
    flex-shrink: 0;
}

.card-close {
    background: none;
    border: none;
    color: var(--fg-muted);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0 4px;
    border-radius: 4px;
}

.card-close:hover {
    color: var(--danger);
    background: rgba(248, 81, 73, 0.1);
}

.card-body {
    overflow: auto;
    user-select: text;
}

table.data {
    border-collapse: collapse;
    width: 100%;
    font-size: 12px;
}

table.data thead th {
    position: sticky;
    top: 0;
    background: var(--bg-soft);
    text-align: left;
    padding: 8px 12px;
    font-weight: 600;
    color: var(--fg-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

table.data tbody td {
    padding: 6px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
}

table.data tbody tr:hover td {
    background: rgba(255, 255, 255, 0.03);
}

table.data td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ---------- Console ---------- */

.console {
    display: flex;
    flex-direction: column;
    background: var(--bg-soft);
    border-left: 1px solid var(--border);
    min-height: 0;
}

@media (max-width: 768px) {
    .console {
        height: auto;
        border-left: none;
        border-top: 1px solid var(--border);
    }
}

.console-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.console-header .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent);
}

.console-header .title {
    font-size: 12px;
    color: var(--fg-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    flex: 1;
}

.clear-btn {
    background: none;
    border: none;
    color: var(--fg-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 0 6px;
    line-height: 1;
}

.clear-btn:hover { color: var(--fg); }

.console-log {
    flex: 1;
    overflow-y: auto;
    padding: 10px 14px;
    font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.5;
}

.log-entry {
    margin-bottom: 4px;
    word-wrap: break-word;
}

.log-entry .ts {
    color: var(--fg-muted);
    margin-right: 8px;
}

.log-entry.cmd .body { color: var(--accent); }
.log-entry.cmd .body::before { content: "> "; color: var(--fg-muted); }
.log-entry.ok .body { color: var(--fg); }
.log-entry.err .body { color: var(--danger); }
.log-entry.info .body { color: var(--fg-muted); }
.log-entry.sys .body { color: #d4a72c; }
.log-entry.sys .body::before { content: "· "; color: var(--fg-muted); }

.console-input {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

.console-input .prompt {
    color: var(--accent);
    font-family: "JetBrains Mono", monospace;
    font-weight: 600;
}

.console-input input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--fg);
    font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
    font-size: 13px;
    padding: 4px 0;
}

.console-input input::placeholder {
    color: var(--fg-muted);
}

.console-input.busy .prompt {
    animation: blink 0.8s infinite;
}

@keyframes blink {
    50% { opacity: 0.3; }
}

/* ---- Pubkey live-panel ---------------------------------------------------- */
/* Wizualnie wyodrębnione od tabel: węższe, lekko inny accent, krótki flash
   przy każdym update żeby user zauważył że dane się odświeżyły. */

.pubkey-panel-card {
    border-color: var(--accent);
}

.pubkey-panel-card .card-meta {
    color: var(--accent);
}

.panel-body {
    padding: 12px 14px;
    overflow-y: auto;
    max-height: 70vh;
}

.panel-grid {
    display: grid;
    grid-template-columns: max-content 1fr;
    column-gap: 14px;
    row-gap: 4px;
    font-size: 12px;
    margin-bottom: 10px;
}

.panel-row {
    display: contents;
}

.panel-label {
    color: var(--fg-muted);
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.05em;
    align-self: center;
}

.panel-value {
    color: var(--fg);
    word-break: break-word;
}

.panel-value.mono {
    font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
    font-size: 11px;
}

.role-badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.role-primary {
    background: var(--accent);
    color: var(--bg);
}

.role-secondary {
    background: var(--border);
    color: var(--fg-muted);
}

.panel-section-h {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--fg-muted);
    margin: 14px 0 4px 0;
    padding-bottom: 2px;
    border-bottom: 1px solid var(--border);
}

.panel-mini-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    font-family: "JetBrains Mono", monospace;
}

.panel-mini-table td {
    padding: 2px 4px;
    border-bottom: 1px solid var(--border);
    color: var(--fg);
}

.panel-mini-table td:first-child {
    color: var(--fg-muted);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.panel-mini-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.panel-empty {
    padding: 24px;
    text-align: center;
    color: var(--fg-muted);
}

.panel-flash {
    animation: panelFlash 0.8s ease-out;
}

@keyframes panelFlash {
    0%   { box-shadow: 0 0 0 2px var(--accent), 0 0 12px var(--accent); }
    100% { box-shadow: none; }
}

/* ---------- SQL approval modal ---------- */
/* Jasny motyw + duży font żeby SQL dało się przeczytać też z telefonu. */

.sql-confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.sql-confirm-overlay[hidden] { display: none; }

.sql-confirm-modal {
    background: #ffffff;
    color: #1a1a1a;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    max-width: 760px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 28px 28px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
}

.sql-confirm-modal h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
    color: #111;
}

.sql-confirm-purpose {
    font-size: 14px;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: -4px;
}

.sql-confirm-code {
    background: #f4f6fa;
    border: 1px solid #d4dae3;
    border-radius: 8px;
    padding: 16px 18px;
    margin: 0;
    font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
    font-size: 17px;
    line-height: 1.5;
    color: #0b3a8c;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-x: auto;
    max-height: 50vh;
}

.sql-confirm-reason-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 14px;
    color: #444;
}

.sql-confirm-reason-wrap input {
    padding: 10px 12px;
    border: 1px solid #c4ccd6;
    border-radius: 6px;
    font-size: 15px;
    font-family: inherit;
    color: #1a1a1a;
    background: #fff;
}

.sql-confirm-reason-wrap input:focus {
    outline: none;
    border-color: #4c8bf5;
    box-shadow: 0 0 0 3px rgba(76, 139, 245, 0.2);
}

.sql-confirm-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 4px;
}

.sql-confirm-buttons button {
    padding: 12px 22px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    font-family: inherit;
}

.sql-confirm-approve {
    background: #1f8a3d;
    color: #fff;
}
.sql-confirm-approve:hover { background: #176b30; }
.sql-confirm-approve:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(31, 138, 61, 0.35);
}

.sql-confirm-reject {
    background: #fff;
    color: #b3261e;
    border-color: #d6a7a4;
}
.sql-confirm-reject:hover { background: #fdecec; }
.sql-confirm-reject:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(179, 38, 30, 0.25);
}

@media (max-width: 520px) {
    .sql-confirm-modal {
        padding: 20px 18px 18px;
        font-size: 15px;
    }
    .sql-confirm-modal h2 { font-size: 19px; }
    .sql-confirm-code { font-size: 16px; padding: 14px; }
    .sql-confirm-buttons { flex-direction: column-reverse; }
    .sql-confirm-buttons button { width: 100%; }
}
