:root { color-scheme: dark; }
* { box-sizing: border-box; margin: 0; }
body {
  font: 14px/1.5 system-ui, -apple-system, sans-serif;
  background: #0d1117; color: #e6edf3;
}
a { color: #58a6ff; }
.hidden { display: none !important; }
.muted { color: #8b949e; }
.small { font-size: 12px; }

/* ---- login ---- */
.center-screen { min-height: 100vh; display: grid; place-items: center; }
.card {
  background: #161b22; border: 1px solid #30363d; border-radius: 12px;
  padding: 32px; width: min(380px, 90vw);
}
.card h1 { font-size: 18px; margin-bottom: 20px; }
label { display: block; font-size: 13px; color: #8b949e; margin: 14px 0 4px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid #30363d;
  background: #0d1117; color: inherit; font-size: 14px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 1px solid #58a6ff; }
.err { color: #f85149; font-size: 13px; margin-top: 12px; min-height: 1.2em; }
.qr { text-align: center; margin: 14px 0; }
.qr img { width: 180px; border-radius: 8px; background: #fff; padding: 8px; }
code { font-size: 12px; word-break: break-all; color: #8b949e; }

.btn {
  padding: 8px 14px; border: 1px solid #30363d; border-radius: 8px;
  background: #21262d; color: #e6edf3; font-size: 13px; font-weight: 500; cursor: pointer;
}
.btn:hover { background: #30363d; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: #238636; border-color: #2ea043; color: #fff; }
.btn.primary:hover { background: #2ea043; }
.btn.danger { background: #da3633; border-color: #f85149; color: #fff; }
.btn.danger:hover { background: #f85149; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.ghost { background: transparent; }
form button[type=submit], form button:not([type]) {
  width: 100%; margin-top: 20px; padding: 11px; border: 0; border-radius: 8px;
  background: #238636; color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
}

/* ---- app shell ---- */
#app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
#sidebar {
  background: #161b22; border-right: 1px solid #30363d; padding: 20px 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
#sidebar .brand { font-weight: 700; font-size: 16px; padding: 0 20px 16px; }
#sidebar a {
  display: block; padding: 9px 20px; color: #c9d1d9; text-decoration: none; font-size: 13px;
  border-left: 3px solid transparent;
}
#sidebar a:hover { background: #1c2128; }
#sidebar a.active { background: #1c2128; border-left-color: #58a6ff; color: #58a6ff; font-weight: 600; }
.sidebar-spacer { flex: 1; }
.sidebar-footer { padding: 12px 20px; border-top: 1px solid #30363d; }
.sidebar-footer .btn { width: 100%; margin-top: 8px; }

#view { padding: 28px 32px; overflow-x: auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.page-head h2 { font-size: 20px; }
.page-actions { display: flex; gap: 8px; }

/* ---- stat cards ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-top: 8px; }
.stat-card { background: #161b22; border: 1px solid #30363d; border-radius: 10px; padding: 16px; }
.stat-card.stat-warn { border-color: #d29922; }
.stat-value { font-size: 26px; font-weight: 700; }
.stat-label { color: #8b949e; font-size: 12px; margin-top: 4px; }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; background: #161b22; border: 1px solid #30363d; border-radius: 10px; overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid #21262d; font-size: 13px; white-space: nowrap; }
th { color: #8b949e; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #1c2128; }
.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; text-transform: capitalize; background: #30363d; }
.badge.ok { background: #033a16; color: #3fb950; }
.badge.warn { background: #3d2d00; color: #d29922; }
.badge.err { background: #3c1618; color: #f85149; }
.badge.off { background: #21262d; color: #8b949e; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.dot.ok { background: #3fb950; }
.dot.off { background: #8b949e; }

/* ---- toasts ---- */
#toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: #21262d; border: 1px solid #30363d; border-left: 3px solid #58a6ff;
  padding: 10px 16px; border-radius: 8px; font-size: 13px; opacity: 0; transform: translateY(6px);
  transition: opacity .2s, transform .2s; max-width: 320px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { border-left-color: #f85149; }
.toast.ok { border-left-color: #3fb950; }

/* ---- modal ---- */
#modal-root.hidden { display: none; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(1,4,9,.7); display: grid; place-items: center; z-index: 200;
}
.modal {
  background: #161b22; border: 1px solid #30363d; border-radius: 12px; padding: 22px;
  width: min(480px, 92vw); max-height: 86vh; overflow: auto;
}
.modal.wide { width: min(760px, 94vw); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { font-size: 16px; }
.modal-close { background: none; border: none; color: #8b949e; font-size: 20px; cursor: pointer; line-height: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.token-box {
  background: #0d1117; border: 1px solid #30363d; border-radius: 8px; padding: 10px 12px;
  font-family: monospace; font-size: 13px; word-break: break-all; margin: 10px 0;
}

/* ---- terminal / console ---- */
.term-container { width: 100%; height: 60vh; background: #0d1117; border-radius: 8px; overflow: hidden; padding: 6px; }
.console-log {
  background: #0d1117; border: 1px solid #30363d; border-radius: 8px; padding: 10px 12px;
  height: 50vh; overflow-y: auto; white-space: pre-wrap; font-family: monospace; font-size: 12.5px;
}
.console-input-row { display: flex; gap: 8px; margin-top: 10px; }
.console-input-row input { flex: 1; font-family: monospace; }

/* ---- file manager ---- */
.file-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.file-toolbar .spacer { flex: 1; }
#fm-breadcrumb a { margin-right: 2px; }
.file-list { border: 1px solid #30363d; border-radius: 8px; overflow: hidden; max-height: 50vh; overflow-y: auto; }
.file-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid #21262d; font-size: 13px; }
.file-row:last-child { border-bottom: none; }
.file-row:hover { background: #1c2128; }
.file-name { flex: 1; cursor: pointer; overflow: hidden; text-overflow: ellipsis; }
.file-size { color: #8b949e; font-size: 12px; width: 80px; text-align: right; }
.file-row-actions { display: flex; gap: 6px; }

.page { max-width: 1400px; }
.empty-state { color: #8b949e; padding: 30px; text-align: center; }
pre.json-detail { background: #0d1117; border: 1px solid #30363d; border-radius: 6px; padding: 8px; font-size: 11px; max-width: 320px; overflow: auto; white-space: pre-wrap; }
