:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel2: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --green: #4ade80;
  --red: #f87171;
  --orange: #fbbf24;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
}

/* ---------- Pages auth ---------- */
.auth-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 1rem;
}
.auth-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 2rem; width: 100%; max-width: 400px;
}
.auth-logo { display: block; width: 56px; height: 56px; margin: 0 auto .8rem; }
.brand { display: flex; align-items: center; gap: .55rem; }
.brand .logo { width: 30px; height: 30px; }
.auth-card h1 { font-size: 1.5rem; margin-bottom: .25rem; }

/* MFA setup steps */
.mfa-steps { list-style: none; counter-reset: step; margin: 1rem 0; padding: 0; }
.mfa-steps li {
  position: relative; padding: 0 0 .7rem 2.2rem; color: var(--text);
  font-size: .9rem; line-height: 1.4;
}
.mfa-steps li::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 0; top: -2px;
  width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--accent); color: #082f49;
  font-weight: 700; font-size: .8rem;
  display: flex; align-items: center; justify-content: center;
}
.auth-card .sub { color: var(--muted); font-size: .9rem; margin-bottom: 1.5rem; }
.auth-card label { display: block; font-size: .85rem; color: var(--muted); margin: .8rem 0 .25rem; }
.auth-card img.qr { display: block; margin: 1rem auto; border-radius: 8px; background: #fff; padding: 8px; }
.secret { font-family: monospace; background: var(--panel2); padding: .4rem .6rem; border-radius: 6px; word-break: break-all; font-size: .8rem; }

input, select {
  width: 100%; padding: .6rem .8rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel2);
  color: var(--text); font-size: .95rem;
}
input:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }

button {
  border: none; border-radius: 8px; padding: .6rem 1rem;
  font-size: .9rem; font-weight: 600; cursor: pointer;
  background: var(--accent); color: #082f49;
}
button:hover { filter: brightness(1.1); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.full { width: 100%; margin-top: 1.2rem; }
button.secondary { background: var(--panel2); color: var(--text); border: 1px solid var(--border); }
button.danger { background: transparent; color: var(--red); border: 1px solid var(--red); }
button.small { padding: .35rem .7rem; font-size: .8rem; }

.error-msg { color: var(--red); font-size: .85rem; margin-top: .8rem; min-height: 1.2em; }
.link-sm { display: inline-block; margin-top: .5rem; color: var(--accent); font-size: .8rem; text-decoration: none; }
.link-sm:hover { text-decoration: underline; }

/* ---------- Dashboard ---------- */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 2rem; background: var(--panel); border-bottom: 1px solid var(--border);
}
header h1 { font-size: 1.25rem; }
header h1 span { color: var(--accent); }
header .actions { display: flex; gap: .6rem; align-items: center; }

main { padding: 1.5rem 2rem; max-width: 1300px; margin: 0 auto; }

.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 1.2rem; align-items: center; }
.toolbar select { width: auto; }

table {
  width: 100%; table-layout: fixed; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
}
th, td {
  padding: .7rem .9rem; text-align: left; font-size: .9rem;
  vertical-align: middle; overflow-wrap: anywhere;
}
th { background: var(--panel2); color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; }
tr + tr td { border-top: 1px solid var(--border); }
td .host { color: var(--muted); font-size: .8rem; }
td .badge { white-space: nowrap; }
/* Fixed column widths so content never shifts the layout */
col.c-machine { width: 19%; }
col.c-os      { width: 24%; }
col.c-updates { width: 11%; }
col.c-status  { width: 9%; }
col.c-last    { width: 15%; }
col.c-actions { width: 22%; }

.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge.success { background: rgba(74, 222, 128, .15); color: var(--green); }
.badge.error { background: rgba(248, 113, 113, .15); color: var(--red); }
.badge.running { background: rgba(251, 191, 36, .15); color: var(--orange); }
.badge.idle { background: var(--panel2); color: var(--muted); }

.row-actions { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.row-actions .small { white-space: nowrap; }

/* ---------- Docked console ---------- */
.console-dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; flex-direction: column;
  background: #0b1220; border-top: 1px solid var(--border);
  box-shadow: 0 -6px 22px rgba(0, 0, 0, .4);
}
.console-resize { height: 6px; cursor: ns-resize; background: transparent; flex: 0 0 auto; }
.console-resize:hover { background: var(--accent); opacity: .45; }
.console-bar {
  display: flex; align-items: center; gap: .5rem; flex: 0 0 auto;
  padding: .3rem .8rem; background: var(--panel2); border-bottom: 1px solid var(--border);
  font-size: .8rem; color: var(--muted);
}
.console-title { font-weight: 600; letter-spacing: .3px; color: var(--text); }
.console-title span { color: var(--accent); }
#console {
  height: 260px; overflow-y: auto; padding: .8rem 1rem; background: #020617;
  font-family: "Cascadia Code", Consolas, monospace; font-size: .8rem; line-height: 1.5;
}
.console-dock.collapsed .console-resize,
.console-dock.collapsed #console { display: none; }
#console .m { color: var(--accent); font-weight: 600; }
#console .ok { color: var(--green); }
#console .ko { color: var(--red); }

/* ---------- Modal ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .6);
  display: none; align-items: center; justify-content: center; z-index: 10;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 1.5rem; width: 100%; max-width: 460px;
}
.modal h2 { font-size: 1.1rem; margin-bottom: 1rem; }
.modal label { display: block; font-size: .85rem; color: var(--muted); margin: .7rem 0 .25rem; }
.modal .btns { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1.3rem; }
.modal pre { background: var(--panel2); padding: .7rem; border-radius: 8px; font-size: .75rem; white-space: pre-wrap; word-break: break-all; }

.empty { text-align: center; color: var(--muted); padding: 2rem; }

/* Current user + users management */
.current-user { color: var(--muted); font-size: .85rem; margin-right: .3rem; }
.current-user b { color: var(--text); }

.users-table { margin-bottom: 1rem; }
.users-table th, .users-table td { padding: .5rem .6rem; font-size: .85rem; }
.u-subtitle { font-size: .95rem; margin: .8rem 0 .5rem; }
.u-add-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.u-add-form input[type=text], .u-add-form #u-name { flex: 1; min-width: 140px; }
.u-admin-check { display: flex; align-items: center; gap: .35rem; color: var(--muted); font-size: .85rem; white-space: nowrap; }
.u-admin-check input { width: auto; }
.invite-box { margin-top: 1rem; background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; padding: .8rem; }
.invite-box pre { background: #020617; padding: .6rem; border-radius: 6px; font-size: .78rem; white-space: pre-wrap; word-break: break-all; margin: .5rem 0; }

/* Recovery codes panel (MFA setup) */
.recovery-panel { margin-top: 1rem; }
.recovery-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: .5rem;
  background: #020617; border: 1px solid var(--border); border-radius: 8px;
  padding: .9rem; margin: .8rem 0; font-family: monospace; font-size: .95rem;
}
.recovery-grid span { text-align: center; letter-spacing: 1px; }
.recovery-warn { color: var(--orange); font-size: .82rem; }
