:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f1f3f6;
  --border: #e2e5ea;
  --text: #1b1f24;
  --muted: #69717d;
  --accent: #1f8a66;
  --accent-2: #2ea078;
  --accent-soft: #e3f4ed;
  --danger: #c8412f;
  --danger-soft: #fbe9e6;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --online: #2ea078;
  --offline: #a3aab4;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1215;
    --panel: #171b20;
    --panel-2: #1e232a;
    --border: #2a3038;
    --text: #e6e9ed;
    --muted: #8d96a3;
    --accent: #3cc08f;
    --accent-2: #2ea078;
    --accent-soft: #15302a;
    --danger: #ec6a57;
    --danger-soft: #3a1d19;
    --warn: #e2a64a;
    --warn-soft: #3a2d17;
    --offline: #59616c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.hidden { display: none !important; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- layout */
.shell { display: grid; grid-template-columns: 220px 1fr; height: 100vh; }
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 16px 12px;
  gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 700; font-size: 17px; }
.brand img { width: 26px; height: 26px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; color: var(--text);
  font-weight: 500;
}
.nav a:hover { background: var(--panel-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar .spacer { flex: 1; }
.sidebar .me { padding: 10px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.main { overflow: auto; min-width: 0; }
.page { padding: 24px 28px; max-width: 1280px; margin: 0 auto; }
.page.wide { max-width: none; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

/* ---------- controls */
button, .btn {
  font: inherit; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text);
  cursor: pointer; white-space: nowrap;
  text-decoration: none !important;
}
button:hover, .btn:hover { background: var(--panel-2); }
button:disabled { opacity: .5; cursor: default; }
button.primary, .btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
button.primary:hover, .btn.primary:hover { filter: brightness(1.06); background: var(--accent-2); }
button.danger { color: var(--danger); }
button.danger:hover { background: var(--danger-soft); }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--panel-2); }
button.icon { width: 32px; padding: 0; }
button svg, .btn svg { width: 16px; height: 16px; }
input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  height: 32px; padding: 0 10px; min-width: 0;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: 13px; }
label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
input[type=checkbox] { height: auto; width: 15px; height: 15px; accent-color: var(--accent-2); }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .card-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.card .card-body { padding: 16px; }
.grid { display: grid; gap: 16px; }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 500; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }
.badge.ok { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--offline); flex: none; }
.dot.on { background: var(--online); box-shadow: 0 0 0 3px var(--accent-soft); }

.notice { padding: 10px 12px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--border); font-size: 13px; }
.notice.warn { background: var(--warn-soft); border-color: transparent; color: var(--text); }
.notice.ok { background: var(--accent-soft); border-color: transparent; }

.codebox { position: relative; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 44px 10px 12px; font-family: var(--mono); font-size: 12px; word-break: break-all; max-height: 140px; overflow: auto; }
.codebox button { position: absolute; top: 6px; right: 6px; height: 28px; width: 28px; padding: 0; }

/* ---------- tables */
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.list td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list tr:last-child td { border-bottom: none; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: var(--panel-2); }
table.list tr.sel td { background: var(--accent-soft); }

/* ---------- auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: 100%; max-width: 380px; padding: 28px; }
.auth .brand { justify-content: center; padding-bottom: 6px; font-size: 22px; }

/* ---------- device page */
.device-head { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 14px; }
.device-head .title { display: flex; align-items: center; gap: 10px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.tabs a svg { width: 16px; height: 16px; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.bar { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--accent-2); }

/* ---------- desktop viewer */
.toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 8px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
.toolbar select { height: 30px; }
.toolbar .sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.viewport {
  position: relative; background: #0b0d10; border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  height: calc(100vh - 250px); min-height: 360px;
  overflow: auto; display: flex;
}
.viewport canvas { margin: auto; display: block; outline: none; cursor: default; image-rendering: auto; }
.viewport.fit canvas { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewport:fullscreen { height: 100vh; border: none; border-radius: 0; }
.viewport .overlay { position: absolute; inset: 0; display: grid; place-items: center; color: #c9ced6; text-align: center; padding: 20px; pointer-events: none; }
.viewport .overlay .msg { background: rgba(20, 24, 30, .85); padding: 14px 18px; border-radius: 10px; max-width: 420px; pointer-events: auto; }
.stats { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }

.term-wrap { background: #0b0d10; border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius) var(--radius); height: calc(100vh - 250px); min-height: 320px; padding: 8px; }
.term-wrap .xterm { height: 100%; }

/* ---------- files */
.pathbar { display: flex; gap: 6px; align-items: center; }
.pathbar input { flex: 1; font-family: var(--mono); font-size: 12.5px; }
.files-table { max-height: calc(100vh - 300px); overflow: auto; position: relative; }
.files-table.drop { outline: 2px dashed var(--accent); outline-offset: -6px; }
.fname { display: flex; align-items: center; gap: 8px; }
.fname svg { width: 17px; height: 17px; flex: none; color: var(--muted); }
.fname svg.dir { color: #d9a23a; }
.uploads { display: flex; flex-direction: column; gap: 6px; }

/* ---------- modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(10, 12, 16, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; width: 100%; max-width: 460px; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
.modal .modal-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.modal .modal-foot { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--accent-2); border-radius: 8px; padding: 10px 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); max-width: 380px; animation: tin .18s ease-out; }
.toast.err { border-left-color: var(--danger); }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; opacity: .5; margin-bottom: 8px; }
.qr svg { width: 180px; height: 180px; background: #fff; border-radius: 8px; padding: 6px; }

.menu { position: relative; }
.menu .menu-list { position: absolute; right: 0; top: 36px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 30px rgba(0, 0, 0, .2); padding: 4px; z-index: 30; min-width: 190px; }
.menu .menu-list.left { left: 0; right: auto; }
.menu .menu-list button { width: 100%; justify-content: flex-start; border: none; background: transparent; height: 30px; }
.menu .menu-list button:hover { background: var(--panel-2); }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { flex-direction: row; align-items: center; padding: 8px 12px; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .brand { padding: 0 8px 0 0; }
  .nav { display: flex; }
  .nav a span { display: none; }
  .sidebar .spacer, .sidebar .me .who { display: none; }
  .sidebar .me { border: none; padding: 0; }
  .page { padding: 16px; }
  .hide-sm { display: none; }
}
