/* Panel styles: variables, light and dark themes, mobile-first tables. */

:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --text: #1b1f24;
    --muted: #5f6b7a;
    --border: #dfe3e8;
    --accent: #2f6fed;
    --accent-text: #ffffff;
    --danger: #c9372c;
    --ok: #1f8a4c;
    --warn: #b26a00;
    --info: #2f6fed;
    --radius: 10px;
    --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 4%);
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1216;
        --surface: #171b21;
        --surface-2: #1f242c;
        --text: #e6e9ee;
        --muted: #98a2b0;
        --border: #2a313b;
        --accent: #5b8cff;
        --danger: #ff6b5e;
        --ok: #3ccf7f;
        --warn: #f0a63a;
        --info: #5b8cff;
        --shadow: 0 1px 2px rgb(0 0 0 / 40%);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0; line-height: 1.2; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
code, pre, .mono { font-family: var(--mono); font-size: .9em; }
pre { margin: 0; white-space: pre-wrap; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.err { color: var(--danger); }
.break { word-break: break-all; }

/* Layout */
.topbar {
    display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
    padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; color: var(--text); }
.nav { display: flex; gap: .25rem; flex: 1; }
.nav a { color: var(--muted); padding: .35rem .7rem; border-radius: 8px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); font-weight: 600; }
.me { display: flex; align-items: center; gap: .6rem; }
.me-name { max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 28px; height: 28px; border-radius: 50%; }

.page { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.page-center { min-height: 100vh; display: grid; place-items: center; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.crumbs { margin-bottom: .5rem; font-size: .9rem; }
.stack { display: grid; gap: 1rem; margin-bottom: 1rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.card-head h2 { margin: 0; }
.empty { text-align: center; padding: 3rem 1rem; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.empty p:first-child { font-size: 1.15rem; font-weight: 600; margin: 0 0 .25rem; }

/* Controls */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    padding: .5rem .95rem; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer;
    white-space: nowrap; transition: background .15s, opacity .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled, .btn.htmx-request { opacity: .55; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn-ghost { background: transparent; }
.btn-sm { padding: .25rem .6rem; font-size: .85rem; }
.btn-wide { width: 100%; }
.btn.copied { color: var(--ok); }

input[type="text"] {
    font: inherit; color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: 8px; padding: .5rem .75rem; min-width: 0;
}
input[type="text"]:focus-visible, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.create { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head .create { margin: 0; }
.create input { flex: 1 1 14rem; }

/* Status badges */
.badge {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .1rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600;
    background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge-healthy { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge-unhealthy { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge-failed, .badge-not_found { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.badge-creating, .badge-starting, .badge-stopping { background: color-mix(in srgb, var(--info) 15%, transparent); color: var(--info); }
.badge-stopped { background: var(--surface-2); color: var(--muted); }
.tag { font-size: .72rem; padding: .05rem .4rem; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.tag-warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 15%, transparent); }
.spinner {
    width: .7em; height: .7em; border-radius: 50%;
    border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Tables: cards on narrow screens */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.card .table { border: 0; }
.table th, .table td { text-align: left; padding: .65rem .8rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.table-compact th, .table-compact td { padding: .45rem .6rem; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions .btn + .btn { margin-left: .25rem; }
.sbx-title { font-weight: 600; }
tr.revoked td { opacity: .55; }

@media (max-width: 720px) {
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table tr { border-bottom: 1px solid var(--border); padding: .5rem 0; }
    .table td { border: 0; padding: .25rem .8rem; display: flex; gap: .75rem; }
    .table td[data-label]::before { content: attr(data-label); flex: 0 0 7.5rem; color: var(--muted); font-size: .8rem; }
    .table td > * { min-width: 0; }
    .row-actions { text-align: left; }
    .topbar { gap: .5rem; padding: .5rem .75rem; }
    .me-name { display: none; }
    .page { padding: 1rem .75rem 3rem; }
}

/* Facts, errors, logs */
.facts { display: grid; grid-template-columns: 9rem 1fr; gap: .4rem 1rem; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; min-width: 0; }
@media (max-width: 520px) { .facts { grid-template-columns: 1fr; } .facts dd { margin-bottom: .4rem; } }
.error-box { margin-top: 1rem; padding: .85rem 1rem; border-radius: 8px; background: color-mix(in srgb, var(--danger) 9%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); }
.error-box.warn { background: color-mix(in srgb, var(--warn) 9%, transparent); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.error-box p { margin: .35rem 0; }
.log { margin-top: .5rem; padding: .75rem; background: var(--surface-2); border-radius: 6px; font-size: .8rem; max-height: 22rem; overflow: auto; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* Copy lines, tabs, tokens */
.copyline { display: flex; align-items: flex-start; gap: .5rem; background: var(--surface-2); padding: .5rem .75rem; border-radius: 8px; margin: .5rem 0; }
.copyline > code, .copyline > pre { flex: 1; min-width: 0; word-break: break-all; }
.tabs { margin-top: 1rem; }
.tab-list { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: .75rem; overflow-x: auto; }
.tab-list button { background: none; border: 0; border-bottom: 2px solid transparent; padding: .5rem .8rem; font: inherit; color: var(--muted); cursor: pointer; }
.tab-list button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.new-token { padding: .85rem 1rem; border-radius: 8px; border: 1px solid color-mix(in srgb, var(--ok) 40%, transparent); background: color-mix(in srgb, var(--ok) 8%, transparent); margin-bottom: 1rem; }
.new-token p { margin: 0 0 .25rem; }

/* Login, consent */
.login, .consent { width: min(440px, 100%); display: grid; gap: .75rem; }
.login h1, .consent h1 { margin-bottom: .25rem; }
.login p, .consent p { margin: 0; }
.consent-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .5rem; }

/* Flash messages and toasts */
.flash { padding: .65rem .9rem; border-radius: 8px; margin-bottom: 1rem; background: var(--surface-2); }
.flash-error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.flash-success { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); }
.toasts { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; z-index: 50; max-width: min(420px, calc(100vw - 2rem)); }
.toast {
    padding: .7rem 1rem; border-radius: 8px; background: var(--text); color: var(--bg); box-shadow: var(--shadow);
    cursor: pointer; animation: toast-in .2s ease-out; transition: opacity .4s, transform .4s;
}
.toast-error { background: var(--danger); color: #fff; }
.toast-success { background: var(--ok); color: #fff; }
.toast-out { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* View transitions: list and card share the names sbx-<id>-title and sbx-<id>-status. */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .18s; }
::view-transition-group(*) { animation-duration: .25s; animation-timing-function: cubic-bezier(.2, .8, .2, 1); }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
    ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
