:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-strong: #f9fafb;
  --ink: #17202a;
  --muted: #5d6673;
  --line: #d8dee8;
  --line-strong: #b9c2d0;
  --brand: #234e70;
  --brand-ink: #ffffff;
  --green: #15803d;
  --green-soft: #dcfce7;
  --yellow: #ca8a04;
  --yellow-soft: #fef3c7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --info: #2563eb;
  --shadow: 0 18px 45px rgba(31, 41, 55, 0.12);
  --radius: 8px;
  --tile-radius: 6px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.65), rgba(244, 246, 248, 0.9)),
    var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

a {
  color: var(--brand);
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 0 auto 14px;
  max-width: 1440px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: var(--radius);
  background: #111827;
  box-shadow: var(--shadow);
}

.brand-mark svg {
  display: block;
  width: 30px;
  height: 30px;
}

.brand-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
}

.brand-subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 1.05fr) minmax(420px, 1.3fr) minmax(300px, 0.85fr);
  gap: 14px;
  max-width: 1440px;
  margin: 0 auto;
}

.operator-layout {
  grid-template-columns: minmax(430px, 0.95fr) minmax(360px, 0.75fr) auto;
  align-items: start;
}

.operator-column {
  min-width: 0;
}

.activity-column {
  min-width: 0;
}

.admin-column {
  min-width: 0;
}

.admin-drawer {
  min-width: 92px;
}

.admin-drawer > summary {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 12px 30px rgba(31, 41, 55, 0.08);
  cursor: pointer;
  font-weight: 900;
  list-style: none;
  padding: 11px 12px;
}

.admin-drawer > summary::-webkit-details-marker {
  display: none;
}

.admin-drawer[open] {
  min-width: min(33vw, 360px);
}

.admin-stack {
  display: grid;
  gap: 14px;
  margin-top: 12px;
}

.login-layout {
  display: grid;
  grid-template-columns: minmax(320px, 0.85fr) minmax(420px, 1.15fr);
  gap: 16px;
  max-width: 1180px;
  margin: 24px auto;
}

.auth-layout {
  display: grid;
  min-height: calc(100vh - 92px);
  place-items: center;
  padding: 18px 0;
}

.auth-card {
  width: min(100%, 460px);
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 12px 30px rgba(31, 41, 55, 0.08);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 0;
}

.panel-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
}

.panel-kicker {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.panel-body {
  padding: 14px;
}

.map-console {
  position: relative;
}

.map-console-body {
  display: grid;
  gap: 10px;
}

.map-console .map-canvas {
  height: clamp(330px, 54vh, 620px);
  min-height: 330px;
}

.stack {
  display: grid;
  gap: 14px;
}

.compact-stack {
  display: grid;
  gap: 10px;
}

.login-card {
  align-self: start;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.field label,
.field > span,
.label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.input,
.textarea,
.select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: var(--tile-radius);
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
}

.textarea {
  min-height: 78px;
  resize: vertical;
}

.input:focus,
.textarea:focus,
.select:focus,
.area-tile:focus-visible,
.btn:focus-visible,
.command-button:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.22);
  outline-offset: 2px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line-strong);
  border-radius: var(--tile-radius);
  background: #fff;
  color: var(--ink);
  padding: 9px 12px;
  font-weight: 750;
  text-decoration: none;
}

.btn svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.btn.primary {
  border-color: var(--brand);
  background: var(--brand);
  color: var(--brand-ink);
}

.btn.danger {
  border-color: #991b1b;
  background: var(--red);
  color: #fff;
}

.btn.ghost {
  background: transparent;
}

.btn.small {
  min-height: 34px;
  padding: 7px 9px;
  font-size: 0.86rem;
}

.btn.full {
  width: 100%;
}

.building-map {
  display: grid;
  grid-template-columns: repeat(var(--map-cols, 8), minmax(34px, 1fr));
  grid-template-rows: repeat(var(--map-rows, 6), minmax(62px, 1fr));
  gap: 6px;
  min-height: 438px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background-color: #eef2f7;
  background-image:
    linear-gradient(90deg, rgba(216, 222, 232, 0.52) 1px, transparent 1px),
    linear-gradient(180deg, rgba(216, 222, 232, 0.52) 1px, transparent 1px),
    var(--map-background, none);
  background-position:
    0 0,
    0 0,
    center;
  background-repeat:
    repeat,
    repeat,
    no-repeat;
  background-size:
    calc(100% / var(--map-cols, 8)) calc(100% / var(--map-rows, 6)),
    calc(100% / var(--map-cols, 8)) calc(100% / var(--map-rows, 6)),
    contain;
}

.map-canvas {
  position: relative;
  min-height: 438px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background-color: #eef2f7;
  background-image:
    linear-gradient(90deg, rgba(216, 222, 232, 0.52) 1px, transparent 1px),
    linear-gradient(180deg, rgba(216, 222, 232, 0.52) 1px, transparent 1px);
  background-size:
    calc(100% / var(--map-cols, 8)) calc(100% / var(--map-rows, 6)),
    calc(100% / var(--map-cols, 8)) calc(100% / var(--map-rows, 6));
}

.map-canvas.has-map-image {
  background-color: #fff;
  background-image: none;
}

.map-editor-canvas.draw-mode {
  cursor: crosshair;
}

.map-photo,
.map-placeholder,
.zone-layer {
  position: absolute;
  inset: 0;
}

.map-photo {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.map-placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.92rem;
  text-align: center;
}

.zone-layer {
  z-index: 1;
}

.zone-layer .area-tile {
  position: absolute;
}

.zone-layer .area-tile,
.zone-overlay {
  position: absolute;
}

.area-tile {
  position: relative;
  display: grid;
  min-width: 0;
  align-content: space-between;
  gap: 6px;
  border: 1px solid #aab4c3;
  border-radius: var(--tile-radius);
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  padding: 9px;
  text-align: left;
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    background 120ms ease,
    box-shadow 120ms ease;
}

.area-tile:not(:disabled):hover {
  transform: translateY(-1px);
  border-color: var(--brand);
  box-shadow: 0 8px 20px rgba(31, 41, 55, 0.12);
}

.area-tile.selected {
  border-color: var(--info);
  background: #eff6ff;
  box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.28);
}

.area-tile.occupied {
  background: #f8fafc;
}

.area-tile.owned {
  border-color: var(--green);
  background: var(--green-soft);
}

.area-tile.yellow-alert {
  border-color: var(--yellow);
  background: var(--yellow-soft);
  box-shadow: inset 0 0 0 2px rgba(202, 138, 4, 0.2);
}

.area-tile.red-alert {
  border-color: var(--red);
  background: var(--red-soft);
  box-shadow: inset 0 0 0 2px rgba(220, 38, 38, 0.26);
  animation: redPulse 1.2s ease-in-out infinite;
}

.area-tile.cell-zone-tile {
  min-height: 0;
  padding: 6px;
}

.area-tile.cell-zone-tile .area-name {
  font-size: 0.78rem;
}

.area-tile.cell-zone-tile .area-meta {
  font-size: 0.68rem;
}

.building-map.has-map-image .area-tile,
.map-canvas.has-map-image .area-tile {
  background: rgba(255, 255, 255, 0.44);
  border-color: rgba(35, 78, 112, 0.72);
  backdrop-filter: blur(1px);
}

.building-map.has-map-image .area-tile.owned,
.map-canvas.has-map-image .area-tile.owned {
  background: rgba(220, 252, 231, 0.62);
}

.building-map.has-map-image .area-tile.yellow-alert,
.map-canvas.has-map-image .area-tile.yellow-alert {
  background: rgba(254, 243, 199, 0.68);
}

.building-map.has-map-image .area-tile.red-alert,
.map-canvas.has-map-image .area-tile.red-alert {
  background: rgba(254, 226, 226, 0.72);
}

.area-tile.status-none,
.building-map.has-map-image .area-tile.status-none,
.map-canvas.has-map-image .area-tile.status-none {
  background: rgba(255, 255, 255, 0.42);
  border-color: rgba(35, 78, 112, 0.74);
  color: #111827;
}

.area-tile.status-green,
.building-map.has-map-image .area-tile.status-green,
.map-canvas.has-map-image .area-tile.status-green {
  background: rgba(34, 197, 94, 0.78);
  border-color: #0f7b34;
  color: #052e16;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.3);
}

.area-tile.status-yellow,
.building-map.has-map-image .area-tile.status-yellow,
.map-canvas.has-map-image .area-tile.status-yellow {
  background: rgba(250, 204, 21, 0.88);
  border-color: #a16207;
  color: #3f2f00;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.32);
}

.area-tile.status-red,
.building-map.has-map-image .area-tile.status-red,
.map-canvas.has-map-image .area-tile.status-red {
  background: rgba(255, 0, 0, 0.9);
  border-color: #fff;
  color: #fff;
  box-shadow:
    0 0 0 4px rgba(255, 255, 255, 0.72),
    0 0 30px rgba(255, 0, 0, 0.9);
  animation: redPulse 0.9s ease-in-out infinite;
}

.area-tile.status-green .area-meta,
.area-tile.status-yellow .area-meta,
.area-tile.status-red .area-meta {
  color: inherit;
}

.area-tile.status-green .door-label,
.area-tile.status-yellow .door-label,
.area-tile.status-red .door-label {
  background: rgba(255, 255, 255, 0.55);
  color: inherit;
}

.area-name {
  display: block;
  overflow-wrap: anywhere;
  font-size: 0.92rem;
  font-weight: 850;
}

.area-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.occupant-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.door-label {
  display: inline-flex;
  min-width: 24px;
  justify-content: center;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.08);
  padding: 2px 6px;
  color: #374151;
  font-size: 0.72rem;
  font-weight: 800;
}

.status-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.save-status {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--tile-radius);
  background: #fff;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
}

.save-status.saved {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #166534;
}

.save-status.error {
  border-color: #fecaca;
  background: #fff1f2;
  color: #991b1b;
}

.badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 3px 9px;
  font-size: 0.78rem;
  font-weight: 800;
}

.badge.green {
  border-color: #86efac;
  background: var(--green-soft);
  color: #166534;
}

.badge.yellow {
  border-color: #fde68a;
  background: var(--yellow-soft);
  color: #854d0e;
}

.badge.red {
  border-color: #fecaca;
  background: var(--red-soft);
  color: #991b1b;
}

.badge.danger {
  border-color: #fecaca;
  background: var(--red-soft);
  color: #991b1b;
}

.badge.info {
  border-color: #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
}

.command-panel.embedded {
  position: sticky;
  bottom: 10px;
  z-index: 50;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 14px 30px rgba(31, 41, 55, 0.14);
  backdrop-filter: blur(10px);
}

.command-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 10px 0;
}

.command-body {
  padding: 10px;
}

.command-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.command-button {
  display: grid;
  min-width: 0;
  min-height: 96px;
  place-items: center;
  border: 0;
  border-radius: var(--radius);
  color: #fff;
  padding: 14px 9px;
  text-align: center;
  box-shadow: 0 14px 24px rgba(31, 41, 55, 0.16);
}

.command-button svg {
  width: 28px;
  height: 28px;
}

.command-button span {
  display: block;
  margin-top: 7px;
  overflow-wrap: anywhere;
  font-size: 1.05rem;
  font-weight: 900;
}

.command-button small {
  display: block;
  margin-top: 2px;
  font-size: 0.76rem;
  font-weight: 750;
  opacity: 0.92;
}

.command-button.green {
  background: linear-gradient(180deg, #16a34a, #166534);
}

.command-button.yellow {
  background: linear-gradient(180deg, #f59e0b, #a16207);
}

.command-button.red {
  background: linear-gradient(180deg, #ff1f1f, #a40000);
}

.request-card,
.alert-card,
.coverage-row,
.roster-row,
.message,
.setting-row,
.notice-card {
  border: 1px solid var(--line);
  border-radius: var(--tile-radius);
  background: var(--panel-strong);
  padding: 10px;
}

.alert-card {
  display: grid;
  gap: 10px;
}

.coverage-list {
  display: grid;
  gap: 8px;
}

.coverage-summary {
  display: grid;
  gap: 10px;
}

.coverage-focus {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--tile-radius);
  background: #fff;
  padding: 10px;
}

.coverage-focus.status-green {
  border-color: #86efac;
  background: #f0fdf4;
}

.coverage-focus.status-yellow {
  border-color: #facc15;
  background: #fffbeb;
}

.coverage-focus.status-red {
  border-color: #ff2a2a;
  background: #fff1f2;
}

.coverage-legend {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
}

.coverage-count {
  display: grid;
  min-width: 0;
  justify-items: center;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: var(--tile-radius);
  background: #fff;
  padding: 8px 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
}

.coverage-count strong {
  color: var(--ink);
  font-size: 1rem;
}

.coverage-dot {
  width: 16px;
  height: 16px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #fff;
}

.coverage-count.status-green .coverage-dot {
  border-color: #15803d;
  background: #22c55e;
}

.coverage-count.status-yellow .coverage-dot {
  border-color: #ca8a04;
  background: #facc15;
}

.coverage-count.status-red .coverage-dot {
  border-color: #991b1b;
  background: #ff0000;
  box-shadow: 0 0 14px rgba(255, 0, 0, 0.8);
}

.coverage-row {
  display: grid;
  gap: 8px;
}

.alert-card.yellow {
  border-color: #facc15;
  background: #fffbeb;
}

.alert-card.red {
  border-color: #f87171;
  background: #fff1f2;
  animation: cardPulse 1.2s ease-in-out infinite;
}

.alert-head,
.request-head,
.message-head,
.roster-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.alert-title,
.request-title,
.roster-name {
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 850;
}

.alert-meta,
.request-meta,
.message-meta,
.roster-meta {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.countdown {
  font-variant-numeric: tabular-nums;
  font-weight: 900;
}

.roster-list,
.message-list,
.alert-list {
  display: grid;
  gap: 8px;
}

.roster-row {
  display: grid;
  gap: 8px;
}

.roster-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.ack-list {
  align-items: flex-start;
}

.ack-list .badge {
  border-radius: var(--tile-radius);
  white-space: normal;
}

.message-list {
  max-height: 360px;
  overflow: auto;
  padding-right: 2px;
}

.chat-panel {
  transition:
    box-shadow 120ms ease,
    transform 120ms ease;
}

.chat-panel.expanded {
  position: fixed;
  inset: 92px 18px 18px;
  z-index: 35;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
}

.chat-panel.expanded .panel-body {
  display: grid;
  min-height: 0;
  grid-template-rows: minmax(0, 1fr) auto;
}

.chat-panel.expanded .message-list {
  max-height: none;
}

.message {
  background: #fff;
}

.message.alert {
  border-color: #facc15;
}

.message.emergency {
  border-color: #f87171;
}

.message-text {
  margin: 6px 0 0;
  overflow-wrap: anywhere;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 10px;
}

.setting-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px;
  gap: 10px;
  align-items: center;
}

.map-builder .field {
  margin-bottom: 0;
}

.map-settings-form,
.area-form,
.area-editor {
  display: grid;
  gap: 10px;
}

.map-size-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.area-coord-grid {
  display: grid;
  grid-template-columns: minmax(58px, 0.9fr) repeat(4, minmax(48px, 1fr));
  gap: 7px;
}

.area-coord-grid.compact {
  grid-template-columns: minmax(68px, 1fr) auto auto;
}

.area-editor-list {
  display: grid;
  gap: 8px;
  max-height: 520px;
  overflow: auto;
  padding-right: 2px;
}

.area-editor {
  border: 1px solid var(--line);
  border-radius: var(--tile-radius);
  background: #fff;
  padding: 10px;
}

.area-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.zone-adjust-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.file-drop {
  display: grid;
  gap: 5px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--tile-radius);
  background: #fff;
  color: var(--muted);
  padding: 10px;
}

.file-drop input {
  width: 100%;
  color: var(--muted);
  font-size: 0.82rem;
}

.source-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.freeform-zone-tools,
.zone-list-panel,
.square-zone-builder {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--tile-radius);
  background: var(--panel-strong);
  padding: 10px;
}

.draw-zone-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(80px, 0.5fr) auto;
  gap: 8px;
  align-items: end;
}

.draw-zone-grid .field {
  margin-bottom: 0;
}

.overlay-zone-builder {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--tile-radius);
  background: var(--panel-strong);
  padding: 10px;
}

.zone-overlay {
  display: grid;
  min-width: 0;
  align-content: center;
  justify-items: center;
  gap: 2px;
  border: 1px solid rgba(35, 78, 112, 0.82);
  border-radius: var(--tile-radius);
  background: rgba(239, 246, 255, 0.76);
  color: #111827;
  padding: 7px;
  text-align: center;
  box-shadow: 0 8px 18px rgba(31, 41, 55, 0.12);
}

.zone-overlay.selected {
  border-color: var(--info);
  background: rgba(239, 246, 255, 0.9);
  box-shadow:
    0 0 0 2px rgba(37, 99, 235, 0.3),
    0 12px 24px rgba(31, 41, 55, 0.15);
}

.zone-overlay.drawing {
  pointer-events: none;
  border-style: dashed;
  border-color: var(--green);
  background: rgba(220, 252, 231, 0.56);
}

.zone-overlay span {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: 0.82rem;
  font-weight: 850;
}

.zone-overlay small {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 850;
}

.zone-overlay.editable {
  cursor: grab;
  touch-action: none;
}

.zone-overlay.dragging {
  cursor: grabbing;
  box-shadow: 0 12px 26px rgba(31, 41, 55, 0.2);
}

.resize-handle {
  position: absolute;
  width: 15px;
  height: 15px;
  border: 1px solid rgba(17, 24, 39, 0.45);
  border-radius: 4px;
  background: #fff;
}

.resize-handle.se {
  right: 4px;
  bottom: 4px;
  cursor: nwse-resize;
}

.selected-zone-editor {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.area-code-row {
  display: grid;
  grid-template-columns: minmax(74px, 0.3fr) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.zone-list {
  display: grid;
  gap: 7px;
  max-height: 220px;
  overflow: auto;
  padding-right: 2px;
}

.zone-list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--tile-radius);
  background: #fff;
  padding: 8px;
}

.zone-list-row.selected {
  border-color: #93c5fd;
  background: #eff6ff;
}

.zone-list-row strong,
.zone-list-row span {
  display: block;
  overflow-wrap: anywhere;
}

.zone-list-row span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.zone-cell-grid {
  display: grid;
  grid-template-columns: repeat(var(--map-cols, 8), minmax(28px, 1fr));
  grid-template-rows: repeat(var(--map-rows, 6), minmax(32px, 1fr));
  gap: 3px;
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: var(--tile-radius);
  background-color: #eef2f7;
  background-image:
    linear-gradient(90deg, rgba(216, 222, 232, 0.52) 1px, transparent 1px),
    linear-gradient(180deg, rgba(216, 222, 232, 0.52) 1px, transparent 1px),
    var(--map-background, none);
  background-position:
    0 0,
    0 0,
    center;
  background-repeat:
    repeat,
    repeat,
    no-repeat;
  background-size:
    calc(100% / var(--map-cols, 8)) calc(100% / var(--map-rows, 6)),
    calc(100% / var(--map-cols, 8)) calc(100% / var(--map-rows, 6)),
    contain;
  padding: 5px;
}

.zone-cell {
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(100, 116, 139, 0.55);
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.58);
  color: #111827;
  padding: 0;
  font-size: 0.68rem;
  font-weight: 900;
}

.zone-cell.assigned {
  border-color: rgba(35, 78, 112, 0.82);
  background: rgba(219, 234, 254, 0.72);
}

.zone-cell-grid.has-map-image .zone-cell {
  background: rgba(255, 255, 255, 0.28);
}

.zone-cell-grid.has-map-image .zone-cell.assigned {
  background: rgba(219, 234, 254, 0.34);
}

.zone-cell.selected {
  border-color: #15803d;
  background: rgba(22, 163, 74, 0.78);
  color: #fff;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.34);
}

.mic-meter {
  display: grid;
  gap: 6px;
}

.meter-track {
  position: relative;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
}

.meter-fill {
  width: var(--level, 0%);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--red));
  transition: width 80ms linear;
}

.empty-state {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.google-signin-slot {
  min-height: 44px;
}

.auth-message,
.auth-error {
  margin: 0;
  border-radius: var(--tile-radius);
  padding: 10px 12px;
  font-size: 0.88rem;
}

.auth-message {
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
}

.auth-error {
  border: 1px solid #fecaca;
  background: var(--red-soft);
  color: #991b1b;
}

.access-list {
  display: grid;
  gap: 8px;
}

.access-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--tile-radius);
  background: var(--panel-strong);
  padding: 10px;
}

.access-profile {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.access-avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 50%;
  object-fit: cover;
}

.access-avatar.fallback {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--brand);
  font-size: 0.75rem;
  font-weight: 900;
}

.access-name,
.access-email {
  overflow: hidden;
  margin: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.access-name {
  font-weight: 800;
}

.access-email {
  color: var(--muted);
  font-size: 0.82rem;
}

.access-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.critical-banner {
  display: none;
  max-width: 1440px;
  margin: 0 auto 14px;
  border: 1px solid #f87171;
  border-radius: var(--radius);
  background: #fff1f2;
  padding: 12px 14px;
}

.critical-banner.active {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.critical-title {
  margin: 0;
  color: #991b1b;
  font-weight: 900;
}

.critical-meta {
  margin: 3px 0 0;
  color: #7f1d1d;
  font-size: 0.9rem;
}

.login-map-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.offline {
  opacity: 0.66;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes redPulse {
  0%,
  100% {
    box-shadow:
      0 0 0 4px rgba(255, 255, 255, 0.72),
      0 0 24px rgba(255, 0, 0, 0.84);
  }
  50% {
    box-shadow:
      0 0 0 6px rgba(255, 255, 255, 0.9),
      0 0 42px rgba(255, 0, 0, 1);
  }
}

@keyframes cardPulse {
  0%,
  100% {
    border-color: #f87171;
  }
  50% {
    border-color: #dc2626;
  }
}

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: minmax(320px, 1fr) minmax(360px, 1fr);
  }

  .operator-layout {
    grid-template-columns: minmax(360px, 1fr) minmax(320px, 0.9fr);
  }

  .layout > aside:last-child {
    grid-column: 1 / -1;
  }

  .admin-drawer[open] {
    min-width: 0;
  }

  .login-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .layout,
  .login-layout {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 10px;
  }

  .operator-layout {
    grid-template-columns: 1fr;
  }

  .panel-header,
  .panel-body {
    padding: 12px;
  }

  .building-map,
  .map-canvas {
    grid-template-columns: repeat(var(--map-cols, 8), minmax(42px, 1fr));
    grid-template-rows: repeat(var(--map-rows, 6), minmax(58px, 1fr));
    min-height: 360px;
  }

  .map-console .map-canvas {
    height: clamp(235px, 42vh, 330px);
    min-height: 235px;
  }

  .area-tile {
    min-height: 0;
    padding: 6px;
  }

  .area-name {
    font-size: 0.78rem;
  }

  .area-meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
    font-size: 0.68rem;
  }

  .command-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .command-button {
    min-height: 72px;
    justify-items: center;
    padding: 9px 4px;
    text-align: center;
  }

  .command-button svg {
    width: 23px;
    height: 23px;
  }

  .command-button span {
    margin-top: 4px;
    font-size: 0.9rem;
  }

  .command-button small {
    margin-top: 1px;
    font-size: 0.65rem;
  }

  .coverage-legend {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .coverage-count {
    padding: 7px 2px;
  }

  .chat-panel.expanded {
    inset: 86px 10px 94px;
  }

  .admin-drawer,
  .admin-drawer[open] {
    min-width: 0;
  }

  .chat-form,
  .setting-row,
  .map-size-grid,
  .draw-zone-grid,
  .area-code-row,
  .zone-list-row,
  .access-row,
  .area-coord-grid,
  .area-coord-grid.compact,
  .zone-adjust-grid {
    grid-template-columns: 1fr;
  }

  .access-actions {
    justify-content: flex-start;
  }
}
