/* ============================================================
   Server Panel — "instrument console"
   Black & white; colour only for status (ok / warn / danger).
   Space Grotesk (display) + JetBrains Mono (data).
   ============================================================ */

:root {
    --bg:          #0a0a0a;
    --surface:     #141414;
    --surface-2:   #1c1c1c;
    --line:        #2a2a2a;
    --line-soft:   #1f1f1f;

    --text:        #f2f2f2;
    --text-dim:    #a8a8a8;
    --text-faint:  #6e6e6e;

    --brand:       #ffffff;
    --brand-ink:   #000000;
    --ok:          #3fd7ac;
    --warn:        #f5c451;
    --danger:      #ff6b57;

    --sans: "Space Grotesk", system-ui, -apple-system, sans-serif;
    --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

    --r:    14px;
    --r-sm: 9px;
    --shadow: 0 1px 0 rgba(255,255,255,.02) inset, 0 12px 30px -18px rgba(0,0,0,.7);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; color-scheme: dark; accent-color: var(--text); }

body {
    margin: 0;
    font-family: var(--body);
    font-size: 15px;
    line-height: 1.55;
    color: var(--text);
    background:
        radial-gradient(1100px 560px at 78% -12%, #1a1a1a 0%, transparent 58%),
        radial-gradient(900px 500px at 0% 0%, #141414 0%, transparent 50%),
        var(--bg);
    background-attachment: fixed;
    min-height: 100vh;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { font-family: var(--sans); font-weight: 600; letter-spacing: -.01em; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.02rem; }

code, .mono { font-family: var(--mono); }

.eyebrow {
    font-family: var(--mono);
    font-size: .68rem;
    letter-spacing: .18em;
    text-transform: uppercase;
    color: var(--text-faint);
}

/* ---- top bar (login page) / brand -------------------------- */

.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between;
    padding: .85rem 1.5rem;
    background: rgba(10,10,10,.72);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line-soft);
}
.brand { display: inline-flex; align-items: center; gap: .65rem; font-family: var(--sans); font-weight: 500; font-size: .84rem; letter-spacing: .14em; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand b { font-weight: 700; margin-left: .35em; color: var(--brand); }
.brand-mark { width: 26px; height: 26px; flex: none; transition: transform .2s; }
.brand:hover .brand-mark { transform: rotate(-6deg); }
.brand-mark .bg, .brand-mark .led { fill: var(--brand); }
.brand-mark .u { fill: var(--brand-ink); }


@media (prefers-reduced-motion: reduce) { .brand-mark, .brand-mark .led { animation: none; transition: none; } }

/* ---- sidebar (logged in) ----------------------------------- */

:root { --sidebar-w: 232px; }
.sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 20; width: var(--sidebar-w);
    display: flex; flex-direction: column; gap: 1.6rem;
    padding: 1.3rem .9rem 1.1rem;
    background: rgba(10,10,10,.85);
    border-right: 1px solid var(--line-soft);
}
.sidebar .brand { padding: 0 .55rem; }
.sidenav { display: flex; flex-direction: column; gap: .15rem; }
.sidenav-foot { margin-top: auto; padding-top: .9rem; border-top: 1px solid var(--line-soft); }
.sidenav-pair { display: grid; grid-template-columns: auto 1fr; gap: .3rem; }  /* short "Info", room for "Settings" */
.sidenav-pair a { min-width: 0; padding-right: .4rem; }
.sidenav a {
    display: flex; align-items: center; gap: .7rem;
    padding: .55rem .65rem; border-radius: var(--r-sm);
    color: var(--text-dim); font-family: var(--sans); font-size: .93rem;
}
.sidenav a svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sidenav a:hover { color: var(--text); background: var(--surface); text-decoration: none; }
.sidenav a.active { color: var(--text); background: var(--surface-2); box-shadow: inset 2px 0 0 var(--brand); }
body.with-sidebar .wrap { margin-left: var(--sidebar-w); }


/* ---- layout ------------------------------------------------- */

.wrap { margin: 2.4rem 0 4rem; padding: 0 2rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.6rem; }
.page-head .titles { display: flex; flex-direction: column; gap: .35rem; }

/* ---- buttons ------------------------------------------------ */

.btn {
    display: inline-flex; align-items: center; gap: .5rem; cursor: pointer;
    font-family: var(--sans); font-weight: 600; font-size: .92rem;
    padding: .6rem 1.05rem; border-radius: var(--r-sm);
    border: 1px solid transparent; background: var(--brand); color: var(--brand-ink);
    transition: transform .12s ease, filter .12s ease, background .12s ease, border-color .12s ease;
}
.btn:hover { filter: brightness(1.06); text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.ghost:hover { border-color: var(--brand); filter: none; }
.btn.danger { background: transparent; border-color: rgba(255,107,87,.4); color: var(--danger); }
.btn.danger:hover { background: rgba(255,107,87,.12); }
.btn.small { padding: .4rem .7rem; font-size: .82rem; }
button.btn { line-height: 1; }

/* ---- cards -------------------------------------------------- */

.card {
    background: linear-gradient(180deg, var(--surface) 0%, #101010 100%);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 1.4rem;
    box-shadow: var(--shadow);
}
.card + .card { margin-top: 1.15rem; }
.card.auth { max-width: 400px; margin: 4rem auto; }
.card.pad-lg { padding: 1.8rem; }
.card.danger-zone { border-color: rgba(255,107,87,.28); }

/* ---- sites grid --------------------------------------------- */

.sites-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 1.1rem; }

.site-group { margin-bottom: 1.9rem; }
.group-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .9rem; }
.group-count { font-family: var(--mono); font-size: .7rem; color: var(--text-faint); border: 1px solid var(--line); border-radius: 999px; padding: .04rem .45rem; }

/* Folder cards (overview) */
.folders-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 1.1rem; }
.folder-card {
    display: flex; flex-direction: column; gap: .45rem;
    padding: 1.3rem 1.3rem 1.15rem;
    background: linear-gradient(180deg, var(--surface) 0%, #101010 100%);
    border: 1px solid var(--line); border-radius: var(--r);
    color: var(--text); box-shadow: var(--shadow);
    transition: transform .14s ease, border-color .14s ease;
}
.folder-card:hover { transform: translateY(-3px); border-color: #4a4a4a; text-decoration: none; }
.folder-card.ungrouped { border-style: dashed; }
.folder-card .fhead { display: flex; align-items: center; gap: .6rem; }
.folder-card .ficon { flex: none; font-size: 1.35rem; line-height: 1; }
.folder-card .ficon:not(.logo) { filter: grayscale(1); }  /* emoji fallback stays black & white; real logos keep their colours */
.folder-card .ficon img { display: block; width: 1.5rem; height: 1.5rem; border-radius: 5px; object-fit: contain; }
.folder-card .fname { font-family: var(--sans); font-weight: 600; font-size: 1.05rem; word-break: break-word; }
.folder-card .fmeta { font-family: var(--mono); font-size: .74rem; color: var(--text-faint); }
.folder-card .fmeta .warn { color: var(--warn); }

.site-card {
    position: relative; overflow: hidden;
    display: block; padding: 1.25rem 1.25rem 1.1rem 1.5rem;
    background: linear-gradient(180deg, var(--surface) 0%, #101010 100%);
    border: 1px solid var(--line); border-radius: var(--r);
    color: var(--text); box-shadow: var(--shadow);
    transition: transform .14s ease, border-color .14s ease;
}
.site-card::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
    background: var(--rail, var(--text-faint));
    box-shadow: 0 0 18px -2px var(--rail, transparent);
}
.site-card:hover { transform: translateY(-3px); border-color: #4a4a4a; text-decoration: none; }
.site-card.is-ok    { --rail: var(--ok); }
.site-card.is-setup { --rail: var(--warn); }
.site-card.is-down  { --rail: var(--danger); }

.site-card .domain { font-family: var(--mono); font-weight: 500; font-size: 1.06rem; color: var(--text); word-break: break-all; }
.site-card .metarow { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .9rem; }

/* ---- chips / badges ----------------------------------------- */

.chip {
    display: inline-flex; align-items: center; gap: .35rem;
    font-family: var(--mono); font-size: .72rem; letter-spacing: .02em;
    padding: .22rem .5rem; border-radius: 999px;
    border: 1px solid var(--line); color: var(--text-dim); background: rgba(255,255,255,.015);
}
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.ok    { color: var(--ok);     border-color: rgba(63,215,172,.3); }
.chip.warn  { color: var(--warn);   border-color: rgba(245,196,81,.3); }
.chip.down  { color: var(--danger); border-color: rgba(255,107,87,.32); }
button.chip { cursor: pointer; font-family: var(--mono); line-height: 1.2; }
.chip-action { color: var(--brand); border-color: rgba(255,255,255,.45); background: rgba(255,255,255,.1); }
.chip-action:hover { color: var(--text); border-color: var(--brand); background: rgba(255,255,255,.2); }

/* ---- detail: status header --------------------------------- */

.status-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.6rem; }
.status-head .domain { font-family: var(--mono); font-size: 1.55rem; font-weight: 500; word-break: break-all; }
.status-head .spacer { flex: 1; }

/* ---- key/value ---------------------------------------------- */

.kv { display: grid; grid-template-columns: max-content 1fr; gap: .55rem 1.4rem; margin: 0; }
.kv dt { color: var(--text-faint); font-family: var(--mono); font-size: .76rem; letter-spacing: .04em; text-transform: uppercase; align-self: center; }
.kv dd { margin: 0; font-family: var(--mono); font-size: .9rem; color: var(--text); overflow-wrap: anywhere; }

/* ---- connect guide (the signature sequence) ----------------- */

.guide { display: grid; gap: 0; }
.step { position: relative; display: grid; grid-template-columns: 3.2rem 1fr; gap: 1rem; padding: 1.3rem 0; border-top: 1px dashed var(--line-soft); }
.step:first-child { border-top: 0; }
.step-n { font-family: var(--mono); font-size: 1.5rem; font-weight: 700; color: var(--brand); opacity: .85; line-height: 1; padding-top: .1rem; }
.step.done .step-n { color: var(--ok); }
.step-body h3 { font-family: var(--sans); font-size: 1rem; margin-bottom: .35rem; }
.step-body p { margin: .1rem 0 .8rem; color: var(--text-dim); font-size: .92rem; }
.step-body p .k { color: var(--text); font-family: var(--mono); }

/* ---- copy field --------------------------------------------- */

.copyfield { display: flex; align-items: stretch; gap: .5rem; margin: .5rem 0; }
.copyfield pre {
    flex: 1; margin: 0; padding: .65rem .8rem; overflow-x: auto;
    background: #0c0c0c; border: 1px solid var(--line); border-radius: var(--r-sm);
    font-family: var(--mono); font-size: .82rem; color: var(--text);
    white-space: pre-wrap; word-break: break-all;
}
.copyfield.oneline pre { white-space: nowrap; }
.copy-btn {
    flex: 0 0 auto; align-self: stretch; cursor: pointer;
    font-family: var(--sans); font-weight: 600; font-size: .8rem;
    padding: 0 .85rem; border-radius: var(--r-sm);
    border: 1px solid var(--line); background: var(--surface-2); color: var(--text-dim);
    transition: color .12s, border-color .12s, background .12s;
}
.copy-btn:hover { color: var(--text); border-color: var(--brand); }
.copy-btn.copied { color: var(--ok); border-color: rgba(63,215,172,.4); }

/* ---- forms -------------------------------------------------- */

.field { display: block; margin-bottom: 1.1rem; }
.field > .label { display: block; font-family: var(--sans); font-weight: 500; font-size: .9rem; margin-bottom: .4rem; color: var(--text); }
.field .hint { display: block; margin-top: .35rem; color: var(--text-faint); font-size: .82rem; }
input, select {
    display: block; width: 100%; padding: .62rem .75rem;
    background: #0c0c0c; border: 1px solid var(--line); border-radius: var(--r-sm);
    color: var(--text); font: inherit; font-family: var(--mono); font-size: .9rem;
    transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(255,255,255,.15); }
.form-inline { display: flex; gap: .6rem; align-items: center; }
.form-inline select { width: auto; }

/* ---- flash -------------------------------------------------- */

.flash { display: flex; gap: .6rem; padding: .75rem 1rem; border-radius: var(--r-sm); margin-bottom: 1rem; border: 1px solid var(--line); background: var(--surface); font-size: .92rem; }
.flash::before { font-family: var(--mono); font-weight: 700; }
.flash-ok    { border-color: rgba(63,215,172,.35); color: #bff0e1; }
.flash-ok::before    { content: "✓"; color: var(--ok); }
.flash-error { border-color: rgba(255,107,87,.35); color: #ffd6cf; white-space: pre-wrap; }
.flash-error::before { content: "!"; color: var(--danger); }
.flash-info::before  { content: "›"; color: var(--brand); }

/* ---- misc --------------------------------------------------- */

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.log { background: #0c0c0c; border: 1px solid var(--line); border-radius: var(--r-sm); padding: .75rem .85rem; overflow: auto; max-height: 320px; font-family: var(--mono); font-size: .8rem; white-space: pre; color: var(--text-dim); }
details summary { cursor: pointer; color: var(--text-faint); font-family: var(--mono); font-size: .8rem; margin-top: .6rem; }

/* Collapsible section cards (setup guide, deploy) */
.guide-card > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: .7rem; margin: 0; color: inherit; font-family: inherit; font-size: inherit; }
.guide-card > summary::-webkit-details-marker { display: none; }
.guide-card > summary::after { content: "▾"; margin-left: auto; color: var(--text-faint); transition: transform .18s ease; }
.guide-card[open] > summary::after { transform: rotate(180deg); }
.guide-card[open] > summary { margin-bottom: 1.2rem; }
.summary-note { font-family: var(--mono); font-size: .72rem; color: var(--text-faint); }

.breadcrumb { font-family: var(--mono); font-size: .74rem; letter-spacing: .03em; color: var(--text-faint); margin-bottom: .6rem; }
.breadcrumb a { color: var(--text-dim); }
.breadcrumb a:hover { color: var(--text); }
.breadcrumb .sep { margin: 0 .4rem; opacity: .55; }
.empty { text-align: center; padding: 3rem 1.5rem; }
.empty .glyph { font-family: var(--mono); font-size: 2.4rem; color: var(--text-faint); }
.section-label { display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; }
hr.rule { border: 0; border-top: 1px solid var(--line-soft); margin: 1.4rem 0; }

[hidden] { display: none !important; }

.head-actions { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; }
.search {
    width: 230px; padding: .55rem .8rem; border-radius: var(--r-sm);
    background: #0c0c0c; border: 1px solid var(--line); color: var(--text);
    font-family: var(--mono); font-size: .84rem;
}
.search::placeholder { color: var(--text-faint); }
.search:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(255,255,255,.15); }
.search::-webkit-search-cancel-button { filter: invert(.6); }

/* Label tabs above the folder grid */
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin: -.4rem 0 1.4rem; border-bottom: 1px solid var(--line); }
.tab {
    appearance: none; background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px;
    padding: .55rem .8rem; font: 500 .92rem var(--sans); color: var(--text-dim); cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--brand); }
.tab .n { font-family: var(--mono); font-size: .72rem; color: var(--text-faint); margin-left: .2rem; }
.tab.active .n { color: var(--brand); }
.tab:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; border-radius: 6px 6px 0 0; }
.label-form { margin: -.6rem 0 1.4rem; }
.label-form input[type=text] { width: 12rem; }
@media (max-width: 560px) { .search { width: 100%; } .head-actions { width: 100%; } }

@media (max-width: 560px) {
    .status-head .domain { font-size: 1.2rem; }
    .step { grid-template-columns: 2.2rem 1fr; gap: .7rem; }
    .kv { grid-template-columns: 1fr; gap: .15rem .5rem; }
    .kv dd { margin-bottom: .5rem; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---- database browser (read-only) --------------------------- */

.dtable-card { padding: 0; overflow: hidden; }
.dtable-scroll { overflow-x: auto; }
.dtable { width: 100%; border-collapse: collapse; font-size: .86rem; }
.dtable th {
    text-align: left; font-family: var(--mono); font-weight: 500; font-size: .72rem; letter-spacing: .05em;
    text-transform: uppercase; color: var(--text-faint); padding: .7rem .9rem; border-bottom: 1px solid var(--line);
    white-space: nowrap; background: rgba(255,255,255,.015);
}
.dtable td { padding: .55rem .9rem; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.dtable tbody tr:last-child td { border-bottom: 0; }
.dtable tbody tr:hover td { background: rgba(255,255,255,.04); }
.dtable .num { text-align: right; font-family: var(--mono); white-space: nowrap; }
.dtable td .chip { margin: .1rem .15rem .1rem 0; }
.dtable.rows td { font-family: var(--mono); font-size: .8rem; white-space: nowrap; max-width: 22rem; overflow: hidden; text-overflow: ellipsis; }
.dtable .when { white-space: nowrap; }
.dtable.rows td.null { color: var(--text-faint); font-style: italic; }
.dtable.rows td.masked { color: var(--warn); letter-spacing: .1em; }
.dtable.rows td.binary { color: var(--text-faint); }
.guide-card .dtable-scroll { margin: 0 -1.8rem -1.8rem; }
.ok-text { color: var(--ok); }
.warn-text { color: var(--warn); font-family: var(--mono); font-size: .8rem; }
.pager { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin: 1rem 0 .6rem; }
.pager .spacer { flex: 1; }

/* Narrow screens: sidebar turns into a top bar instead of eating the width. */
@media (max-width: 860px) {
    .topbar { padding: .75rem 1rem; }
    /* The sidebar becomes a top bar with the nav as a scrollable row. */
    .sidebar { position: sticky; top: 0; width: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; padding: .7rem 1rem; border-right: 0; border-bottom: 1px solid var(--line-soft); backdrop-filter: blur(12px); }
    .sidenav { flex-direction: row; flex-wrap: wrap; gap: .2rem; }
    .sidenav-foot { margin: 0 0 0 auto; padding: 0; border: 0; flex-direction: row; }
    .sidenav-pair { display: flex; gap: .2rem; }
    .sidenav a { padding: .4rem .55rem; font-size: .88rem; }
    .sidenav a.active { box-shadow: inset 0 -2px 0 var(--brand); }
    body.with-sidebar .wrap { margin-left: 0; }
    .wrap { padding: 0 1rem; margin-top: 1.4rem; }
    .page-head { flex-wrap: wrap; }
}

/* ---- server page: stat tiles + two columns ------------------ */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.1rem; margin-bottom: 1.15rem; }
.stat { display: flex; flex-direction: column; gap: .45rem; padding: 1.3rem; background: linear-gradient(180deg, var(--surface) 0%, #101010 100%); border: 1px solid var(--line); border-radius: var(--r); }
.stat-value { font-family: var(--sans); font-size: 1.9rem; font-weight: 600; line-height: 1.1; }
.stat-value small { font-size: 1rem; color: var(--text-faint); margin-left: .1rem; }
.stat-note { font-family: var(--mono); font-size: .76rem; color: var(--text-faint); }
.meter { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--text); border-radius: inherit; }
.meter.warn span { background: var(--warn); }
.meter.danger span { background: var(--danger); }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.1rem; }
.cols .card + .card { margin-top: 0; }

/* a button that reads like a quiet text link (e.g. "Forgot password?") */
.linkish { appearance: none; background: none; border: 0; padding: 0; font: inherit; font-size: .85rem; color: var(--text-dim); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.linkish:hover { color: var(--text); }

/* ---- modal (new site) ---------------------------------------- */
.modal {
    width: min(560px, calc(100vw - 2rem)); max-height: calc(100vh - 3rem); overflow: auto;
    padding: 1.6rem 1.8rem 1.8rem; margin: auto;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--line); border-radius: var(--r);
    box-shadow: 0 30px 80px -20px rgba(0,0,0,.9);
}
.modal::backdrop { background: rgba(0,0,0,.65); backdrop-filter: blur(3px); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.3rem; }
.modal-head h2 { font-size: 1.3rem; margin-top: .35rem; }
.modal-close { appearance: none; background: none; border: 1px solid var(--line); border-radius: var(--r-sm); color: var(--text-dim); width: 2rem; height: 2rem; cursor: pointer; font-size: .85rem; }
.modal-close:hover { color: var(--text); border-color: var(--text-faint); }
