/* Shared components and page building blocks, ported from
   CentsysAssetTrackingPortal (StatCard, Modal, manage & overview pages). */

/* ---- Page scaffolding ------------------------------------------------ */
.page {
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.heading {
  font-size: 19px;
}
.sub {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 14px;
}
.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
}
.grid-form {
  display: grid;
  grid-template-columns: minmax(320px, 400px) 1fr;
  gap: 18px;
  align-items: start;
}

/* ---- Stat cards ------------------------------------------------------ */
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}
a.stat {
  color: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
a.stat:hover {
  text-decoration: none;
  border-color: var(--green-400);
  box-shadow: var(--shadow-md);
}
.stat-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.stat-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.stat-value {
  font-family: var(--font-head);
  font-size: 28px;
  font-weight: 800;
  color: var(--ink-800);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat-hint {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
}
.stat.green .stat-icon {
  background: var(--green-100);
  color: var(--green-700);
}
.stat.ink .stat-icon {
  background: var(--grey-100);
  color: var(--ink-600);
}
.stat.amber .stat-icon {
  background: var(--warning-bg);
  color: #b07c06;
}
.stat.red .stat-icon {
  background: var(--danger-bg);
  color: var(--danger);
}
.stat.emphasis {
  border-left: 4px solid var(--green-500);
}
.stat.emphasis.red {
  border-left-color: var(--danger);
}
.stat.emphasis.amber {
  border-left-color: var(--warning);
}
.stat.red {
  --pulse: rgba(217, 75, 70, 0.35);
}
.stat.pulse {
  animation: statPulse 1.8s ease-in-out infinite;
}
@keyframes statPulse {
  0%,
  100% {
    box-shadow: var(--shadow-sm);
  }
  50% {
    box-shadow: var(--shadow-sm), 0 0 0 5px var(--pulse);
  }
}
@media (prefers-reduced-motion: reduce) {
  .stat.pulse {
    animation: none;
    box-shadow: var(--shadow-sm), 0 0 0 3px var(--pulse);
  }
}

/* ---- Panels ---------------------------------------------------------- */
.panel {
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.panel-head h3 {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 15px;
}
.panel-head h3 svg {
  color: var(--green-600);
}
.panel-head.danger h3 svg {
  color: var(--danger);
}
.panel-body {
  padding: 20px;
}
.panel-foot {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

/* ---- Alert / list items ---------------------------------------------- */
.item-list {
  list-style: none;
  margin: 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  border-left: 4px solid var(--grey-300);
  background: var(--surface);
}
.item.critical {
  border-left-color: var(--danger);
  background: #fdf3f2;
}
.item.warning {
  border-left-color: var(--warning);
  background: #fefaf0;
}
.item.ok {
  border-left-color: var(--green-600);
}
[data-theme='dark'] .item.critical {
  background: rgba(217, 75, 70, 0.12);
}
[data-theme='dark'] .item.warning {
  background: rgba(232, 164, 23, 0.1);
}
.item-main {
  flex: 1;
  min-width: 0;
}
.item-top {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}
.item-title {
  font-weight: 700;
  font-size: 14.5px;
  color: var(--ink-800);
}
.item-time {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.item-detail {
  margin: 0 0 3px;
  font-size: 13.5px;
  color: var(--ink-600);
  overflow-wrap: anywhere;
}
.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 600;
}
.item-meta span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.item-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

/* Operator details block inside an alarm card. */
.details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px 18px;
  margin-top: 10px;
}
.details dt {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.details dd {
  margin: 1px 0 0;
  font-size: 13.5px;
  color: var(--ink-800);
  overflow-wrap: anywhere;
}

/* ---- Tables ---------------------------------------------------------- */
.badge,
.nowrap {
  white-space: nowrap;
}
.primary-cell {
  display: flex;
  flex-direction: column;
}
.primary-name {
  font-weight: 600;
  color: var(--ink-800);
}
.primary-sub {
  font-size: 12.5px;
  color: var(--text-muted);
}
.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}
.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 7px;
  line-height: 0;
  color: var(--ink-500);
  transition: background-color 0.14s ease, color 0.14s ease;
}
.icon-btn:hover {
  background: var(--grey-100);
  color: var(--ink-700);
}
.icon-btn.danger:hover {
  background: var(--danger-bg);
  color: var(--danger);
}
/* Several badges in one cell, e.g. a gate with a tamper and a beam alarm open. */
.badge-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.table tr.alarmed td {
  background: #fdf3f2;
}
[data-theme='dark'] .table tr.alarmed td {
  background: rgba(217, 75, 70, 0.1);
}

/* Countdown chip for running access. */
.countdown {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--green-700);
}
.countdown.low {
  color: #b07c06;
}
.countdown.ended {
  color: var(--text-muted);
}
[data-theme='dark'] .countdown {
  color: var(--green-400);
}
[data-theme='dark'] .countdown.low {
  color: #f0c66a;
}
.progress {
  height: 4px;
  border-radius: 999px;
  background: var(--grey-100);
  overflow: hidden;
  margin-top: 6px;
  width: 120px;
}
.progress > span {
  display: block;
  height: 100%;
  background: var(--green-500);
  transition: width 1s linear;
}
.progress.low > span {
  background: var(--warning);
}

/* Search box with leading icon. */
.search {
  position: relative;
  display: flex;
  align-items: center;
}
.search svg {
  position: absolute;
  left: 11px;
  color: var(--grey-400);
  pointer-events: none;
}
.search .input {
  padding-left: 34px;
  min-width: 240px;
}

/* Chip filters. */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}
.chip:hover {
  border-color: var(--green-400);
}
.chip.active {
  border-color: var(--green-500);
  background: var(--green-50);
  color: var(--green-700);
}
[data-theme='dark'] .chip.active {
  background: rgba(129, 195, 65, 0.12);
  color: var(--green-400);
}
.chip-count {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  color: var(--ink-700);
}

/* ---- Forms ----------------------------------------------------------- */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-grid .full {
  grid-column: 1 / -1;
}
.field-hint {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}
.duration-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.duration-pick {
  padding: 7px 12px;
  border: 1px solid var(--grey-300);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-700);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.duration-pick:hover {
  border-color: var(--green-400);
  background: var(--green-50);
}
.duration-pick.active {
  border-color: var(--green-500);
  background: var(--green-500);
  color: #fff;
}
[data-theme='dark'] .duration-pick:hover:not(.active) {
  background: rgba(129, 195, 65, 0.1);
}
.input-suffix {
  display: flex;
  align-items: center;
  gap: 8px;
}
.input-suffix .input {
  width: 110px;
}

.notice {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.45;
}
.notice svg {
  flex-shrink: 0;
  margin-top: 1px;
}
.notice-error {
  border: 1px solid var(--danger);
  background: #fdf3f2;
  color: var(--danger);
}
.notice-success {
  border: 1px solid var(--green-500);
  background: var(--green-50);
  color: var(--green-800);
}
.notice-info {
  border: 1px solid var(--grey-300);
  background: var(--grey-50);
  color: var(--ink-600);
  font-weight: 500;
}
.notice-warning {
  border: 1px solid var(--warning);
  background: var(--warning-bg);
  color: #8a5e03;
}
[data-theme='dark'] .notice-error {
  background: rgba(217, 75, 70, 0.12);
  color: #f0a6a3;
}
[data-theme='dark'] .notice-success {
  background: rgba(129, 195, 65, 0.1);
  color: #b6e08a;
}
[data-theme='dark'] .notice-warning {
  background: rgba(232, 164, 23, 0.1);
  color: #f0c66a;
}
.notice-dismiss {
  margin-left: auto;
  background: transparent;
  border: none;
  color: inherit;
  padding: 0;
  line-height: 0;
  opacity: 0.7;
}
.notice-dismiss:hover {
  opacity: 1;
}

/* Big enrolment code. */
.code-display {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 8px 0 16px;
}
.code-digit {
  width: 46px;
  height: 58px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--green-500);
  background: var(--green-50);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-head);
  font-size: 28px;
  font-weight: 800;
  color: var(--ink-800);
}
[data-theme='dark'] .code-digit {
  background: rgba(129, 195, 65, 0.1);
}

pre.code-block {
  margin: 0;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--grey-50);
  font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ink-800);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Activity feed. */
.feed {
  list-style: none;
  margin: 0;
  padding: 6px 0;
}
.feed li {
  display: flex;
  gap: 12px;
  padding: 10px 20px;
  font-size: 13.5px;
}
.feed li + li {
  border-top: 1px solid var(--grey-100);
}
.feed-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--grey-100);
  color: var(--ink-600);
}
.feed-icon.green {
  background: var(--green-100);
  color: var(--green-700);
}
.feed-icon.red {
  background: var(--danger-bg);
  color: var(--danger);
}
.feed-icon.amber {
  background: var(--warning-bg);
  color: #b07c06;
}
.feed-main {
  flex: 1;
  min-width: 0;
  color: var(--ink-700);
  overflow-wrap: anywhere;
}
.feed-time {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---- Modal ----------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(29, 33, 37, 0.5);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 7vh 16px 16px;
  z-index: 100;
  animation: fadeIn 0.12s ease;
}
.modal {
  width: 100%;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: pop 0.14s ease;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 {
  font-size: 18px;
}
.modal-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}
.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  line-height: 0;
}
.modal-close:hover {
  background: var(--grey-100);
  color: var(--ink-700);
}
.modal-body {
  padding: 22px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  background: var(--grey-50);
  flex-shrink: 0;
}
@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
  }
}

/* ---- Responsive ------------------------------------------------------ */
@media (max-width: 1360px) {
  .grid-form {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 1180px) {
  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 560px) {
  .cards {
    grid-template-columns: 1fr;
  }
  .toolbar {
    align-items: stretch;
  }
  .actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }
  .search,
  .search .input {
    width: 100%;
    min-width: 0;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .item {
    flex-wrap: wrap;
  }
  .item-actions {
    flex-direction: row;
    width: 100%;
  }
  .item-actions .btn {
    flex: 1;
  }
  .modal-overlay {
    padding: 16px 12px;
    align-items: center;
  }
}

/* Enrolment QR code: kept on white so phone cameras read it in dark mode too. */
.qr-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 0 0 16px;
  font-size: 13px;
  text-align: center;
}
.qr-block img {
  background: #fff;
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  image-rendering: pixelated;
}
.block {
  display: block;
}

/* ---- Sign-in and "Confirm it's you" ------------------------------------ */
fieldset.field {
  border: none;
  margin: 0;
  padding: 0;
  min-width: 0;
}
fieldset.field legend {
  padding: 0;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-700);
}
.input-lg {
  height: 46px;
  font-size: 16px;
}
.btn-block {
  width: 100%;
  justify-content: center;
  height: 44px;
}

/* Two-way choice (WhatsApp or SMS): radio labels in the sign-in form, buttons in the dialog. */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.segment {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  border: 1px solid var(--grey-300);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-700);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.segment input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.segment:hover {
  border-color: var(--green-400);
}
.segment.active,
.segment:has(input:checked) {
  border-color: var(--green-500);
  background: var(--green-50);
  color: var(--green-800);
  box-shadow: inset 0 0 0 1px var(--green-500);
}
.segment:has(input:focus-visible) {
  outline: 2px solid var(--green-500);
  outline-offset: 2px;
}
[data-theme='dark'] .segment.active,
[data-theme='dark'] .segment:has(input:checked) {
  background: rgba(129, 195, 65, 0.12);
  color: var(--green-400);
}

/* The 4-digit OTP: big, spaced digits that are easy to type on a phone. */
.otp-input {
  height: 54px;
  max-width: 200px;
  font-family: var(--font-head);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.5em;
  text-align: center;
  padding-left: 0.5em;
  font-variant-numeric: tabular-nums;
}

/* A dialog opened over another dialog (e.g. "Confirm it's you" over "Add guard"). */
.modal-overlay.modal-top {
  z-index: 110;
}

/* ---- Roles ------------------------------------------------------------ */
.role-picks {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.role-pick {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--grey-300);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
}
.role-pick input {
  margin-top: 3px;
  accent-color: var(--green-600);
}
.role-pick.active {
  border-color: var(--green-500);
  background: var(--green-50);
}
[data-theme='dark'] .role-pick.active {
  background: rgba(129, 195, 65, 0.1);
}
.role-pick-text {
  display: flex;
  flex-direction: column;
  line-height: 1.35;
}
.role-pick-name {
  font-weight: 700;
  color: var(--ink-800);
}
.role-pick-hint {
  font-size: 12.5px;
  color: var(--text-muted);
}
