/* Inguumel Camera — нийтлэг загвар */
:root {
  --navy: #0C1524;
  --navy-2: #151C29;
  --navy-3: #1B2433;
  --blue: #2F6BFF;
  --blue-dark: #1E4FD1;
  --blue-soft: #EEF3FF;
  --ground: #F4F6FA;
  --card: #FFFFFF;
  --line: #E2E7EF;
  --line-2: #C9D2DF;
  --text: #0C1524;
  --muted: #4A5568;
  --green: #0E6B4C;
  --green-soft: #E6F4EE;
  --amber: #92400E;
  --amber-soft: #FDF1E3;
  --red: #B42318;
  --red-soft: #FDECEC;
  --radius: 14px;
  --font: 'Noto Sans', system-ui, sans-serif;
  --display: 'Montserrat', 'Noto Sans', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--ground); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-dark); }
h1, h2, h3 { font-family: var(--display); margin: 0; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 800; font-size: 16px; letter-spacing: .02em; color: var(--text); }
.brand span { color: var(--blue); }
.brand.light { color: #fff; }
.brand.light span { color: #7FA4FF; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 7px; }
.field label { font-size: 14px; font-weight: 600; }
.field .hint { font-size: 12px; color: var(--muted); }
.input { height: 52px; padding: 0 16px; border: 1px solid var(--line-2); border-radius: 12px; background: #F8FAFC; color: var(--text); font-size: 16px; width: 100%; }
.input:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }
.input.code { height: 62px; text-align: center; font-family: var(--display); font-weight: 800; font-size: 26px; letter-spacing: .45em; border: 1.5px solid var(--blue); }
.input.invite { height: 62px; text-align: center; font-family: var(--display); font-weight: 800; font-size: 24px; letter-spacing: .2em; text-transform: uppercase; border: 1.5px solid var(--blue); }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.check input { width: 20px; height: 20px; accent-color: var(--blue); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 52px; padding: 0 22px; border-radius: 14px; border: none; background: var(--blue); color: #fff; font-family: var(--display); font-weight: 700; font-size: 16px; cursor: pointer; }
.btn:hover { background: var(--blue-dark); color: #fff; }
.btn.block { width: 100%; }
.btn.sm { height: 40px; padding: 0 14px; border-radius: 10px; font-family: var(--font); font-size: 14px; font-weight: 600; }
.btn.ghost { background: #fff; color: var(--text); border: 1px solid var(--line-2); }
.btn.ghost:hover { background: var(--ground); color: var(--text); }
.btn.danger { background: #fff; color: var(--red); border: 1px solid #E8C4C4; }
.btn.link { background: transparent; color: var(--blue); height: 44px; font-family: var(--font); font-size: 14px; font-weight: 600; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.alert svg { flex: none; margin-top: 2px; }
.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: 12px; font-size: 14px; line-height: 1.5; }
.alert.error { background: var(--red-soft); color: var(--red); }
.alert.info { background: var(--blue-soft); color: #1E3A8A; }
.alert.ok { background: var(--green-soft); color: var(--green); }
.alert.muted { background: var(--ground); color: var(--muted); }

/* Auth layout */
.auth { min-height: 100vh; display: flex; flex-wrap: wrap; background: #fff; }
.auth-hero { flex: 1 1 480px; background: var(--navy); color: #fff; padding: 48px 56px; display: flex; flex-direction: column; justify-content: space-between; gap: 40px; }
.auth-hero h1 { font-weight: 800; font-size: 40px; line-height: 1.15; }
.auth-hero p { color: #C5CEDD; font-size: 17px; max-width: 480px; }
.auth-main { flex: 1 1 420px; display: flex; justify-content: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 18px; }
.auth-card h1 { font-size: 26px; }
.auth-card .lead { margin: -6px 0 0; color: var(--muted); font-size: 15px; line-height: 1.55; }
.auth-card .lead strong { color: var(--text); }
.auth-top { display: flex; align-items: center; justify-content: space-between; }
.auth-top .step { font-size: 13px; font-weight: 600; color: var(--muted); }
.icon-btn { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 12px; color: var(--text); background: transparent; border: none; cursor: pointer; }
.badge-icon { width: 56px; height: 56px; border-radius: 16px; background: var(--blue-soft); color: var(--blue-dark); display: flex; align-items: center; justify-content: center; }
.badge-icon.ok { width: 80px; height: 80px; border-radius: 40px; background: var(--green-soft); color: var(--green); margin: 0 auto; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 13px; }
@media (max-width: 760px) {
  .auth-hero { flex-basis: 100%; padding: 48px 24px 28px; border-radius: 0 0 28px 28px; gap: 18px; justify-content: flex-start; }
  .auth-hero h1 { font-size: 26px; }
  .auth-hero .hero-extra { display: none; }
  .auth.compact .auth-hero { display: none; }
}

/* App shell */
.shell { min-height: 100vh; display: flex; }
.sidebar { width: 248px; flex: none; background: var(--navy); color: #fff; padding: 24px 16px; display: flex; flex-direction: column; gap: 26px; position: sticky; top: 0; height: 100vh; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a { display: flex; align-items: center; gap: 12px; height: 46px; padding: 0 14px; border-radius: 10px; color: #C5CEDD; font-size: 15px; }
.sidebar nav a:hover { background: var(--navy-2); color: #fff; }
.sidebar nav a.active { background: var(--blue); color: #fff; font-weight: 600; }
.sidebar .side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.sidebar .support { padding: 14px; border-radius: 12px; background: var(--navy-2); font-size: 13px; color: #C5CEDD; }
.sidebar .support strong { color: #fff; }
.content { flex: 1; min-width: 0; padding: 28px 36px 48px; display: flex; flex-direction: column; gap: 20px; }
.page-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.page-head h1 { font-size: 26px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.mobile-top, .bottom-nav { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .content { padding: 8px 16px 100px; }
  .mobile-top { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 4px; }
  .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: 70px; padding-bottom: env(safe-area-inset-bottom); background: #fff; border-top: 1px solid var(--line); justify-content: space-around; align-items: center; }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 64px; color: var(--muted); font-size: 11px; }
  .bottom-nav a.active { color: var(--blue); font-weight: 600; }
  .page-head h1 { font-size: 22px; }
}

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; }
.pad { padding: 18px 20px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { padding: 14px 18px; border-radius: 14px; background: #fff; border: 1px solid var(--line); }
.stat .k { font-size: 13px; color: var(--muted); }
.stat .v { margin-top: 4px; font-family: var(--display); font-weight: 700; font-size: 24px; }
.stat .v.bad { color: var(--red); }

.tag { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 8px; background: #EEF1F6; color: var(--muted); font-size: 12px; font-weight: 600; }
.tag.offline { background: var(--red-soft); color: var(--red); }
.tag.ok { background: var(--green-soft); color: var(--green); }
.tag.blue { background: var(--blue-soft); color: var(--blue-dark); }
.tag.amber { background: var(--amber-soft); color: var(--amber); }
.dot { width: 8px; height: 8px; border-radius: 4px; display: inline-block; flex: none; }
.dot.on { background: #12805C; } .dot.off { background: var(--red); } .dot.unk { background: #8792A6; }

/* Devices (home) */
.devices { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 520px), 1fr)); gap: 14px; }
.device { padding: 14px 0 6px; display: flex; flex-direction: column; gap: 10px; }
.device-head { display: flex; align-items: center; gap: 10px; padding: 0 14px; }
.device-head h2 { flex: 1; min-width: 0; font-size: 16px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device.is-offline .device-head h2 { color: var(--muted); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px; }
.cams { display: flex; gap: 8px; overflow-x: auto; padding: 0 14px 4px; scroll-snap-type: x mandatory; }
.cam { flex: none; position: relative; width: 168px; aspect-ratio: 16 / 10; border-radius: 10px; background: var(--navy-3); overflow: hidden; color: #fff; scroll-snap-align: start; }
.cam .ph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #8C9AB3; font-size: 11px; }
.cam .nm { position: absolute; left: 0; right: 0; bottom: 0; padding: 16px 8px 6px; background: linear-gradient(transparent, rgba(12,21,36,.85)); font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cam.off { background: #5B6472; }
.cam.off .ph { color: #fff; font-weight: 600; flex-direction: column; gap: 4px; }
.device.expanded .cams { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); overflow: visible; }
.device.expanded .cam { width: auto; }
.expand { align-self: center; height: 36px; padding: 0 12px; border: none; background: transparent; color: var(--muted); font-size: 13px; display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.device.expanded .expand svg { transform: rotate(180deg); }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.empty h2 { color: var(--text); font-size: 18px; margin-bottom: 6px; }

/* Lists / tables */
.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 18px; border-top: 1px solid #EEF1F6; }
.list-row:first-child { border-top: none; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; }
.tbl th, .tbl td { position: relative; }
.tbl th { text-align: left; padding: 10px 14px; font-size: 12px; font-weight: 600; color: var(--muted); background: #F8FAFC; }
.tbl td { padding: 11px 14px; border-top: 1px solid #EEF1F6; vertical-align: middle; }
.tbl td.num { font-variant-numeric: tabular-nums; }
.inline-form { display: inline; }

/* Admin companies */
.split { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
.split > .side { flex: 1 1 300px; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.split > .main { flex: 2 1 520px; min-width: 0; }
.co-item { display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; border-radius: 14px; border: 1.5px solid var(--line); background: #fff; color: var(--text); }
.co-item:hover { color: var(--text); border-color: #9DB8FF; }
.co-item.active { border-color: var(--blue); background: var(--blue-soft); }
.co-item .t { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; font-size: 16px; }
.co-item .s { font-size: 13px; color: var(--muted); }
.invite-box { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; padding: 14px 16px; border-radius: 12px; background: var(--blue-soft); }
.invite-box .code { font-family: var(--display); font-weight: 800; font-size: 24px; letter-spacing: .12em; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { height: 38px; padding: 0 14px; border-radius: 19px; border: 1px solid #D5DCE6; background: #fff; color: var(--text); font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; }
.chip.active { background: var(--navy); border-color: var(--navy); color: #fff; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.site-opt { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.site-opt input { width: 18px; height: 18px; accent-color: var(--blue); }
details.box { border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; background: #fff; }
details.box summary { cursor: pointer; padding: 12px 0; font-weight: 600; }
details.box[open] summary { border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; padding-bottom: 14px; }

/* Badge */
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: #D92D20; color: #fff; font-size: 11px; font-weight: 700; font-family: var(--font); line-height: 1; }
.badge[hidden] { display: none; }
.sidebar nav a .badge { margin-left: auto; }
.nav-ic { position: relative; display: inline-flex; }
.nav-ic .badge { position: absolute; top: -6px; right: -12px; min-width: 18px; height: 18px; font-size: 10px; }

/* Чат */
.chat-fab { position: fixed; right: 20px; bottom: 24px; z-index: 30; width: 58px; height: 58px; border-radius: 29px; background: linear-gradient(135deg, #45B6F5, #2F6BFF); color: #fff; display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 24px rgba(47,107,255,.35); }
.chat-fab:hover { color: #fff; transform: translateY(-1px); }
.chat-fab .badge { position: absolute; top: -2px; right: -2px; border: 2px solid #fff; height: 22px; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: #fff; border: 1px solid var(--line); border-radius: 18px 18px 0 0; }
.chat-avatar { flex: none; width: 42px; height: 42px; border-radius: 21px; background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: center; font-family: var(--display); font-weight: 700; }
.chat { display: flex; flex-direction: column; height: calc(100vh - 200px); min-height: 420px; background: #fff; border: 1px solid var(--line); border-top: none; border-radius: 0 0 18px 18px; overflow: hidden; }
.chat-admin .chat { height: calc(100vh - 260px); border: none; border-radius: 0; }
.chat-admin .chat-head { border: none; border-radius: 0; }
.chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: var(--ground); }
.msg { display: flex; flex-direction: column; gap: 3px; max-width: 80%; }
.msg.me { align-self: flex-end; align-items: flex-end; }
.msg.them { align-self: flex-start; align-items: flex-start; }
.msg .bubble { padding: 10px 14px; border-radius: 18px 18px 18px 4px; background: #fff; border: 1px solid var(--line); font-size: 15px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.me .bubble { background: var(--blue); border-color: var(--blue); color: #fff; border-radius: 18px 18px 4px 18px; }
.msg .t { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chat-quick { display: flex; gap: 8px; padding: 8px 12px 0; overflow-x: auto; background: #fff; }
.chat-quick .chip { flex: none; height: 34px; font-size: 13px; color: var(--blue-dark); border-color: #C9D7F5; cursor: pointer; }
.chat-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; background: #fff; }
.chat-form textarea { height: auto; min-height: 46px; max-height: 140px; padding: 12px 16px; border-radius: 23px; resize: none; line-height: 1.4; font-size: 15px; }
.chat-send { flex: none; width: 46px; height: 46px; border: none; border-radius: 23px; background: var(--blue); color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.chat-err { margin: 0; padding: 0 16px 10px; color: var(--red); font-size: 13px; background: #fff; }
@media (max-width: 860px) {
  .chat-fab { bottom: 86px; right: 16px; }
  .chat { height: calc(100dvh - 250px); min-height: 360px; }
  .chat-admin .chat { height: calc(100dvh - 300px); }
  .chat-admin .side { max-height: 200px; overflow-y: auto; }
}

/* Төхөөрөмж нэмэх — QR уншигч */
.head-actions { display: flex; gap: 8px; align-items: center; }
.scan-card { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.scanner { position: relative; width: 100%; max-width: 420px; margin: 0 auto; aspect-ratio: 1 / 1; border-radius: 16px; overflow: hidden; background: var(--navy); color: #C5CEDD; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; }
.scanner.is-live video { display: block; }
.scan-idle { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; padding: 20px; }
.scan-idle p { margin: 0; font-size: 14px; line-height: 1.5; }
.scanner.is-live .scan-idle { display: none; }
.scan-frame { position: absolute; inset: 16%; pointer-events: none; }
.scan-frame span { position: absolute; width: 28px; height: 28px; border: 3px solid #fff; }
.scan-frame span:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 8px; }
.scan-frame span:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 8px; }
.scan-frame span:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 8px; }
.scan-frame span:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 8px; }
.scan-line { position: absolute; left: 6%; right: 6%; height: 2px; background: var(--blue); box-shadow: 0 0 10px var(--blue); top: 0; display: none; }
.scanner.is-live .scan-line { display: block; animation: scanline 2.2s ease-in-out infinite alternate; }
@keyframes scanline { from { top: 4%; } to { top: 96%; } }
@media (prefers-reduced-motion: reduce) { .scanner.is-live .scan-line { animation: none; top: 50%; } }
.scanner.is-found .scan-frame span { border-color: #34D399; }
.scan-status { margin: 0; min-height: 20px; text-align: center; font-size: 14px; color: var(--muted); }
.scan-status.ok { color: var(--green); font-weight: 600; }
.scan-status.err { color: var(--red); }
.scan-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.scan-actions .btn { padding: 0 12px; font-size: 15px; }
.scan-actions label.btn { cursor: pointer; }
.device-form { display: flex; flex-direction: column; gap: 16px; }
.input.mono { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; letter-spacing: .06em; text-transform: uppercase; }
.input.static { display: flex; align-items: center; gap: 8px; background: var(--ground); color: var(--text); }
select.input { appearance: auto; }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 52px; }
.pw-toggle { position: absolute; right: 4px; top: 4px; width: 44px; height: 44px; border: 0; background: transparent; color: var(--muted); border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.input.filled { border-color: #34D399; background: var(--green-soft); }
@media (max-width: 400px) { .scan-actions { grid-template-columns: 1fr; } }
[hidden] { display: none !important; }
.scan-card, .device-form, .device-note { width: 100%; max-width: 720px; }
