:root {
    --bg: #ffffff;
    --surface: #f9fafb;
    --surface-2: #f3f4f6;
    --code-bg: rgba(0, 0, 0, .04);
    --ink: #111827;
    --ink-strong: #030712;
    --muted: #6b7280;
    --line: #e5e7eb;
    --line-strong: #d1d5db;

    --green: #1f7a3d;
    --green-bg: #eaf7ee;
    --yellow: #8a6100;
    --yellow-bg: #fdf5e2;
    --grey-bg: #f2f3f5;
    --red: #bf4f51;
    --red-bg: #fdeceb;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-pill: 999px;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .04);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, .06);

    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
    --text-display: 2rem;
    --text-h1: 1.5rem;
    --text-h2: 1.25rem;
    --text-h3: 1.1rem;
    --text-body: 1rem;
    --text-small: 0.875rem;
    --text-xs: 0.75rem;
    --line-body: 1.55;
    --lead-tight: 1.2;
    --transition-fast: 120ms ease;
    --transition-normal: 200ms ease;

    --focus-ring: 0 0 0 3px rgba(17, 24, 39, .18);
    --hover-bg: rgba(17, 24, 39, .04);
}

html.dark {
    --bg: #09090b;
    --surface: #111113;
    --surface-2: #18181b;
    --code-bg: rgba(255, 255, 255, .06);
    --ink: #f9fafb;
    --ink-strong: #ffffff;
    --muted: #a1a1aa;
    --line: #27272a;
    --line-strong: #3f3f46;

    --green: #4ade80;
    --green-bg: #172a1e;
    --yellow: #facc15;
    --yellow-bg: #2a2417;
    --grey-bg: #1f2937;
    --red: #f87171;
    --red-bg: #2a1718;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, .4);

    --focus-ring: 0 0 0 3px rgba(249, 250, 251, .18);
    --hover-bg: rgba(249, 250, 251, .06);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--text-body);
    line-height: var(--line-body);
    color: var(--ink);
    background: var(--bg);
}

h1 {
    font-size: var(--text-h1);
    line-height: var(--lead-tight);
    margin: 0 0 var(--space-2);
}

h2 {
    font-size: var(--text-h2);
    line-height: var(--lead-tight);
    margin: var(--space-10) 0 var(--space-3);
}

h3 {
    font-size: var(--text-h3);
    line-height: var(--lead-tight);
    margin: var(--space-6) 0 var(--space-2);
}

.muted {
    color: var(--muted);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.hidden {
    display: none !important;
}

.pre-line {
    white-space: pre-line;
}

.container {
    width: 100%;
    max-width: 1120px;
    margin-inline: auto;
    padding-inline: var(--space-4);
}

.site-header {
    border-bottom: 1px solid var(--line);
}

.header-row {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding-block: var(--space-3);
    flex-wrap: wrap;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    margin-inline: auto;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.site-main {
    padding-block: var(--space-10);
}

.site-footer {
    border-top: 1px solid var(--line);
    padding-block: var(--space-6);
}

.footer-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-3);
}

.brand {
    font-weight: 700;
    text-decoration: none;
    color: var(--ink);
}

.who {
    color: var(--muted);
}

.lang-switch-btn,
.theme-switch-btn {
    border: 0;
    background: none;
    color: var(--muted);
    font: inherit;
    cursor: pointer;
    padding: 0;
    border-radius: var(--radius-sm);
    transition: color var(--transition-fast);
}

.lang-switch-btn:hover,
.theme-switch-btn:hover {
    color: var(--ink);
}

.lang-switch-btn:focus-visible,
.theme-switch-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.button {
    display: inline-flex;
    min-width: 8rem;
    padding: .55rem 1.1rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    color: var(--ink);
    font: inherit;
    text-decoration: none;
    cursor: pointer;
    justify-content: center;
    align-items: center;
    text-align: center;
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

.button:hover {
    background: var(--hover-bg);
}

.button:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.button.small {
    padding: .2rem .6rem;
    font-size: var(--text-small);
    min-width: 0;
}

.button.danger {
    background: var(--red);
    border-color: var(--red);
    color: #fff;
}

.button.block,
.button-block {
    width: 100%;
}

.button[disabled] {
    background: var(--line);
    border-color: var(--line);
    color: var(--muted);
    cursor: not-allowed;
}

button.link {
    border: 0;
    background: none;
    color: var(--muted);
    font: inherit;
    cursor: pointer;
    padding: 0;
    border-radius: var(--radius-sm);
    transition: color var(--transition-fast);
}

button.link:hover {
    color: var(--ink);
}

button.link:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

form {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: center;
    margin: var(--space-2) 0;
}

label {
    display: block;
    width: 100%;
    margin-top: var(--space-2);
}

label.toggle {
    width: auto;
}

input, select {
    padding: .5rem .65rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    font: inherit;
    background: var(--bg);
    color: var(--ink);
    transition: border-color var(--transition-fast);
}

input:focus-visible, select:focus-visible {
    outline: none;
    border-color: var(--line-strong);
    box-shadow: var(--focus-ring);
}

.field-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    text-align: center;
}

.summary {
    display: flex;
    gap: var(--space-10);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}

.figure {
    display: flex;
    flex-direction: column;
}

.figure .value {
    font-size: var(--text-display);
    font-weight: 700;
    line-height: var(--lead-tight);
}

.figure .label {
    color: var(--muted);
    font-size: var(--text-small);
}

.blocked {
    display: block;
    padding: var(--space-3) var(--space-4);
    background: var(--yellow-bg);
    border-left: 3px solid var(--yellow);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-6);
}

.stepper {
    display: flex;
    gap: var(--space-2);
    list-style: none;
    padding: 0;
    margin: var(--space-6) 0;
}

.stepper li {
    flex: 1;
    padding: var(--space-2) var(--space-3);
    text-align: center;
    font-size: var(--text-small);
    color: var(--muted);
    border-top: 2px solid var(--line);
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.stepper li.done {
    color: var(--ink);
    border-top-color: var(--green);
    font-weight: 600;
}

.card {
    padding: var(--space-5) var(--space-6);
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.card-progress {
    background: var(--surface);
}

.card-ready {
    background: var(--green-bg);
    border-color: var(--green);
}

.card-stopped {
    background: var(--yellow-bg);
    border-color: var(--yellow);
}

.card-deleted {
    background: var(--grey-bg);
    color: var(--muted);
}

.card-failed {
    background: var(--red-bg);
    border-color: var(--red);
    text-align: center;
}

.card .label {
    display: inline-block;
    width: 6rem;
    color: var(--muted);
}

.card code {
    font-family: var(--font-mono);
    font-size: var(--text-small);
    padding: .1rem .4rem;
    background: var(--code-bg);
    border-radius: var(--radius-sm);
}

.card .actions {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.card-ready .actions {
    justify-content: center;
}

.card-failed .actions {
    justify-content: center;
}

.card-package {
    text-align: center;
}

.card-package h3 {
    margin: 0 0 var(--space-2);
}

.card-package .units {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0 0 var(--space-1);
}

.card-package .units small {
    font-size: var(--text-small);
    font-weight: 400;
    color: var(--muted);
}

.card-package .price {
    color: var(--muted);
    margin: 0 0 var(--space-4);
}

.packages-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    gap: var(--space-4);
    margin-top: var(--space-4);
}

.packages-extra.hidden {
    display: none;
}

.spinner {
    display: inline-block;
    width: .9rem;
    height: .9rem;
    border: 2px solid var(--line);
    border-top-color: var(--ink);
    border-radius: 50%;
    animation: spin 900ms linear infinite;
    vertical-align: -.1rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .spinner {
        animation: none;
    }
}

.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

.pill {
    display: inline-block;
    font-size: var(--text-xs);
    font-weight: 500;
    padding: .15rem .6rem;
    border-radius: var(--radius-pill);
    background: var(--grey-bg);
    color: var(--ink);
    white-space: nowrap;
}

.pill-ready {
    background: var(--green-bg);
    color: var(--green);
}

.pill-stopped {
    background: var(--yellow-bg);
    color: var(--yellow);
}

.pill-failed {
    background: var(--red-bg);
    color: var(--red);
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-small);
}

th, td {
    text-align: left;
    padding: var(--space-3) var(--space-2);
    border-bottom: 1px solid var(--line);
}

th {
    color: var(--muted);
    font-weight: 600;
}

tbody tr:hover td {
    background: var(--hover-bg);
}

td form {
    margin: 0;
}

td.named {
    display: flex;
    align-items: center;
    gap: .4rem;
}

td.named form {
    display: inline-flex;
}

button.pin {
    border: 0;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: 1.15rem;
    line-height: 1;
    padding: 0;
    cursor: pointer;
}

button.pin[aria-pressed="true"] {
    color: var(--yellow);
}

button.pin:focus-visible {
    outline: 2px solid var(--ink);
    outline-offset: 2px;
}

.account-picker {
    width: 100%;
    margin: var(--space-2) 0;
}

.account-picker input[type="text"] {
    width: 100%;
    margin-bottom: var(--space-2);
}

.account-picker table {
    cursor: pointer;
}

.account-picker tr.user-row:hover td {
    background: var(--grey-bg);
}

.account-picker tr.user-row.selected td {
    background: var(--green-bg);
}

.pagination {
    display: flex;
    gap: var(--space-3);
    align-items: center;
    margin-top: var(--space-2);
    flex-wrap: wrap;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.tab-input {
    position: absolute;
    width: 1px;
    height: 1px;
    clip: rect(0 0 0 0);
}

.tab-label {
    padding: var(--space-2) var(--space-4);
    border: 1px solid var(--line);
    border-bottom: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    background: var(--surface-2);
    cursor: pointer;
    font-size: var(--text-small);
    font-weight: 500;
    color: var(--muted);
    transition: background var(--transition-fast), color var(--transition-fast);
}

.tab-label:hover {
    background: var(--hover-bg);
    color: var(--ink);
}

.tab-input:checked + .tab-label {
    background: var(--bg);
    color: var(--ink);
    font-weight: 600;
    border-color: var(--line);
}

.tab-pane {
    display: none;
    flex-basis: 100%;
    order: 1;
    border-top: 1px solid var(--line);
    padding-top: var(--space-4);
}

#tab-recent-servers:checked ~ #content-recent-servers {
    display: block;
}

#tab-users:checked ~ #content-users,
#tab-add-units:checked ~ #content-add-units,
#tab-deployments:checked ~ #content-deployments,
#tab-packages:checked ~ #content-packages {
    display: block;
}

#cred-chat:checked ~ #pane-chat,
#cred-api:checked ~ #pane-api {
    display: block;
}

.card .address,
.card .secret {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.card .address .label,
.card .secret .label {
    flex: 0 0 9.5rem;
    white-space: nowrap;
}

.card .address code a {
    color: inherit;
}

.card .address code,
.card .secret code {
    flex: 0 1 20rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.deployments {
    list-style: none;
    padding: 0;
}

.deployments li {
    display: flex;
    gap: var(--space-3);
    align-items: center;
    padding: .4rem 0;
    border-bottom: 1px solid var(--line);
}

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

.toast {
    position: fixed;
    top: var(--space-6);
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    white-space: pre-line;
    text-align: center;
    padding: .75rem 1rem;
    border: 1px solid var(--red);
    border-radius: var(--radius-md);
    background: var(--red-bg);
    color: var(--red);
    box-shadow: var(--shadow-md);
}

.toast-error {
    border-color: var(--red);
    background: var(--red-bg);
    color: var(--red);
}

.toast-info {
    border-color: var(--line-strong);
    background: var(--surface-2);
    color: var(--ink);
}

.toast-success {
    border-color: var(--green);
    background: var(--green-bg);
    color: var(--green);
}

.actions-row {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
    align-items: center;
}

.service-narrow {
    max-width: 680px;
    margin-inline: auto;
}

.card-narrow {
    max-width: 480px;
    margin-inline: auto;
}

.message-card {
    margin: var(--space-6) 0;
}

.message-text {
    margin: 0;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    flex-wrap: wrap;
    gap: var(--space-4);
}
