/* ════════════════════════════════════════════════
   КУХТУЙ 2.0 — тёмная премиальная тема
   ════════════════════════════════════════════════ */

:root {
  --bg: #0a0c11;
  --bg2: #0e1118;
  --card: #12151d;
  --card2: #171b25;
  --border: #232836;
  --border-soft: #1c2130;
  --text: #e9ecf3;
  --muted: #8a93a8;
  --faint: #5c6478;
  --accent: #f5a524;
  --accent2: #ff7847;
  --green: #2fd48c;
  --red: #ff6b6b;
  --blue: #5aa9ff;
  --radius: 16px;
  --shadow: 0 12px 32px rgba(0, 0, 0, .38);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display: 'Manrope', var(--font);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font: 14px/1.5 var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 700px at 85% -10%, #1a2030 0%, transparent 60%),
    radial-gradient(900px 600px at -10% 110%, #171c2a 0%, transparent 55%),
    var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(245, 165, 36, .3); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #262c3d; border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }
:focus-visible { outline: 2px solid rgba(245, 165, 36, .6); outline-offset: 2px; }

.hidden { display: none !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; font-variant-numeric: tabular-nums; }

.app { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }

/* ──────── сайдбар ──────── */

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
  padding: 22px 18px;
  border-right: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, .012);
}

.brand { display: flex; gap: 12px; align-items: center; }
.brand-logo {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #221503; font: 800 20px var(--display);
  box-shadow: 0 6px 18px rgba(245, 165, 36, .25);
}
.brand-logo.big { width: 64px; height: 64px; font-size: 30px; border-radius: 18px; margin: 0 auto 18px; }
.brand-name { font: 800 18px var(--display); letter-spacing: .01em; }
.brand-sub { font-size: 11.5px; color: var(--faint); margin-top: 1px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--card); border: 1px solid var(--border-soft); border-radius: 12px; padding: 10px 6px; text-align: center; }
.stat-num { font: 800 18px var(--display); font-variant-numeric: tabular-nums; }
.stat-num.on { color: var(--green); }
.stat-label { font-size: 10.5px; color: var(--faint); margin-top: 2px; text-transform: uppercase; letter-spacing: .06em; }

.side-block { display: flex; flex-direction: column; gap: 8px; }
.conn { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: #4a5164; transition: background .2s; }
.conn-dot.on { background: var(--green); }
.side-hint { font-size: 11.5px; color: var(--faint); line-height: 1.55; margin: 0; }
.side-foot { font-size: 11px; color: var(--faint); margin-top: 8px; }

/* ──────── меню пользователя ──────── */

.user-menu {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; background: var(--card); border: 1px solid var(--border-soft);
  border-radius: 12px;
}
.user-ava {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #221503; font: 800 14px var(--display);
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-weight: 600; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 10px; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; }

/* ──────── шапка ──────── */

.main { padding: 26px 28px; min-width: 0; }

.topbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
h1 { font: 800 22px var(--display); letter-spacing: -.01em; margin: 0; }
.sub { color: var(--faint); font-size: 12px; margin-top: 4px; }
.topbar-right { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

input[type="text"], input[type="password"], textarea {
  width: 100%;
  background: #0d1017; border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 9px 12px;
  font: 500 13px var(--font); outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus { border-color: rgba(245, 165, 36, .55); box-shadow: 0 0 0 3px rgba(245, 165, 36, .12); }
::placeholder { color: var(--faint); }

.search { position: relative; display: flex; align-items: center; }
.search span { position: absolute; left: 11px; display: grid; place-items: center; color: var(--faint); }
.search svg { width: 15px; height: 15px; }
.search input { padding-left: 34px; width: 250px; }

.chips { display: flex; gap: 2px; background: #0d1017; border: 1px solid var(--border); border-radius: 11px; padding: 3px; }
.chip {
  border: none; background: transparent; color: var(--muted);
  font: 600 12.5px var(--font); padding: 7px 13px; border-radius: 8px;
  cursor: pointer; transition: .15s;
}
.chip:hover { color: var(--text); }
.chip.active { background: rgba(245, 165, 36, .14); color: var(--accent); }

/* ──────── кнопки ──────── */

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--card2); color: var(--text);
  font: 600 13px var(--font); cursor: pointer; transition: .15s; text-decoration: none;
}
.btn svg { width: 14px; height: 14px; }
.btn:hover { border-color: #2e3550; transform: translateY(-1px); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border-color: transparent; color: #221503; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 12px; font-size: 12px; border-radius: 8px; }
.btn.full { width: 100%; justify-content: center; }
.btn.danger { color: var(--red); border-color: rgba(255,107,107,.3); }
.btn.danger:hover { background: rgba(255,107,107,.1); }
.btn:disabled { opacity: .45; pointer-events: none; }

.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  display: grid; place-items: center;
  background: transparent; border: 1px solid transparent; color: var(--muted);
  cursor: pointer; transition: .15s;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--card2); color: var(--text); border-color: var(--border); }
.icon-btn.danger:hover { color: var(--red); background: rgba(255, 107, 107, .1); border-color: rgba(255, 107, 107, .25); }

/* ──────── сетка устройств ──────── */

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; padding-bottom: 30px; }

.sk {
  height: 168px; border-radius: var(--radius);
  background: linear-gradient(100deg, var(--card) 40%, #1a1f2b 50%, var(--card) 60%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 13px;
  cursor: pointer; transition: transform .16s, border-color .16s, box-shadow .16s;
}
.card:hover { transform: translateY(-2px); border-color: #2c3450; box-shadow: var(--shadow); }
.card.off { opacity: .82; }

.card-top { display: flex; gap: 12px; align-items: center; }
.card-id { flex: 1; min-width: 0; }
.card-name {
  display: flex; gap: 6px; align-items: center;
  font: 700 14.5px var(--display);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-sub { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.ava {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #2b3350, #1b2136);
  color: #cdd5ea; font: 800 17px var(--display);
}
.card.off .ava { filter: grayscale(.7); }

.tag {
  flex: none; font-size: 10px; font-weight: 600; color: var(--faint);
  border: 1px solid var(--border); padding: 2px 7px; border-radius: 99px;
}

.status { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); flex: none; }

.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot.on { background: var(--green); animation: pulse 2s infinite; }
.dot.off { background: #4a5164; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(47, 212, 140, .45); }
  70%  { box-shadow: 0 0 0 8px rgba(47, 212, 140, 0); }
  100% { box-shadow: 0 0 0 0 rgba(47, 212, 140, 0); }
}

.card-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.mchip {
  display: inline-flex; gap: 6px; align-items: center; max-width: 100%;
  font-size: 11.5px; color: #b9c1d6;
  background: #161a26; border: 1px solid var(--border-soft);
  padding: 4px 9px; border-radius: 8px;
}
.mchip b { color: var(--faint); font-weight: 600; }

.card-owner {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--blue);
  padding-top: 8px; border-top: 1px dashed var(--border-soft);
}
.card-owner svg { width: 12px; height: 12px; }

.card-actions { display: flex; gap: 6px; border-top: 1px solid var(--border-soft); padding-top: 12px; }
.qa {
  width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center;
  background: #141826; border: 1px solid var(--border-soft); color: var(--muted);
  cursor: pointer; transition: .15s;
}
.qa svg { width: 15px; height: 15px; }
.qa:hover { color: var(--accent); border-color: rgba(245, 165, 36, .4); background: rgba(245, 165, 36, .07); }

/* ──────── пустые состояния ──────── */

.empty { display: grid; place-items: center; padding: 60px 20px; }
.empty-card { max-width: 560px; text-align: center; }
.empty-card h2 { font: 800 20px var(--display); margin: 0 0 8px; }
.empty-card p { color: var(--muted); font-size: 13.5px; line-height: 1.6; margin: 0 0 18px; }
.code {
  display: block; text-align: left; white-space: pre;
  background: #0d1017; border: 1px solid var(--border-soft); border-radius: 12px;
  padding: 14px 16px;
  font: 12px/1.8 ui-monospace, Menlo, Consolas, monospace; color: #aab3c8;
}

/* ──────── drawer ──────── */

.backdrop {
  position: fixed; inset: 0; z-index: 35;
  background: rgba(5, 7, 10, .55); backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.backdrop.show { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; right: 0; height: 100%;
  width: min(620px, 100vw); z-index: 40;
  background: var(--bg2); border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  transform: translateX(102%);
  transition: transform .28s cubic-bezier(.4, 0, .2, 1);
}
.drawer.open { transform: none; }

.drawer-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border-soft); flex: none;
}
.drawer-id { flex: 1; min-width: 0; }
.drawer-name { font: 800 17px var(--display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-status { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); margin-top: 3px; }
.drawer-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.drawer-scroll { flex: 1; overflow-y: auto; }

.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 14px; padding: 16px 20px 6px; font-size: 13px; }
.kv-k { color: var(--faint); }
.kv-v { word-break: break-word; }
.kv.big { grid-template-columns: 200px 1fr; padding: 20px; }

.note-card {
  margin: 12px 20px 0; padding: 10px 14px; border-radius: 10px;
  background: rgba(245, 165, 36, .07); border: 1px solid rgba(245, 165, 36, .18);
  font-size: 13px; color: #e8d9bd;
}

.drawer-assign {
  margin: 12px 20px 0; padding: 12px 14px; border-radius: 10px;
  background: rgba(90, 169, 255, .06); border: 1px solid rgba(90, 169, 255, .2);
}
.assign-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.assign-label { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; }
.assign-current { font-size: 13px; color: var(--blue); font-weight: 600; margin-top: 2px; }

.tabs {
  position: sticky; top: 0; z-index: 2;
  display: flex; gap: 4px; padding: 10px 20px 0;
  background: var(--bg2); border-bottom: 1px solid var(--border-soft);
}
.tabs button {
  padding: 10px 13px; margin-bottom: -1px;
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--muted); font: 600 13px var(--font); cursor: pointer; transition: .15s;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

.drawer-tools {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 20px; border-bottom: 1px solid var(--border-soft);
}
.tools-hint { font-size: 11px; color: var(--faint); }

/* ──────── вкладки ──────── */

.tab-tools { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px 8px; }
.count { font-size: 12px; color: var(--muted); }
.tab-search { width: 200px; }

.rows { padding: 4px 12px 24px; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; transition: background .12s; }
.row:hover { background: rgba(255, 255, 255, .03); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-weight: 500; font-size: 13.5px; }
.row-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.row-end { color: var(--muted); font-size: 13px; flex: none; }

.cg { width: 30px; height: 30px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 13px; font-weight: 800; }
.cg.in     { background: rgba(47, 212, 140, .13); color: var(--green); }
.cg.out    { background: rgba(90, 169, 255, .13); color: var(--blue); }
.cg.missed { background: rgba(255, 107, 107, .13); color: var(--red); }
.call-right { text-align: right; font-size: 12.5px; display: flex; flex-direction: column; gap: 2px; flex: none; }

.tab-foot { padding: 10px 20px 24px; color: var(--faint); font-size: 12px; }

.tab-empty { text-align: center; padding: 56px 20px; }
.te-title { font: 700 14px var(--display); }
.te-sub { font-size: 12.5px; margin-top: 6px; color: var(--faint); }

.shots { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; padding: 16px 20px 24px; }
.shot {
  position: relative; margin: 0; aspect-ratio: 9 / 16;
  border-radius: 12px; overflow: hidden; cursor: zoom-in;
  background: #0d1017; border: 1px solid var(--border-soft);
}
.shot img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.shot:hover img { transform: scale(1.04); }
.shot figcaption {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 18px 8px 6px; font-size: 10.5px; color: #dfe3ee;
  background: linear-gradient(transparent, rgba(0, 0, 0, .75));
}

/* ──────── модалка ──────── */

.modal-wrap {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(5, 7, 12, .6); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px;
}
.modal {
  width: min(420px, 100%);
  background: var(--bg2); border: 1px solid var(--border); border-radius: 18px;
  padding: 22px; box-shadow: var(--shadow); animation: pop .2s;
}
.modal.wide { width: min(720px, 100%); }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }
.modal h3 { margin: 0 0 4px; font: 700 16px var(--display); }
.modal-sub { color: var(--muted); font-size: 12.5px; margin: 0 0 16px; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.modal-head { display: flex; justify-content: space-between; align-items: center;
  padding-bottom: 12px; border-bottom: 1px solid var(--border-soft); margin-bottom: 16px; }
.modal-head h3 { margin: 0; }
.modal-body { max-height: 65vh; overflow-y: auto; }

/* ──────── таблица пользователей ──────── */

.users-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 16px; }
.users-table th, .users-table td { padding: 10px 8px; text-align: left;
  border-bottom: 1px solid var(--border-soft); }
.users-table th { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.users-table td { color: var(--text); }
.users-table .user-cell small { color: var(--faint); font-size: 11px; }
.role-pill {
  display: inline-block; padding: 3px 9px; border-radius: 99px;
  font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.role-pill.admin { background: rgba(245,165,36,.15); color: var(--accent); }
.role-pill.user  { background: rgba(90,169,255,.15);  color: var(--blue); }

/* ──────── список назначения ──────── */

.assign-list { display: flex; flex-direction: column; gap: 8px; max-height: 340px; overflow-y: auto; margin-bottom: 12px; }
.assign-item {
  display: flex; gap: 10px; align-items: center; padding: 12px 14px;
  background: var(--card); border: 1px solid var(--border-soft); border-radius: 10px;
  cursor: pointer; transition: .15s;
}
.assign-item:hover { border-color: var(--accent); background: var(--card2); }
.assign-item.current { border-color: var(--green); background: rgba(47,212,140,.06); }
.assign-item.none { opacity: .8; }
.assign-ava {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #2b3350, #1b2136); color: #cdd5ea;
  font: 800 13px var(--display);
}
.assign-item.current .assign-ava { background: linear-gradient(135deg, var(--green), #1fa968); color: #042014; }
.assign-info { flex: 1; min-width: 0; }
.assign-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.assign-sub { font-size: 11px; color: var(--faint); }
.assign-check { color: var(--green); flex: none; }

/* ──────── вход / bootstrap ──────── */

.gate {
  position: fixed; inset: 0; z-index: 80;
  background: var(--bg);
  display: grid; place-items: center; padding: 20px;
}
.gate-card {
  width: min(360px, 100%); text-align: center;
  display: flex; flex-direction: column; gap: 10px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 18px; padding: 28px 24px;
  box-shadow: var(--shadow);
}
.gate-card.wide { width: min(460px, 100%); }
.gate-card h2 { font: 800 22px var(--display); margin: 0; }
.gate-sub { color: var(--muted); font-size: 13px; margin: 0 0 8px; }
.hint { color: var(--faint); font-size: 11.5px; margin: 10px 0 0; line-height: 1.55; }

.login-tabs {
  display: flex; gap: 2px; background: #0d1017; border: 1px solid var(--border);
  border-radius: 11px; padding: 3px; margin: 6px 0 14px;
}
.login-tabs button {
  flex: 1; padding: 8px; background: transparent; border: none; border-radius: 8px;
  color: var(--muted); font: 600 12.5px var(--font); cursor: pointer; transition: .15s;
}
.login-tabs button.active { background: rgba(245,165,36,.14); color: var(--accent); }
.login-pane { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.gate-err {
  color: var(--red); font-size: 12.5px; padding: 10px;
  background: rgba(255,107,107,.08); border-radius: 8px; margin-top: 6px;
}

/* ──────── лайтбокс ──────── */

.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(4, 6, 10, .92); display: grid; place-items: center; }
.lightbox img { max-height: 88vh; max-width: 92vw; border-radius: 12px; box-shadow: var(--shadow); }
.lb-close { position: absolute; top: 18px; right: 18px; color: #fff; }
.lb-dl { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); }

/* ──────── тосты ──────── */

#toasts { position: fixed; right: 20px; bottom: 20px; z-index: 70; display: flex; flex-direction: column; gap: 8px; }
.toast {
  max-width: 340px; padding: 12px 16px; border-radius: 12px;
  background: #161a24; border: 1px solid var(--border); border-left: 3px solid var(--green);
  font-size: 13px; box-shadow: var(--shadow); animation: tin .25s;
}
.toast.warn { border-left-color: var(--accent); }
.toast.err  { border-left-color: var(--red); }
.toast.out  { animation: tout .3s forwards; }
@keyframes tin  { from { opacity: 0; transform: translateY(8px); } }
@keyframes tout { to   { opacity: 0; transform: translateY(6px); } }

/* ──────── ролевые виджеты ──────── */

.admin-only { display: none !important; }
body.is-admin .admin-only { display: inline-flex !important; }
body.is-admin .drawer-assign.admin-only { display: block !important; }

/* ──────── адаптив ──────── */

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .search input { width: 170px; }
}
@media (max-width: 640px) {
  .drawer { width: 100vw; }
  .kv { grid-template-columns: 130px 1fr; }
  .grid { grid-template-columns: 1fr; }
}
