:root {
  --bg: #f6f4f1; --panel: #ffffff; --line: #e4dfd8; --text: #1f1b16; --muted: #6f665c;
  --accent: #b5651d; --accent-ink: #ffffff; --me: #b5651d; --them: #ece7e0; --ok: #2f8f4e; --off: #a8a097;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #171512; --panel: #201d19; --line: #34302a; --text: #f2ede6; --muted: #a39a8f;
          --accent: #d98a3d; --accent-ink: #1a1510; --me: #d98a3d; --them: #2c2823; --ok: #4cc070; --off: #6b645b; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.4 -apple-system, "Segoe UI", system-ui, sans-serif;
       display: grid; grid-template-columns: 280px 1fr; grid-template-rows: 1fr 28px; height: 100vh; }
aside { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
aside header { padding: 16px; font-weight: 650; font-size: 15px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
aside header .logo { width: 28px; height: 28px; border-radius: 7px; }
#search { margin: 10px 12px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); }
#devices { list-style: none; margin: 0; padding: 4px 8px; overflow-y: auto; flex: 1; }
.device { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.device:hover { background: var(--bg); }
.device.active { background: var(--them); }
.device .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device .os { color: var(--muted); font-size: 12px; }
.device .badge { grid-column: 3; background: var(--accent); color: var(--accent-ink); font-size: 11px; border-radius: 10px; padding: 0 7px; }
.dot { width: 9px; height: 9px; border-radius: 50%; }
.dot.on { background: var(--ok); } .dot.off { background: var(--off); }
#empty-devices { color: var(--muted); padding: 16px; }
main { display: flex; flex-direction: column; min-height: 0; }
main header { padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel); display: flex; align-items: center; gap: 12px; }
main header .who { flex: 1; min-width: 0; }
.actions { display: flex; gap: 8px; }
.actions button { padding: 8px 14px; }
button.secondary { background: var(--them); color: var(--text); }
button:disabled { opacity: .45; cursor: default; }
#chat-title { font-weight: 650; font-size: 15px; } #chat-sub { color: var(--muted); font-size: 12px; }
#log { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 8px; }
.placeholder { margin: auto; color: var(--muted); }
.line { display: flex; flex-direction: column; max-width: 70%; }
.line.tech { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 8px 12px; border-radius: 14px; background: var(--them); white-space: pre-wrap; overflow-wrap: anywhere; }
.line.tech .bubble { background: var(--me); color: var(--accent-ink); }
.ts { color: var(--muted); font-size: 11px; margin-top: 2px; }
#composer { display: flex; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); background: var(--panel); }
#composer[hidden] { display: none; }
#text { flex: 1; resize: none; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; }
button { border: 0; border-radius: 10px; padding: 0 16px; background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 600; cursor: pointer; }
footer { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; padding: 0 12px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); background: var(--panel); }

footer { display: flex; align-items: center; gap: 6px; }
footer #status { flex: 1; }
button.link { background: none; color: var(--accent); padding: 4px 6px; font-weight: 600; }
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px; width: min(440px, 92vw); background: var(--panel); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h2 { margin: 0 0 4px; font-size: 17px; }
dialog .hint { margin: 0 0 14px; color: var(--muted); font-size: 12.5px; }
.toggle { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; font-size: 13px; color: var(--muted); }
.toggle strong { color: var(--text); }
.toggle input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.warn { color: #b3261e; font-size: 12.5px; margin: 8px 0 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dialog-actions button { padding: 8px 14px; }
[hidden] { display: none !important; }

/* grouped device list */
.group { list-style: none; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 12px 10px 4px; }
.group.company { color: var(--text); font-size: 12px; text-transform: none; letter-spacing: 0; }
.group.site { padding-top: 4px; font-weight: 600; text-transform: none; letter-spacing: 0; font-size: 11.5px; }
.group .count { font-weight: 500; margin-left: 4px; }
/* dialogs */
dialog.wide { width: min(640px, 94vw); max-height: 86vh; }
.dialog-head { display: flex; align-items: center; gap: 12px; }
.dialog-head h2 { flex: 1; }
.dialog-head button, .small-btn { padding: 6px 12px; }
dialog h3 { font-size: 13px; margin: 18px 0 6px; }
#org-tree { margin: 10px 0 12px; }
.org-row { display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-radius: 8px; }
.org-row:hover { background: var(--bg); }
.org-row .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.org-row .meta { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 6px; }
.org-row.tenant .label { font-weight: 700; }
.org-row.company { margin-left: 18px; } .org-row.company .label { font-weight: 600; }
.org-row.site { margin-left: 36px; }
.org-row button { padding: 4px 9px; font-size: 12px; }
.org-row input { flex: 1; padding: 5px 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); color: var(--text); font: inherit; }
button.danger { background: #b3261e; color: #fff; }
.enrol-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin: 8px 0; }
.enrol-form label, .field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.enrol-form button { padding: 8px 14px; }
select { padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
.key-row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.key-row code { flex: 1; font-size: 18px; letter-spacing: .06em; padding: 10px 12px; background: var(--bg); border: 1px dashed var(--accent); border-radius: 9px; user-select: all; }
.key-row button { padding: 8px 14px; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
ul.plain li span { flex: 1; }
ul.plain li button { padding: 4px 10px; font-size: 12px; }
.dialog-actions.spread { justify-content: space-between; }
.field select { width: 100%; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; }
/* tabs: chat / commands & tools */
#tabs { display: flex; gap: 4px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
#tabs .tab { background: none; color: var(--muted); border-radius: 0; padding: 9px 12px; border-bottom: 2px solid transparent; }
#tabs .tab.active { color: var(--text); border-bottom-color: var(--accent); }
.pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tools-scroll { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.card-head h3 { flex: 1; margin: 0; font-size: 13.5px; }
.card-head select, #tb-kind, #tb-name { padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
#cmd-text { width: 100%; resize: vertical; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text);
            font: 12.5px/1.45 ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.card-foot { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.card-foot .hint { flex: 1; margin: 0; color: var(--muted); font-size: 12px; }
.card-foot button { padding: 7px 18px; }
.tool-row .label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-row .meta, details.run .meta { color: var(--muted); font-size: 12px; margin-left: 8px; flex: none; }
#run-list li { display: block; padding: 0; }
details.run summary { display: flex; align-items: center; gap: 8px; padding: 7px 2px; cursor: pointer; list-style: none; }
details.run summary::-webkit-details-marker { display: none; }
details.run summary .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
.pill { flex: none !important; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 10px; background: var(--them); color: var(--muted); }
.pill.good { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pill.bad { background: color-mix(in srgb, #b3261e 16%, transparent); color: #c4453c; }
.pill.running { color: var(--accent); }
pre.output { margin: 0 0 10px; padding: 10px 12px; max-height: 320px; overflow: auto; border-radius: 8px; background: var(--bg); border: 1px solid var(--line);
             font: 12px/1.45 ui-monospace, "SF Mono", Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
pre.output:empty { display: none; }
#tb-list { margin-top: 10px; }
.run-as { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.run-as select { padding: 5px 8px; }
.run-as .hint { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 12px; }

/* files */
.files { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 12px 20px 8px; gap: 8px; }
.files-bar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
#f-path { flex: 1; min-width: 160px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text);
          font: 12.5px ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.files-scroll { flex: 1; min-height: 0; overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.files-scroll.drop { outline: 2px dashed var(--accent); outline-offset: -4px; }
#f-table { width: 100%; border-collapse: collapse; font-size: 13px; }
#f-table th { position: sticky; top: 0; background: var(--panel); text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
              color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); }
#f-table td { padding: 5px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
#f-table td.name { width: 100%; max-width: 0; overflow: hidden; text-overflow: ellipsis; }
#f-table .num { text-align: right; }
#f-table td.when, #f-table td.num { color: var(--muted); font-size: 12px; }
#f-table td.act { text-align: right; }
#f-table td.act button { padding: 3px 9px; font-size: 12px; margin-left: 4px; }
#f-table tr:hover td { background: color-mix(in srgb, var(--accent) 6%, transparent); }
#f-table a.dir { color: var(--text); font-weight: 600; text-decoration: none; cursor: pointer; }
#f-table a.dir::before { content: "▸ "; color: var(--accent); }
#f-table input { width: 100%; padding: 3px 6px; border: 1px solid var(--accent); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; }
#f-note { padding: 12px; }
#f-note:empty { display: none; }
.files-foot { font-size: 11.5px; }
#f-transfers li { display: flex; align-items: center; gap: 10px; font-size: 12.5px; padding: 4px 0; }
#f-transfers .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#f-transfers progress { width: 160px; accent-color: var(--accent); }
#f-transfers button { padding: 3px 9px; font-size: 12px; }
@media (max-width: 640px) { #f-table td.when, #f-table th:nth-child(3) { display: none; } .files { padding: 10px 12px 6px; } }

/* sign-in */
#signin { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; align-items: center; justify-content: center; overflow-y: auto; padding: 24px 16px; }
.signin-card { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.signin-card form { display: flex; flex-direction: column; gap: 12px; }
.signin-card h1 { font-size: 18px; margin: 6px 0 0; }
.signin-card .hint { margin: 0; color: var(--muted); font-size: 12.5px; }
.signin-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.signin-brand .logo { width: 34px; height: 34px; border-radius: 8px; }
.signin-card input[type=text], .signin-card input[type=password] { padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: var(--text); font: inherit; font-size: 14px; }
.signin-card button[type=submit] { padding: 10px 14px; }
#si-server-fields { display: flex; flex-direction: column; gap: 12px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.qr-row { display: flex; gap: 14px; align-items: center; }
.qr-row img { width: 150px; height: 150px; background: #fff; border-radius: 8px; flex: none; }
.qr-row code { font-size: 12px; word-break: break-all; user-select: all; }
#me { font-weight: 600; color: var(--text); margin-right: 4px; }
/* technicians and audit log */
#tech-name, #audit-filter { padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
label.inline { flex-direction: row !important; align-items: center; gap: 6px !important; padding-bottom: 8px; }
.tech-row .meta { color: var(--muted); font-size: 12px; margin-left: 8px; }
.tag { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 10px; background: var(--them); color: var(--muted); margin-left: 6px; }
.tag.admin { color: var(--accent); } .tag.off { color: #c4453c; }
.audit-scroll { max-height: 60vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
#audit-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
#audit-table th { position: sticky; top: 0; background: var(--panel); text-align: left; font-weight: 600; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
#audit-table td { padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
#audit-table td:first-child { white-space: nowrap; color: var(--muted); }
#audit-table td.subject { color: var(--muted); font-size: 11.5px; }
@media (max-width: 720px) {
  body { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; height: auto; min-height: 100vh; }
  aside { border-right: 0; border-bottom: 1px solid var(--line); max-height: 40vh; }
  main header { flex-wrap: wrap; }
  footer { flex-wrap: wrap; padding: 6px 12px; }
}
#su-step1, #su-step2 { display: flex; flex-direction: column; gap: 12px; }
.signin-card .remember { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: center; font-size: 13px; color: var(--text); cursor: pointer; }
.signin-card .remember .hint { grid-column: 2; font-size: 12px; }
.signin-card #si-remembered .link { padding: 0; font-size: 12.5px; }
.access-box { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 10px; font-size: 13px; }
.access-box .access-mode { display: flex; gap: 14px; flex-wrap: wrap; }
.access-box .access-mode label, .access-tree label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.access-tree { max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 9px; padding: 6px 10px; background: var(--bg); }
.access-tree[hidden] { display: none; }
.access-tree .lvl-company { padding-left: 18px; } .access-tree .lvl-site { padding-left: 36px; }
.access-tree .kind { color: var(--muted); font-size: 11px; }
.tech-row .access { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.tech-row .access-edit { flex-basis: 100%; margin-top: 6px; }
.tech-row { flex-wrap: wrap; }
.org-row select.consent { font-size: 12px; padding: 3px 6px; max-width: 190px; }
#device-consent-box select { width: 100%; }
.pk-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
#si-passkey { width: 100%; margin-top: 6px; }
