:root {
  --lime: #D3DF4C;
  --charcoal: #303438;
  --blue: #5C70B6;
  --lavender: #E8EBF3;
  --blue-dark: #4a5c9c;
  --text: #2a2e33;
  --muted: #6b7280;
  --border: #d9dde8;
  --ok: #2e9d5b;
  --warn: #d48a12;
  --bad: #c8423b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(48, 52, 56, .06), 0 2px 8px rgba(48, 52, 56, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Nunito Sans", "Segoe UI", system-ui, -apple-system, sans-serif; color: var(--text); background: var(--lavender); font-size: 14px; }
a { color: var(--blue); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.error { color: var(--bad); background: #fdecea; border: 1px solid #f5c6c2; padding: 8px 10px; border-radius: 8px; margin: 8px 0; }
code, pre, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; }

/* Login */
.login-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--charcoal) 0%, #3d4249 60%, var(--blue) 140%); }
.login-card { background: #fff; padding: 36px 34px; border-radius: 16px; width: 360px; box-shadow: 0 20px 50px rgba(0,0,0,.25); display: flex; flex-direction: column; gap: 10px; border-top: 6px solid var(--lime); }
.login-logo { width: 120px; align-self: center; }
.login-card h1 { margin: 0; text-align: center; font-weight: 800; color: var(--charcoal); }
.login-card p { margin: 0 0 6px; text-align: center; }

/* Forms */
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; color: var(--charcoal); }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(92, 112, 182, .35); border-color: var(--blue); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 600; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.btn { font: inherit; font-weight: 700; border: 1px solid var(--border); background: #fff; color: var(--charcoal); padding: 7px 14px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--blue); }
.btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn.primary:hover { background: var(--blue-dark); }
.btn.lime { background: var(--lime); border-color: var(--lime); color: var(--charcoal); }
.btn.danger { color: var(--bad); border-color: #efc4c1; }
.btn.danger:hover { background: #fdecea; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.block { width: 100%; justify-content: center; padding: 10px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { border: 0; background: transparent; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }

/* Layout */
.app { display: flex; min-height: 100%; }
.sidebar { width: 228px; background: var(--charcoal); color: #e9ebee; display: flex; flex-direction: column; flex-shrink: 0; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand img { width: 62px; background: #fff; border-radius: 8px; padding: 4px 6px; }
.brand span { font-weight: 800; letter-spacing: .3px; }
#nav { display: flex; flex-direction: column; padding: 10px 8px; gap: 2px; flex: 1; overflow-y: auto; }
#nav a { color: #cfd3d8; text-decoration: none; padding: 9px 12px; border-radius: 8px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
#nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
#nav a.active { background: var(--lime); color: var(--charcoal); }
#nav .nav-sep { margin: 10px 12px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: #8a9097; }
.sidebar-foot { padding: 12px 18px; color: #9aa0a6; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-foot a { color: var(--lime); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { background: #fff; display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar h2 { margin: 0; font-size: 20px; font-weight: 800; color: var(--charcoal); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.tenant-picker { flex-direction: row; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.tenant-picker select { padding: 5px 8px; }
.live { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.live.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(46,157,91,.18); }
.live.off { background: #b9bec7; }
.user-menu { position: relative; }
.role-badge { background: var(--lavender); color: var(--blue); border-radius: 20px; padding: 1px 8px; font-size: 11px; font-weight: 800; text-transform: uppercase; }
.dropdown { position: absolute; right: 0; top: 110%; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); min-width: 210px; padding: 6px; z-index: 20; }
.dropdown button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 6px; font: inherit; cursor: pointer; }
.dropdown button:hover { background: var(--lavender); }
.dropdown-head { padding: 6px 10px 8px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.page { padding: 22px 24px 40px; }

/* Cards / tables */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: #fff; border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); border-left: 5px solid var(--blue); }
.stat.lime { border-left-color: var(--lime); }
.stat.charcoal { border-left-color: var(--charcoal); }
.stat .num { font-size: 30px; font-weight: 800; color: var(--charcoal); }
.stat .lbl { color: var(--muted); font-weight: 600; }
.panel { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h3 { margin: 0; font-size: 16px; font-weight: 800; color: var(--charcoal); }
.toolbar { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 2px solid var(--lavender); }
td { padding: 9px 10px; border-bottom: 1px solid #eef0f5; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn { margin-left: 4px; }
.empty { text-align: center; color: var(--muted); padding: 26px; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 700; background: var(--lavender); color: var(--charcoal); }
.pill.ok { background: #e3f4ea; color: var(--ok); }
.pill.bad { background: #fdecea; color: var(--bad); }
.pill.warn { background: #fdf2dd; color: var(--warn); }
.pill.blue { background: #e6e9f6; color: var(--blue); }
.pill.lime { background: #f2f6c9; color: #5f661a; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--ok); } .dot.off { background: #b9bec7; }

/* Devices */
.ws-group { margin-bottom: 18px; }
.ws-group-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.ws-group-head h3 { margin: 0; font-size: 16px; font-weight: 800; }
.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.device { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.device h4 { margin: 0; font-size: 15px; }
.device .meta { display: flex; gap: 6px; flex-wrap: wrap; }
.device .acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }

/* Captures */
.cap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.cap { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; cursor: pointer; border: 1px solid transparent; }
.cap:hover { border-color: var(--blue); }
.cap .thumbs { display: flex; gap: 2px; background: var(--charcoal); height: 120px; align-items: center; justify-content: center; overflow: hidden; }
.cap .thumbs img { height: 120px; object-fit: cover; flex: 1; min-width: 0; }
.cap .thumbs .noimg { color: #aeb3ba; font-size: 12px; }
.cap .info { padding: 9px 11px; }
.cap .info b { display: block; }
.thumb-row { display: flex; gap: 10px; flex-wrap: wrap; }
.thumb-row figure { margin: 0; width: 200px; }
.thumb-row img { width: 200px; border-radius: 8px; background: var(--charcoal); }
.thumb-row figcaption { font-size: 12px; color: var(--muted); word-break: break-all; }

/* Modal / toast */
.modal-backdrop { position: fixed; inset: 0; background: rgba(48, 52, 56, .55); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 14px; width: 640px; max-width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-weight: 800; }
.modal-body { padding: 16px 18px 18px; }
.toast { position: fixed; bottom: 22px; right: 22px; background: var(--charcoal); color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 60; max-width: 420px; border-left: 5px solid var(--lime); }
.toast.bad { border-left-color: var(--bad); }

.code-big { font-family: ui-monospace, Consolas, monospace; font-size: 28px; font-weight: 800; letter-spacing: 2px; background: var(--lavender); color: var(--charcoal); padding: 14px; border-radius: 10px; text-align: center; border: 2px dashed var(--blue); }
.secret-box { display: flex; gap: 8px; align-items: center; }
.secret-box code { flex: 1; background: var(--lavender); padding: 9px 10px; border-radius: 8px; word-break: break-all; }
pre.example { background: #23272b; color: #e8ebf3; padding: 12px 14px; border-radius: 10px; overflow-x: auto; position: relative; margin: 6px 0 16px; }
pre.example .copy { position: absolute; top: 6px; right: 6px; }
ol.steps li { margin-bottom: 6px; }
.checks td:first-child { width: 80px; }
.callout { background: #f6f8d8; border: 1px solid #e4ea9b; border-radius: 10px; padding: 10px 12px; margin: 10px 0; }

/* /downloads page */
body.downloads { background: var(--lavender); }
.dl { max-width: 720px; margin: 40px auto; background: #fff; border-radius: 14px; padding: 28px 32px; box-shadow: var(--shadow); border-top: 6px solid var(--lime); }
.dl-logo { width: 110px; }
.dl li { margin: 8px 0; }

@media (max-width: 860px) {
  .sidebar { width: 72px; }
  .brand span, #nav a span, .sidebar-foot, #nav .nav-sep { display: none; }
  .form-grid { grid-template-columns: 1fr; }
}

.sx-msg{padding:12px 14px;border-radius:10px;background:#f3f4f8;font-size:14px;line-height:1.5}.sx-msg.ok{background:#eef7d6;border:1px solid #c7d94a}.sx-msg.bad{background:#fdecec;border:1px solid #f0b4b4}.sx-msg ul{margin:6px 0 0 18px;padding:0}
