:root {
  --bg: #f4f5f7; --panel: #fff; --line: #e3e5ea; --text: #17191f; --muted: #6b7280; --accent: #4f46e5; --accent-2: #eef2ff;
  --ok: #16a34a; --warn: #d97706; --danger: #dc2626; --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: #111827; color: #d1d5db; display: flex; flex-direction: column; padding: 18px 14px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 800; font-size: 18px; color: #fff; letter-spacing: -.02em; padding: 4px 8px 18px; display: flex; gap: 8px; align-items: center; }
.brand-mark { color: #818cf8; letter-spacing: -.3em; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { color: #cbd5e1; padding: 9px 10px; border-radius: 8px; display: block; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); }
.sidebar nav a.active { background: #4f46e5; color: #fff; }
.sidebar-foot { margin-top: auto; font-size: 12px; color: #9ca3af; line-height: 1.6; word-break: break-all; }
.sidebar-foot code { color: #e5e7eb; background: transparent; padding: 0; }
main { padding: 28px 36px; max-width: 1400px; min-width: 0; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.02em; }
h2 { font-size: 16px; margin: 0 0 12px; }
.sub { color: var(--muted); margin-bottom: 20px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.btn { border: 1px solid var(--line); background: #fff; padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #4338ca; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 4px 8px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=url], input[type=number], input[type=password], input[type=email], select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d2fe; border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; min-height: 220px; white-space: pre; tab-size: 2; }
input[type=color] { width: 44px; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.row > .fixed { flex: 0 0 auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #9ca3af; margin-right: 6px; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px #dcfce7; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: box-shadow .15s, transform .15s; }
.tile:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.tile .thumb { aspect-ratio: 16/9; background: #111 center/cover no-repeat; display: grid; place-items: center; font-size: 36px; color: #fff; position: relative; overflow: hidden; }
.tile .thumb iframe { width: 1920px; height: 1080px; transform-origin: 0 0; border: 0; pointer-events: none; position: absolute; left: 0; top: 0; }
.tile .body { padding: 10px 12px; }
.tile .name { font-weight: 600; }
.tile .meta { color: var(--muted); font-size: 12px; margin-top: 2px; display: flex; justify-content: space-between; }
.tile.disabled { opacity: .55; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 99px; font-size: 11.5px; background: var(--accent-2); color: var(--accent); font-weight: 600; }
.split { display: grid; grid-template-columns: 280px 1fr; gap: 18px; align-items: start; }
.list { display: flex; flex-direction: column; gap: 4px; }
.list a { display: block; padding: 9px 12px; border-radius: 8px; color: var(--text); border: 1px solid transparent; }
.list a:hover { background: #f3f4f6; }
.list a.active { background: var(--accent-2); border-color: #c7d2fe; color: var(--accent); }
.items { display: flex; flex-direction: column; gap: 6px; }
.item { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; }
.item .n { flex: 1; }
.item input[type=number] { width: 70px; }
.item .icon { font-size: 18px; width: 26px; text-align: center; }
.editor { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
@media (max-width: 1000px) { .editor { grid-template-columns: 1fr; } .split { grid-template-columns: 1fr; } .app { grid-template-columns: 1fr; } .sidebar { position: static; height: auto; } }
.preview { position: sticky; top: 20px; }
.preview .frame { aspect-ratio: 16/9; background: #000; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.preview .frame.portrait { aspect-ratio: 9/16; max-height: 70vh; margin: 0 auto; }
.preview iframe { width: 100%; height: 100%; border: 0; }
.typegrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.typegrid button { text-align: left; padding: 12px; border: 1px solid var(--line); background: #fff; border-radius: 10px; cursor: pointer; }
.typegrid button:hover { border-color: var(--accent); background: var(--accent-2); }
.typegrid .t-icon { font-size: 22px; }
.typegrid .t-label { font-weight: 600; margin-top: 4px; }
.typegrid .t-desc { color: var(--muted); font-size: 12px; margin-top: 2px; }
.modal { position: fixed; inset: 0; background: rgba(17,24,39,.5); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-card { background: #fff; border-radius: 14px; padding: 22px; width: min(720px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-card h2 { margin-bottom: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60; box-shadow: var(--shadow); }
.toast.err { background: var(--danger); }
.drop { border: 2px dashed #c7d2fe; border-radius: var(--radius); padding: 28px; text-align: center; color: var(--muted); background: #fafafe; margin-bottom: 18px; cursor: pointer; }
.drop.over { background: var(--accent-2); border-color: var(--accent); }
.media-tile .thumb { background-size: contain; background-color: #f3f4f6; }
pre { background: #0f172a; color: #e2e8f0; padding: 14px; border-radius: 8px; overflow: auto; font-size: 12.5px; }
code { font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; background: #f1f5f9; padding: 1px 5px; border-radius: 4px; }
pre code { background: none; padding: 0; }
.api-block { margin-bottom: 26px; }
.api-block h3 { margin: 0 0 6px; font-size: 14px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }
.check label { margin: 0; color: var(--text); font-weight: 400; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
kbd { background: #f1f5f9; border: 1px solid #cbd5e1; border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 12px; }

.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.sep { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.badge.warn { background: #fef3c7; color: #b45309; }
.notice { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.item .grip { cursor: grab; color: #9ca3af; user-select: none; letter-spacing: -2px; }
.item.dragging { opacity: .4; }
.item.over { border-color: var(--accent); box-shadow: 0 -2px 0 var(--accent); }
.steps { padding-left: 20px; line-height: 1.7; margin: 8px 0 16px; }
.steps li { margin-bottom: 4px; }
input[type=search] { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }

.sched summary { cursor: pointer; font-weight: 600; margin-bottom: 12px; }
.daypick { display: flex; gap: 6px; flex-wrap: wrap; }
.daychip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 99px; padding: 4px 10px; font-size: 12.5px; color: var(--text); cursor: pointer; margin: 0; }
.daychip:has(input:checked) { background: var(--accent-2); border-color: #c7d2fe; color: var(--accent); }
.daychip input { width: auto; margin: 0; }
input[type=time], input[type=date] { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; }
.sidebar-foot .lang { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; color: #9ca3af; font-size: 12px; }
.sidebar-foot .lang select { width: auto; padding: 3px 6px; font-size: 12px; background: #1f2937; color: #e5e7eb; border-color: #374151; }
.card:has(> table) { overflow-x: auto; }
table select { min-width: 130px; }
table input[type=text] { min-width: 150px; }

/* auth + users + activity */
.auth-wrap { min-height: 80vh; display: grid; place-items: center; }
.auth-card { width: min(440px, 100%); padding: 28px; }
.auth-card .brand.dark { color: var(--text); padding: 0 0 16px; }
.auth-card h1 { margin-bottom: 6px; }
.auth-card form .btn { width: 100%; margin-top: 6px; padding: 10px; }
.whoami { margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; color: #9ca3af; }
.whoami .tenant-row select { width: 100%; background: #1f2937; color: #e5e7eb; border-color: #374151; font-size: 13px; }
.whoami .user-row { margin-top: 8px; line-height: 1.8; }
.whoami a { color: #a5b4fc; }
.chip { display: inline-block; color: #fff; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; line-height: 1.6; white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.who { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.tile .meta .who { font-size: 11px; }
.permgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.permgroup { border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.permgroup-title { font-weight: 600; margin-bottom: 6px; text-transform: capitalize; }
.permgroup .check { margin: 4px 0; font-size: 13px; }
table.activity td { vertical-align: top; }
.act { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; background: #eef2ff; color: #3730a3; white-space: nowrap; }
.act-delete, .act-remove, .act-disconnect { background: #fee2e2; color: #991b1b; }
.act-create, .act-add, .act-connect, .act-pair, .act-upload { background: #dcfce7; color: #166534; }
.act-command { background: #fef3c7; color: #92400e; }
.scr { display: inline-block; background: #f3f4f6; border-radius: 6px; padding: 1px 6px; margin: 1px 2px 1px 0; color: var(--text); }
.changes summary { cursor: pointer; color: var(--accent); }
.changes table td { padding: 2px 6px; vertical-align: top; max-width: 260px; overflow-wrap: anywhere; }
.split.wide { grid-template-columns: minmax(320px, 1fr) 1.3fr; }
.onboarding { margin-top: 18px; border-color: #c7d2fe; background: #f5f7ff; }

.auth-alt { margin-top: 14px; text-align: center; }
.banner { background: #fef3c7; color: #92400e; border-bottom: 1px solid #fde68a; padding: 8px 36px; font-size: 13px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat-v { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.stat-l { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.stat-s { color: var(--muted); font-size: 11.5px; margin-top: 4px; }
.tabs .btn { padding: 5px 10px; }
.app { grid-template-rows: auto 1fr; }
.app > .sidebar { grid-row: 1 / span 2; }
