:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --text: #1d2129;
    --muted: #6b7280;
    --border: #e3e5e9;
    --primary: #2563eb;
    --primary-text: #ffffff;
    --ok: #15803d;
    --ok-bg: #dcfce7;
    --off: #6b7280;
    --off-bg: #eceef1;
    --warn: #a16207;
    --warn-bg: #fef3c7;
    --danger: #b91c1c;
    --danger-bg: #fee2e2;
    --info: #1d4ed8;
    --info-bg: #dbeafe;
    --code-bg: #f1f3f5;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111317;
        --surface: #1a1d23;
        --text: #e6e8eb;
        --muted: #9aa1ac;
        --border: #2b2f37;
        --primary: #3b82f6;
        --ok: #4ade80;
        --ok-bg: #12301d;
        --off: #9aa1ac;
        --off-bg: #262a31;
        --warn: #facc15;
        --warn-bg: #3a2f0b;
        --danger: #f87171;
        --danger-bg: #3b1515;
        --info: #93c5fd;
        --info-bg: #172a4a;
        --code-bg: #14161b;
    }
}

* { box-sizing: border-box; }

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(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .75rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.topbar .brand { font-weight: 700; color: var(--text); font-size: 1.1rem; }
.topbar nav { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }

.container { max-width: 1200px; margin: 0 auto; padding: 1.25rem 16px 3rem; }
.page-header { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; flex-wrap: wrap; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.1rem 1.25rem;
    margin-bottom: 1rem;
}
.card.empty { text-align: center; padding: 2.5rem 1rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.grid .card { margin-bottom: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .85rem; }
tbody tr:last-child td { border-bottom: none; }

dl { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; word-break: break-word; }

.badge {
    display: inline-block;
    padding: .1rem .55rem;
    border-radius: 999px;
    font-size: .8rem;
    font-weight: 600;
    background: var(--off-bg);
    color: var(--off);
}
.badge.online, .badge.cmd-completed { background: var(--ok-bg); color: var(--ok); }
.badge.blocked, .badge.cmd-failed { background: var(--danger-bg); color: var(--danger); }
.badge.warn, .badge.cmd-pending { background: var(--warn-bg); color: var(--warn); }
.badge.cmd-sent { background: var(--info-bg); color: var(--info); }

button, .button {
    display: inline-block;
    padding: .45rem .9rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    cursor: pointer;
}
button:hover, .button:hover { border-color: var(--primary); text-decoration: none; }
button.primary, .button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
button.danger { color: var(--danger); }
button.link { border: none; background: none; color: var(--primary); padding: 0; }

input, textarea {
    width: 100%;
    padding: .45rem .6rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}
textarea { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; resize: vertical; }
label { display: block; margin-bottom: .75rem; color: var(--muted); }
label input { margin-top: .25rem; color: var(--text); }

form.inline { display: inline; }
.row { display: flex; gap: .5rem; margin-bottom: .75rem; align-items: center; flex-wrap: wrap; }
.row input { flex: 1; min-width: 160px; }

.commands { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.payload-commands { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.payload-form label { margin-bottom: .35rem; color: var(--text); font-weight: 600; }
.payload-form textarea { margin-bottom: .5rem; }

pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font: .82rem/1.45 ui-monospace, Consolas, monospace;
    max-height: 14rem;
    overflow: auto;
}
pre.copy {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: .75rem;
    margin-bottom: 1rem;
    cursor: copy;
}
pre.copy.copied { border-color: var(--ok); }

.mono { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
.muted { color: var(--muted); }

.alert { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.error { background: var(--danger-bg); color: var(--danger); }
.error-text { color: var(--danger); }

.login { max-width: 360px; margin: 10vh auto 0; }
.login h1 { text-align: center; margin-bottom: 1rem; }
.login button { width: 100%; }

/* Terminal da box: mesmo visual do GNOME Terminal do Ubuntu (paleta Ubuntu, Ubuntu Mono). */
.term-window {
    --term-bg: #300a24;
    --term-fg: #ffffff;
    --term-green: #8ae234;
    --term-blue: #729fcf;
    --term-red: #ef2929;
    --term-dim: #a89aa4;
    width: min(960px, calc(100vw - 32px));
    height: min(600px, calc(100vh - 32px));
    padding: 0;
    border: 1px solid #1c1c1c;
    border-radius: 12px;
    overflow: hidden;
    background: var(--term-bg);
    color: var(--term-fg);
    box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
}
.term-window[open] { display: flex; flex-direction: column; }
.term-window::backdrop { background: rgba(0, 0, 0, .45); }
.term-titlebar {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    height: 46px;
    padding: 0 52px;
    background: #303030;
    border-bottom: 1px solid #1c1c1c;
    color: #ffffff;
    font: 700 .9rem/1 Ubuntu, "Cantarell", system-ui, sans-serif;
    user-select: none;
}
.term-title { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.term-close {
    position: absolute;
    right: 12px;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: #4a4a4a;
    color: #ffffff;
    font-size: 1rem;
    line-height: 24px;
    text-align: center;
}
.term-close:hover { background: #5c5c5c; }
.term-body {
    flex: 1;
    overflow-y: auto;
    padding: 4px 6px;
    font: 1rem/1.25 "Ubuntu Mono", "DejaVu Sans Mono", monospace;
    outline: none;
    cursor: text;
}
.term-output {
    margin: 0;
    padding: 0;
    background: none;
    border: none;
    color: inherit;
    font: inherit;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: none;
    overflow: visible;
}
.term-line { display: flex; align-items: baseline; }
.term-prompt { white-space: pre; }
.term-user { color: var(--term-green); font-weight: 700; }
.term-path { color: var(--term-blue); font-weight: 700; }
.term-error { color: var(--term-red); }
.term-dim { color: var(--term-dim); }
.term-input {
    flex: 1;
    width: auto;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--term-fg);
    font: inherit;
    caret-color: var(--term-fg);
    outline: none;
    box-shadow: none;
}
.term-window.busy .term-line { visibility: hidden; }
