/* Mobile personal cabinet — Comfortaa / teal glass */
@import url("https://fonts.googleapis.com/css2?family=Comfortaa:wght@400;600;700&display=swap");

:root {
  --m-accent: #3d9cad;
  --m-accent-strong: #2d6f7c;
  --m-text: #1a2530;
  --m-muted: #455563;
  --m-ok: #5cb88a;
  --m-danger: #e07d6f;
  --m-door: #c2410c;
  --m-temp: #dc2626;
  --m-flame: #ff0000;
  --m-smoke: #7c3aed;
  --m-nav-h: 64px;
  --m-safe-b: env(safe-area-inset-bottom, 0px);
  --m-safe-t: env(safe-area-inset-top, 0px);
  --m-radius: 16px;
  --m-glass: rgba(255, 255, 255, 0.56);
  --m-border: rgba(45, 90, 110, 0.14);
  --font: "Comfortaa", system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
.m-body {
  font-family: var(--font);
  color: var(--m-text);
  background: transparent;
  background-color: #e8f2f6;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  position: relative;
}
/* Mobile: avoid background-attachment:fixed quirks; cover via fixed stack */
.m-body.akb-bg-rotating .akb-bg-layer {
  background-attachment: scroll;
}
.hidden { display: none !important; }
.m-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* Login */
.m-login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px calc(24px + var(--m-safe-b));
  padding-top: calc(24px + var(--m-safe-t));
}
.m-login-card {
  width: min(400px, 100%);
  background: var(--m-glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--m-border);
  border-radius: 22px;
  padding: 28px 22px;
  box-shadow: 0 12px 40px rgba(45, 90, 110, 0.12);
}
.m-login-brand {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
}
.m-login-brand span { color: var(--m-accent); }
.m-login-sub { margin: 4px 0 20px; color: var(--m-muted); font-size: 14px; }
.m-login-card label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--m-muted);
  margin: 12px 0 6px;
}
.m-login-card input {
  width: 100%;
  padding: 14px 14px;
  font-size: 16px;
  border: 1px solid var(--m-border);
  border-radius: 12px;
  background: #fff;
  font-family: inherit;
}
.m-err { min-height: 20px; color: #b91c1c; font-size: 13px; margin-top: 8px; }
.m-link-desk {
  display: block;
  text-align: center;
  margin-top: 16px;
  color: var(--m-accent-strong);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  padding: 10px;
}

/* App shell */
.m-app {
  min-height: 100dvh;
  padding-bottom: calc(var(--m-nav-h) + var(--m-safe-b) + 12px);
}
.m-top {
  position: sticky;
  top: 0;
  z-index: 40;
  padding: calc(10px + var(--m-safe-t)) 14px 10px;
  background: rgba(255, 255, 255, 0.42);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  border-bottom: 1px solid var(--m-border);
}
.m-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.m-brand {
  font-size: 18px;
  font-weight: 700;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
}
.m-brand span {
  font-size: 11px;
  font-weight: 700;
  background: rgba(61, 156, 173, 0.16);
  color: var(--m-accent-strong);
  padding: 4px 8px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: middle;
}
.m-icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: rgba(45, 90, 110, 0.08);
  color: var(--m-text);
  font-size: 20px;
  cursor: pointer;
}
.m-shop-row { margin-top: 10px; }
.m-select {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  font-family: inherit;
  font-weight: 600;
  border-radius: 12px;
  border: 1px solid var(--m-border);
  background: #fff;
  color: var(--m-text);
}
.m-contacts-bar {
  margin-top: 8px;
  min-height: 0;
}
.m-contacts-bar:empty { display: none; }
.m-contacts-hint {
  font-size: 12px;
  color: var(--m-muted);
  padding: 6px 2px 2px;
  line-height: 1.35;
}
.m-contacts-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.m-tel-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--m-border);
  background: rgba(255, 255, 255, 0.72);
  text-decoration: none;
  color: var(--m-accent-strong);
  font-weight: 700;
  font-size: 14px;
  line-height: 1.2;
  -webkit-tap-highlight-color: transparent;
}
.m-tel-chip:active { background: rgba(61, 156, 173, 0.14); }
.m-tel-chip .who {
  font-size: 11px;
  font-weight: 600;
  color: var(--m-muted);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.m-contact-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--m-border);
}
.m-contact-row:last-child { border-bottom: none; }
.m-contact-row .who { font-weight: 700; font-size: 14px; }
.m-contact-row .role { font-size: 12px; color: var(--m-muted); margin-top: 2px; }
.m-contact-row a.phone {
  flex: 0 0 auto;
  color: var(--m-accent-strong);
  font-weight: 800;
  font-size: 15px;
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(61, 156, 173, 0.12);
  white-space: nowrap;
}
.m-contact-row a.phone:active { background: rgba(61, 156, 173, 0.22); }
.m-contact-empty {
  font-size: 13px;
  color: var(--m-muted);
  padding: 4px 0 8px;
  line-height: 1.4;
}
.m-sheet-contacts {
  margin-bottom: 14px;
  padding: 12px 12px 4px;
  border-radius: 14px;
  border: 1px solid var(--m-border);
  background: rgba(255, 255, 255, 0.5);
}
.m-sheet-contacts .m-card-title {
  font-size: 14px;
  margin-bottom: 2px;
}
.m-alert-phones {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.m-alert-phones a.phone {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(61, 156, 173, 0.14);
  color: var(--m-accent-strong);
  font-weight: 800;
  font-size: 13px;
  text-decoration: none;
}
.m-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.m-sum {
  font-size: 11px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.42);
  border: 1px solid var(--m-border);
  color: var(--m-muted);
}
.m-sum.warn { color: #9a3412; background: #ffedd5; border-color: #fdba74; }
.m-sum.hot { color: #991b1b; background: #fee2e2; border-color: #fecaca; }
.m-sum.crit { color: #fff; background: #dc2626; border-color: #dc2626; }
.m-sum.ok { color: #166534; background: #dcfce7; border-color: #86efac; }

.m-crit {
  margin: 8px 12px 0;
  padding: 12px 14px;
  border-radius: 14px;
  font-weight: 800;
  font-size: 14px;
  text-align: center;
  letter-spacing: .02em;
  color: #fff;
  background: #dc2626;
  animation: mPulse .55s steps(1) infinite;
}
.m-crit.smoke { background: #7c3aed; }
@keyframes mPulse {
  0%, 49% { filter: brightness(1); }
  50%, 100% { filter: brightness(.82); }
}

.m-main { padding: 10px 12px 0; }
.m-tab-pane { display: none; }
.m-tab-pane.active { display: block; }

.m-filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 12px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.m-filters::-webkit-scrollbar { display: none; }
.m-chip {
  flex: 0 0 auto;
  border: 1px solid var(--m-border);
  background: rgba(255,255,255,.42);
  color: var(--m-text);
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  min-height: 40px;
}
.m-chip.active { background: var(--m-accent); border-color: var(--m-accent); color: #fff; }
.m-chip.door.active { background: var(--m-door); border-color: var(--m-door); }
.m-chip.hot.active { background: var(--m-temp); border-color: var(--m-temp); }
.m-chip.flame.active { background: #b91c1c; border-color: #b91c1c; }
.m-chip.smoke.active { background: var(--m-smoke); border-color: var(--m-smoke); }
.m-chip.off.active { background: #64748b; border-color: #64748b; }

.m-cab-list { display: flex; flex-direction: column; gap: 10px; }
.m-cab {
  background: var(--m-glass);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 2px solid transparent;
  border-radius: var(--m-radius);
  padding: 12px;
  box-shadow: 0 4px 16px rgba(45, 90, 110, 0.08);
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-family: inherit;
  color: inherit;
}
.m-cab.ok { border-color: #86efac; }
.m-cab.door { border-color: var(--m-door); background: linear-gradient(180deg, #fff7ed, rgba(255,255,255,.9)); }
.m-cab.hot { border-color: var(--m-temp); background: #fee2e2; }
.m-cab.offline { border-color: #cbd5e1; opacity: .88; }
.m-cab.flame {
  border-color: #ff0000;
  animation: mCritFlame .45s steps(1) infinite;
}
.m-cab.smoke {
  border-color: #a855f7;
  animation: mCritSmoke .45s steps(1) infinite;
}
.m-cab.both { animation: mCritBoth .35s steps(1) infinite; }
@keyframes mCritFlame {
  0%,49% { background: #ffe5e5; }
  50%,100% { background: #ff6b6b; color: #fff; }
}
@keyframes mCritSmoke {
  0%,49% { background: #f3e8ff; }
  50%,100% { background: #a855f7; color: #fff; }
}
@keyframes mCritBoth {
  0%,49% { background: #ff0000; color: #fff; }
  50%,100% { background: #7c3aed; color: #fff; }
}
.m-cab-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
  margin-bottom: 8px;
}
.m-cab-title { font-size: 15px; font-weight: 700; line-height: 1.25; }
.m-cab-shop {
  display: inline-block;
  margin-top: 3px;
  font-size: 11px;
  font-weight: 700;
  background: rgba(61,156,173,.14);
  color: var(--m-accent-strong);
  border-radius: 6px;
  padding: 2px 7px;
}
.m-cab-meta { font-size: 11px; color: var(--m-muted); margin-top: 2px; }
.m-cab-flags { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.m-flag {
  font-size: 10px;
  font-weight: 800;
  padding: 4px 7px;
  border-radius: 8px;
  background: #f1f5f9;
  color: #475569;
}
.m-flag.door { background: #ffedd5; color: #9a3412; }
.m-flag.hot { background: #fee2e2; color: #991b1b; }
.m-flag.flame { background: #fecaca; color: #7f1d1d; }
.m-flag.smoke { background: #ede9fe; color: #5b21b6; }
.m-flag.off { background: #e2e8f0; color: #64748b; }

.m-cells {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 6px;
}
.m-cell {
  border-radius: 10px;
  border: 2px solid #94a3b8;
  background: #f8fafc;
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px 2px;
}
.m-cell .n { font-weight: 800; font-size: 13px; }
.m-cell.closed { border-color: #2ecc71; background: #d5f5e3; }
.m-cell.open { border-color: var(--m-door); background: #ffedd5; color: #9a3412; }
.m-cell.door-long {
  border-color: #c2410c;
  background: #ffedd5;
  color: #7c2d12;
  animation: mDoorLongBlink .85s ease-in-out infinite;
  box-shadow: 0 0 0 2px rgba(194, 65, 12, .35);
}
.m-cell.offline { border-color: #cbd5e1; background: #eef2f5; opacity: .85; }
.m-cell.hot { border-color: var(--m-temp); background: #fee2e2; }
.m-cell.flame { border-color: #ff0000; background: #fecaca; }
.m-cell.smoke { border-color: #a855f7; background: #ede9fe; }
.m-cell .t {
  font-size: 10px;
  font-weight: 700;
  color: var(--m-muted);
  min-height: 1.15em;
  max-width: 100%;
  overflow: hidden;
  text-align: center;
  line-height: 1.15;
}
.m-cell.open .t,
.m-cell.door-long .t { color: #9a3412; }
.m-cell .t .slot-metric-fade {
  display: inline-block;
  transition: opacity .35s ease, transform .35s ease;
}
.m-cell .t .slot-metric-fade.fade-out {
  opacity: 0;
  transform: translateY(4px);
}
@keyframes mDoorLongBlink {
  0%, 100% {
    background: #ffedd5;
    border-color: #c2410c;
    box-shadow: 0 0 0 2px rgba(194, 65, 12, .35);
  }
  50% {
    background: #fb923c;
    border-color: #9a3412;
    box-shadow: 0 0 0 4px rgba(234, 88, 12, .5);
  }
}
.m-cab.door-long {
  border-color: #c2410c;
  background: linear-gradient(180deg, #fff7ed, rgba(255, 255, 255, .92));
  animation: mDoorLongBlink .85s ease-in-out infinite;
}

.m-empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--m-muted);
  background: var(--m-glass);
  border-radius: var(--m-radius);
  border: 1px solid var(--m-border);
}

/* Alerts */
.m-alerts { display: flex; flex-direction: column; gap: 10px; }
.m-alert {
  background: var(--m-glass);
  border-radius: var(--m-radius);
  border: 1px solid var(--m-border);
  padding: 14px;
}
.m-alert.flame { border-left: 5px solid #ff0000; }
.m-alert.smoke { border-left: 5px solid #7c3aed; }
.m-alert.temp { border-left: 5px solid #dc2626; }
.m-alert.door_5m { border-left: 5px solid #c2410c; }
.m-alert-kind { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--m-muted); }
.m-alert-title { font-size: 15px; font-weight: 700; margin: 4px 0; }
.m-alert-meta { font-size: 12px; color: var(--m-muted); }
.m-alert-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* More */
.m-card {
  background: var(--m-glass);
  border-radius: var(--m-radius);
  border: 1px solid var(--m-border);
  padding: 18px 16px;
}
.m-card-title { font-size: 18px; font-weight: 700; }
.m-muted { color: var(--m-muted); font-size: 13px; margin: 4px 0 16px; }
.m-hint { font-size: 12px; color: var(--m-muted); margin-top: 16px; line-height: 1.4; }

/* Buttons */
.m-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 12px 16px;
  border: none;
  border-radius: 14px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  color: #fff;
  background: var(--m-accent);
}
.m-btn-block { width: 100%; margin-top: 10px; }
.m-btn-primary { background: var(--m-accent-strong); }
.m-btn-ghost {
  background: rgba(45, 90, 110, 0.1);
  color: var(--m-text);
}
.m-btn-danger { background: #e07d6f; }
.m-btn-ack { background: #0f766e; }
.m-btn-clear { background: #b91c1c; }
.m-btn-clear.smoke { background: #6d28d9; }
.m-btn-sm { min-height: 42px; font-size: 13px; padding: 10px 12px; flex: 1; }

/* Bottom nav */
.m-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: calc(var(--m-nav-h) + var(--m-safe-b));
  padding-bottom: var(--m-safe-b);
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid var(--m-border);
  box-shadow: 0 -4px 24px rgba(45, 90, 110, 0.08);
}
.m-nav-btn {
  position: relative;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  color: var(--m-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  min-height: var(--m-nav-h);
}
.m-nav-btn.active { color: var(--m-accent-strong); }
.m-nav-ico { font-size: 18px; line-height: 1; }
.m-badge {
  position: absolute;
  top: 8px;
  right: calc(50% - 28px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Sheet */
.m-sheet {
  position: fixed;
  inset: 0;
  z-index: 80;
  pointer-events: none;
  visibility: hidden;
}
.m-sheet.open {
  pointer-events: auto;
  visibility: visible;
}
.m-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  opacity: 0;
  transition: opacity .2s;
}
.m-sheet.open .m-sheet-backdrop { opacity: 1; }
.m-sheet-panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: min(88dvh, 720px);
  background: #fff;
  border-radius: 22px 22px 0 0;
  transform: translateY(110%);
  transition: transform .28s ease;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--m-safe-b);
  box-shadow: 0 -12px 40px rgba(0,0,0,.2);
}
.m-sheet.open .m-sheet-panel { transform: translateY(0); }
.m-sheet-handle {
  width: 40px; height: 4px;
  border-radius: 999px;
  background: #cbd5e1;
  margin: 10px auto 0;
}
.m-sheet-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 16px 8px;
  border-bottom: 1px solid #e2e8f0;
}
.m-sheet-head h2 { margin: 0; font-size: 17px; }
.m-sheet-body {
  overflow: auto;
  padding: 12px 16px 20px;
  -webkit-overflow-scrolling: touch;
}
.m-metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.m-metric {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px 10px;
  text-align: center;
}
.m-metric .v { font-size: 20px; font-weight: 800; line-height: 1.1; }
.m-metric .l { font-size: 11px; color: var(--m-muted); margin-top: 4px; }
.m-metric.hot .v { color: var(--m-temp); }
.m-metric.open .v { color: var(--m-door); }
.m-metric.ok .v { color: #15803d; }
.m-cell-detail {
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fff;
}
.m-cell-detail h3 { margin: 0 0 8px; font-size: 14px; }
.m-cell-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.m-toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--m-nav-h) + var(--m-safe-b) + 16px);
  transform: translateX(-50%) translateY(20px);
  background: #0f172a;
  color: #fff;
  padding: 12px 18px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: .2s;
  z-index: 100;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.m-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.m-toast.err { background: #7f1d1d; }

body.role-observer .admin-only { display: none !important; }
