:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1e222c; --border: #2a2f3a;
  --text: #e6e9ef; --muted: #8b93a7; --accent: #6d5efc; --accent2: #5648e0;
  --ok: #3ecf8e; --err: #ff5d6c; --warn: #ffb454; --req: #58a6ff;
  --radius: 12px; font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-family: -apple-system, "Segoe UI", Roboto, Inter, system-ui, sans-serif; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }
a { color: var(--accent); }

/* ---- Login ---- */
.login-wrap { display: grid; place-items: center; height: 100vh; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; width: 320px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; background: var(--panel2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }

.btn { background: var(--accent); color: #fff; border: none; padding: 10px 16px; border-radius: 8px; font-weight: 600; }
.btn:hover { background: var(--accent2); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 7px; }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn.ghost:hover { border-color: var(--accent); }
.btn.danger { background: transparent; border: 1px solid var(--err); color: var(--err); }
.btn.danger:hover { background: rgba(255,93,108,.1); }
.btn:disabled { opacity: .5; cursor: default; }

/* ---- Layout ---- */
.layout { display: grid; grid-template-columns: 230px 1fr; height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 18px 12px; }
.brand { font-weight: 800; font-size: 18px; padding: 6px 10px 18px; display: flex; align-items: center; gap: 8px; }
.brand .logo { width: 26px; height: 26px; background: var(--accent); border-radius: 7px; display: grid; place-items: center; color: #fff; font-weight: 800; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--panel2); color: var(--text); }
.nav a.active { background: var(--accent); color: #fff; }
.nav .badge { margin-left: auto; background: var(--err); color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 10px; }
.userbox { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 8px; }
.userbox .u { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; }
.userbox .u:hover { background: var(--panel2); }
.userbox .avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent2); display: grid; place-items: center; font-weight: 700; }
.userbox .uname { font-size: 13px; } .userbox .urole { font-size: 11px; color: var(--muted); }

.main { overflow: auto; padding: 28px 32px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.page-head h2 { margin: 0; font-size: 24px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ---- Cards / grid ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card h3 { margin: 0 0 6px; font-size: 16px; }
.card .meta { color: var(--muted); font-size: 13px; }
.card .row { display: flex; gap: 8px; margin-top: 12px; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.table tr:hover td { background: var(--panel); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.pill.on { background: rgba(62,207,142,.15); color: var(--ok); }
.pill.off { background: rgba(139,147,167,.15); color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.lvl { font-weight: 700; font-size: 12px; }
.lvl.success { color: var(--ok); } .lvl.error { color: var(--err); }
.lvl.info { color: var(--text); } .lvl.request { color: var(--req); }

.toolbar { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 60px 0; }

.banner { background: linear-gradient(90deg, rgba(109,94,252,.18), rgba(109,94,252,.04)); border: 1px solid var(--accent); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 20px; }

/* ---- Modal ---- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; width: 420px; max-width: 92vw; max-height: 88vh; overflow: auto; }
.modal h3 { margin: 0 0 16px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ---- Gallery ---- */
.thumb { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; background: #000; display: block; }
.media-badge { font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--panel2); color: var(--muted); }

/* ---- Toast ---- */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast { background: var(--panel2); border: 1px solid var(--border); border-left: 3px solid var(--accent); padding: 12px 16px; border-radius: 8px; min-width: 220px; animation: slidein .2s; }
.toast.error { border-left-color: var(--err); }
.toast.success { border-left-color: var(--ok); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }

.code-badge { font-family: ui-monospace, monospace; font-size: 20px; letter-spacing: 3px; background: var(--panel2); padding: 4px 12px; border-radius: 8px; }
.schedule-item { display: flex; align-items: center; gap: 12px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: var(--panel2); }

/* ---- Fleet (Точки) ---- */
.fleet-group { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px; overflow: hidden; background: var(--panel); }
.fleet-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; cursor: pointer; user-select: none; background: var(--panel2); }
.fleet-head:hover { background: #222634; }
.fleet-caret { color: var(--muted); width: 14px; }
.fleet-title { font-weight: 700; font-size: 16px; }
.fleet-body { padding: 6px 10px 10px; }
.fleet-device { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-top: 1px solid var(--border); }
.fleet-device:first-child { border-top: none; }
.fleet-name { font-weight: 600; min-width: 140px; }
.fleet-cat { font-size: 13px; min-width: 90px; }

/* ---- Device panel ---- */
.fleet-link { color: var(--text); text-decoration: none; border-bottom: 1px dashed var(--muted); cursor: pointer; }
.fleet-link:hover { color: var(--accent); border-color: var(--accent); }
.panel-meta { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 13px; }
.panel-h { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.panel-row { display: flex; gap: 10px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.shot-wrap { background: #000; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.shot { width: 100%; display: block; max-height: 320px; object-fit: contain; }

/* ---- File picker (schedule slideshow) ---- */
.file-picklist { max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 6px; }
.file-pick { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 6px; cursor: pointer; }
.file-pick:hover { background: var(--panel2); }

/* ---- Tile picker (preview grid) ---- */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; max-height: 340px; overflow-y: auto; padding: 4px; border: 1px solid var(--border); border-radius: 10px; }
.tile { position: relative; border: 2px solid var(--border); border-radius: 10px; overflow: hidden; cursor: pointer; background: #000; transition: border-color .12s; }
.tile:hover { border-color: var(--muted); }
.tile.sel { border-color: var(--accent); }
.tile-thumb { width: 100%; aspect-ratio: 1/1; object-fit: cover; display: block; background: #000; }
.tile-num { position: absolute; top: 6px; left: 6px; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 13px; font-weight: 700; align-items: center; justify-content: center; }
.tile-kind { position: absolute; top: 6px; right: 6px; font-size: 10px; padding: 1px 6px; border-radius: 6px; background: rgba(0,0,0,.65); color: #fff; }
.tile-name { font-size: 11px; padding: 5px 6px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--panel2); }

/* ---- Gallery folders ---- */
.folder-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 18px; }
.folder-chip { display: inline-flex; align-items: center; gap: 7px; padding: 7px 14px; border-radius: 20px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font-weight: 500; }
.folder-chip:hover { border-color: var(--accent); }
.folder-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.folder-count { font-size: 11px; background: rgba(255,255,255,.18); padding: 0 7px; border-radius: 10px; }
.folder-chip:not(.active) .folder-count { background: var(--panel2); color: var(--muted); }

/* ---- Lightbox (gallery preview) ---- */
.lb-bg { position: fixed; inset: 0; background: rgba(0,0,0,.92); display: grid; place-items: center; z-index: 200; padding: 2vmin; }
.lb-media { max-width: 96vw; max-height: 92vh; object-fit: contain; border-radius: 8px; box-shadow: 0 10px 60px rgba(0,0,0,.6); }
.lb-close { position: fixed; top: 18px; right: 22px; width: 44px; height: 44px; border-radius: 50%; border: none; background: rgba(255,255,255,.12); color: #fff; font-size: 20px; cursor: pointer; }
.lb-close:hover { background: rgba(255,255,255,.25); }
.lb-name { position: fixed; bottom: 18px; left: 0; right: 0; text-align: center; color: #fff; font-size: 14px; opacity: .85; }

/* ---- Tile picker: folder tiles ---- */
.tile-folder { background: var(--panel2); }
.tile-folderico { width: 100%; aspect-ratio: 1/1; display: grid; place-items: center; font-size: 46px; background: var(--panel); }

/* ---- Scrollbars in UI style ---- */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }

/* ---- Custom styled dropdown ---- */
.sel { position: relative; display: inline-block; }
.sel-btn { display: inline-flex; align-items: center; gap: 10px; min-width: 150px; justify-content: space-between; padding: 9px 14px; background: var(--panel2); border: 1px solid var(--border); border-radius: 9px; color: var(--text); font-weight: 500; }
.sel-btn:hover { border-color: var(--accent); }
.sel-caret { color: var(--muted); font-size: 11px; transition: transform .15s; }
.sel.open .sel-caret { transform: rotate(180deg); }
.sel-menu { position: absolute; top: calc(100% + 6px); right: 0; min-width: 100%; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 6px; box-shadow: 0 12px 34px rgba(0,0,0,.5); z-index: 40; display: none; max-height: 320px; overflow-y: auto; }
.sel.open .sel-menu { display: block; }
.sel-item { padding: 9px 12px; border-radius: 7px; cursor: pointer; white-space: nowrap; font-size: 14px; }
.sel-item:hover { background: var(--panel2); }
.sel-item.active { background: var(--accent); color: #fff; }
