/* Chicane V3 design system — dark-first.
   Brand colour --main is overridden at runtime from System Settings (BrandColor). */

:root,
[data-theme="dark"] {
    --bg: #0f1117;
    --surface-1: #161b22;
    --surface-2: #21262d;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --text-ghost: #484f58;
    --main: #3b82f6;
    --radius-sm: 6px;
    --green: #00c98e;
    --amber: #f59e0b;
    --red: #ef4444;
    --blue: #3b82f6;
    --purple: #8b5cf6;
    --grey: #8b949e;
}

[data-theme="light"] {
    --bg: #f6f8fa;
    --surface-1: #ffffff;
    --surface-2: #f0f2f5;
    --border: #d0d7de;
    --text: #1f2937;
    --text-muted: #57606a;
    --text-ghost: #8b949e;
    --main: #3b82f6;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 13px;
    line-height: 1.5;
}

a { color: var(--main); }

code, pre, .mono {
    font-family: "Cascadia Code", Consolas, ui-monospace, monospace;
}

/* ---------- Topbar ---------- */
.topbar {
    position: sticky; top: 0; z-index: 100;
    display: flex; align-items: center; gap: 16px;
    padding: 10px 20px;
    background: var(--surface-1);
    border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 15px; font-weight: 600; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav button {
    padding: 6px 14px;
    background: transparent; border: 1px solid transparent;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer; font-size: 12px; font-weight: 500;
    transition: all 0.15s;
}
.topbar nav button:hover { background: var(--surface-2); color: var(--text); }
.topbar nav button.active { background: var(--main); color: #fff; border-color: var(--main); }
.topbar .right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.topbar .meta { color: var(--text-muted); font-size: 11px; }

/* ---------- Main ---------- */
main { padding: 20px; min-width: 0; }
table { width: 100%; }
section { display: none; }
section.active { display: block; }

h2 { font-size: 18px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 24px 0 8px; font-weight: 600; color: var(--text-muted); padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.hint, .small { color: var(--text-muted); font-size: 11px; }
.ghost { color: var(--text-ghost); }

/* ---------- Cards ---------- */
.card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin: 12px 0;
    overflow: hidden;
}
.card.accent-info { border-left: 3px solid var(--blue); }
.card.accent-good { border-left: 3px solid var(--green); }
.card.accent-warn { border-left: 3px solid var(--amber); }
.card.accent-bad  { border-left: 3px solid var(--red); }

/* ---------- Tables ---------- */
table {
    width: 100%; border-collapse: collapse; margin-top: 10px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
th, td {
    text-align: left; padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 12px; vertical-align: top;
}
thead th {
    position: sticky; top: 0;
    background: var(--surface-2);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
}
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td code {
    background: var(--surface-2);
    padding: 1px 6px; border-radius: 3px;
    font-size: 11px; color: var(--text-muted);
}

/* ---------- Forms ---------- */
input, select, textarea {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    width: 100%;
}
input:focus, select:focus, textarea:focus {
    outline: 0; border-color: var(--main);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--main) 30%, transparent);
}
textarea { font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; }
label {
    display: block;
    color: var(--text-muted);
    font-size: 11px; font-weight: 500;
    margin-bottom: 4px;
}
form.inline {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin: 12px 0;
}
form.inline label { display: flex; flex-direction: column; gap: 4px; }

/* ---------- Buttons ---------- */
button, .btn {
    padding: 6px 14px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 12px; font-weight: 500;
    cursor: pointer; transition: all 0.15s;
}
button:hover, .btn:hover { background: var(--border); }
button.primary, .btn.primary {
    background: var(--main); color: #fff; border-color: var(--main);
}
button.primary:hover, .btn.primary:hover {
    background: color-mix(in srgb, var(--main), black 15%);
}
button.danger, .btn.danger {
    background: var(--red); color: #fff; border-color: var(--red);
}
button.danger:hover { background: color-mix(in srgb, var(--red), black 15%); }
button.ghost {
    background: transparent; border-color: transparent; color: var(--text-muted);
}
button.ghost:hover { background: var(--surface-2); color: var(--text); }
button.sm { padding: 3px 10px; font-size: 11px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Badges ---------- */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px; font-weight: 500;
    background: color-mix(in srgb, var(--text-muted), transparent 85%);
    color: var(--text-muted);
    white-space: nowrap;
}
.badge.green   { background: color-mix(in srgb, var(--green), transparent 85%); color: var(--green); }
.badge.amber   { background: color-mix(in srgb, var(--amber), transparent 85%); color: var(--amber); }
.badge.red     { background: color-mix(in srgb, var(--red), transparent 85%); color: var(--red); }
.badge.blue    { background: color-mix(in srgb, var(--blue), transparent 85%); color: var(--blue); }
.badge.purple  { background: color-mix(in srgb, var(--purple), transparent 85%); color: var(--purple); }
.badge.muted   { background: var(--surface-2); color: var(--text-muted); }

/* Status-coloured badges (used by host/worker tables) */
.b-online    { background: color-mix(in srgb, var(--green), transparent 80%); color: var(--green); }
.b-offline   { background: color-mix(in srgb, var(--red), transparent 80%); color: var(--red); }
.b-enrolling { background: color-mix(in srgb, var(--amber), transparent 80%); color: var(--amber); }
.b-disabled  { background: var(--surface-2); color: var(--text-muted); }
.b-healthy   { background: color-mix(in srgb, var(--green), transparent 80%); color: var(--green); }
.b-starting  { background: color-mix(in srgb, var(--blue), transparent 80%); color: var(--blue); }
.b-degraded  { background: color-mix(in srgb, var(--amber), transparent 80%); color: var(--amber); }
.b-draining  { background: color-mix(in srgb, var(--amber), transparent 80%); color: var(--amber); }
.b-stopped   { background: var(--surface-2); color: var(--text-muted); }
.b-unknown   { background: var(--surface-2); color: var(--text-muted); }

/* ---------- Pre / log blocks ---------- */
pre {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-size: 11.5px;
    overflow: auto;
    max-height: 380px;
    color: var(--text-muted);
    /* Wrap long lines (file paths, log output) instead of triggering horizontal scroll. */
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 100%;
    box-sizing: border-box;
}

/* ---------- Toasts (bottom-right stack, slide-in) ---------- */
.toast-stack {
    position: fixed; bottom: 20px; right: 20px;
    display: flex; flex-direction: column; gap: 8px;
    z-index: 9999;
}
.toast {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-left: 3px solid var(--blue);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 12px;
    color: var(--text);
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    animation: toast-in 0.2s ease-out;
    min-width: 260px; max-width: 360px;
}
.toast.green { border-left-color: var(--green); }
.toast.amber { border-left-color: var(--amber); }
.toast.red   { border-left-color: var(--red); }
.toast strong { display: block; font-size: 12px; }
.toast .body { color: var(--text-muted); margin-top: 2px; }
@keyframes toast-in {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ---------- Settings rows (System Settings tab) ---------- */
.settings-section { margin-bottom: 22px; }
.settings-section-title {
    font-size: 13px; font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}
.settings-row {
    /* minmax(0, 1fr) — without the 0 minimum, grid items default to min-content width and let
       wide children (e.g. <pre> with long file paths) blow out the column. */
    display: grid; grid-template-columns: 220px minmax(0, 1fr);
    gap: 16px; align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}
.settings-row:last-child { border-bottom: 0; }
.settings-label {
    color: var(--text-muted);
    font-size: 12px;
    min-width: 0;
}
.settings-label small { display: block; color: var(--text-ghost); font-weight: 400; margin-top: 2px; word-wrap: break-word; }
.settings-value { font-size: 13px; min-width: 0; }

/* ---------- Dialogs (native <dialog>) ---------- */
dialog {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
    color: var(--text);
    padding: 0;
    max-width: 92vw;
    width: 640px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.55);
}
dialog::backdrop { background: rgba(0,0,0,0.6); }
dialog header.dlg {
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 12px;
    background: var(--surface-2);
}
dialog header.dlg h3 { margin: 0; flex: 1; font-size: 15px; border: 0; padding: 0; color: var(--text); }
dialog .body { padding: 16px 18px; }
dialog .body form.inline { margin: 0; padding: 0; border: 0; background: transparent; }
dialog footer.dlg {
    padding: 12px 18px;
    border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 8px;
    background: var(--surface-2);
}
/* Shared confirm/prompt dialog driven by dlgConfirm()/dlgPrompt(). */
dialog.app-dlg { padding: 18px 20px; width: 480px; }
dialog.app-dlg h3 { margin: 0 0 8px 0; padding: 0; border: 0; font-size: 15px; }
dialog.app-dlg #app-dlg-body { color: var(--text-muted); font-size: 13px; line-height: 1.5; white-space: pre-wrap; }

/* ---------- Disk + pool visualization ---------- */
.disk-card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin: 8px 0;
}
.part-usage { display: inline-flex; gap: 8px; align-items: center; }
.part-usage small { color: var(--text-muted); font-size: 11px; }
.part-bar {
    display: inline-block;
    width: 100px; height: 8px;
    background: var(--surface-2);
    border-radius: 2px;
    overflow: hidden;
}
.part-bar > span { display: block; height: 100%; background: var(--green); }
.part-bar.high > span { background: var(--amber); }
.part-bar.full > span { background: var(--red); }
.metric-bar {
    position: relative;
    display: inline-block;
    width: 80px;
    height: 14px;
    background: var(--surface-2);
    border-radius: 2px;
    overflow: hidden;
    vertical-align: middle;
}
.metric-bar > span {
    display: block;
    height: 100%;
    background: var(--green);
    transition: width 0.3s;
}
.metric-bar.amber > span { background: var(--amber); }
.metric-bar.red > span { background: var(--red); }
.metric-bar > label {
    position: absolute;
    inset: 0;
    color: var(--text);
    font-size: 11px;
    line-height: 14px;
    text-align: center;
    text-shadow: 0 0 2px rgba(0,0,0,0.6);
    pointer-events: none;
}
.iface-card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin: 8px 0;
}
.iface-static label { display: block; margin-top: 8px; }
.iface-static input { width: 100%; }
.live-ip {
    margin: 4px 0 10px 0;
    padding: 6px 10px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    font-size: 13px;
}
.live-ip code { font-weight: 600; }
.live-ip.hint { color: var(--text-muted); font-style: italic; }
.disk-card.system { border-left: 3px solid var(--amber); }
.disk-card.empty  { border-left: 3px solid var(--green); }
.disk-card.inuse  { border-left: 3px solid var(--blue); }
.disk-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.disk-head .name { font-family: "Cascadia Code", monospace; font-size: 13px; font-weight: 600; }
.disk-head .meta { color: var(--text-muted); font-size: 12px; }
.disk-head .right { margin-left: auto; display: flex; gap: 6px; }
.disk-bar {
    height: 8px; background: var(--surface-2); border-radius: 999px;
    overflow: hidden; margin: 8px 0 4px; position: relative;
}
.disk-bar > span {
    display: block; height: 100%; background: var(--main);
}
.disk-bar.full > span { background: var(--red); }
.disk-bar.high > span { background: var(--amber); }
.disk-bar-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); }
.partitions-list { margin: 8px 0 0 0; padding: 0; list-style: none; font-size: 12px; }
.partitions-list li {
    display: grid; grid-template-columns: minmax(150px, 1fr) 80px 90px 110px 1fr;
    gap: 8px; padding: 3px 0; color: var(--text-muted); align-items: center;
}
.partitions-list li code { background: transparent; padding: 0; }
.partitions-list li.system-mount { color: var(--amber); }
.partitions-list li .mount-tag { font-size: 10px; padding: 1px 6px; border-radius: 3px; background: var(--surface-2); }
.partitions-list li.system-mount .mount-tag { background: color-mix(in srgb, var(--amber), transparent 80%); color: var(--amber); }

.dataset-row {
    display: grid; grid-template-columns: 2fr 1fr 1fr 80px;
    gap: 8px; padding: 6px 8px; font-size: 12px;
    border-bottom: 1px solid var(--border);
    align-items: center;
}
.dataset-row:last-child { border-bottom: 0; }
.dataset-row code { background: transparent; padding: 0; }
.dataset-row .indent-1 { padding-left: 14px; }
.dataset-row .indent-2 { padding-left: 28px; }
.dataset-row .indent-3 { padding-left: 42px; }
.dataset-row.snapshot { color: var(--text-muted); font-size: 11px; }

/* ---------- Mode switcher (inside deploy tabs) ---------- */
.mode-switch {
    display: inline-flex; gap: 0;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 3px;
    margin: 12px 0;
}
.mode-switch button {
    background: transparent; border: 0;
    color: var(--text-muted);
    padding: 5px 14px;
    border-radius: 4px;
}
.mode-switch button.primary {
    background: var(--main); color: #fff;
}

/* ---------- Layout helpers ---------- */
.row { display: flex; gap: 12px; align-items: center; }
.row.gap-lg { gap: 20px; }
.row.right { justify-content: flex-end; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.muted-link { color: var(--text-muted); text-decoration: none; font-size: 11px; }
.muted-link:hover { color: var(--text); }
/* Used as a wrapper inside <td>, NOT directly on <td> — applying display:flex to a table cell
   breaks the cell's participation in the row layout (the border-bottom no longer joins the
   horizontal separator across the row, leaving a visible gap between rows in this column). */
td > .row-actions, .row-actions { display: flex; gap: 4px; justify-content: flex-end; flex-wrap: nowrap; white-space: nowrap; }
.row-actions button { padding: 2px 10px; font-size: 11px; }
td.row-actions-cell { white-space: nowrap; }

@media (max-width: 768px) {
    .topbar { flex-wrap: wrap; padding: 10px 12px; }
    .topbar nav { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
    main { padding: 12px; }
    .settings-row { grid-template-columns: 1fr; gap: 4px; }
    form.inline { grid-template-columns: 1fr; }
}
