:root {
  --bg-deep: #131319;
  --bg-mid: #1b1c24;
  --surface: rgba(255, 255, 255, 0.05);
  --surface-strong: rgba(28, 29, 36, 0.82);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f2f3f7;
  --text-muted: #9a9aa8;
  --header-text: #ffffff;
  --accent: #03d100;
  --accent-soft: rgba(3, 209, 0, 0.14);
  --accent-border: rgba(3, 209, 0, 0.45);
  --accent-hover: #029d00;
  --accent-text: #081400;
  --ok: #03d100;
  --ok-soft: rgba(3, 209, 0, 0.14);
  --pending: #fbbf24;
  --pending-soft: rgba(251, 191, 36, 0.16);
  --danger: #f87171;
  --danger-strong: #ef4444;
  --danger-hover: #dc2626;
  --radius: 16px;
  --radius-lg: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

/* .field's own `display: flex` has equal specificity to the browser's
   default [hidden] rule, and ours loads later — without this, an element
   that is both class="field" and [hidden] stays visible. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-deep);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(900px circle at 15% -10%, rgba(3, 209, 0, 0.10) 0%, rgba(3, 209, 0, 0) 55%),
    radial-gradient(700px circle at 100% 0%, rgba(3, 209, 0, 0.06) 0%, rgba(3, 209, 0, 0) 50%),
    linear-gradient(180deg, var(--bg-mid) 0%, var(--bg-deep) 55%);
}

/* ---------------------------------------------------------------- top-level screens
   (splash, create account, login, change pin, account list, dashboard) */
.view {
  display: none;
  flex: 1 1 auto;
}

.view.active {
  display: flex;
  flex-direction: column;
}

.center-card {
  margin: auto;
  width: 100%;
  max-width: 360px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.app-title {
  text-align: center;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin: 0 0 12px;
}

.app-title-light {
  font-weight: 400;
  color: var(--text);
}

.view-title {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 700;
  color: #ffffff;
}

.view-hint {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 8px;
}

form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-label {
  font-size: 12px;
  color: var(--text-muted);
}

.field input,
.field select {
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 0 12px;
  font-size: 15px;
}

.field input::placeholder {
  color: #6b6b78;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
}

.field input.field-error {
  border-color: var(--danger-strong);
}

.field input.field-error:focus {
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.2);
}

/* Fixed "+254" prefix — the user only ever types the 9-digit local part, so
   the "+2540721..." leading-zero mistake isn't something they can type at
   all, not just something we validate after the fact. */
.phone-input-wrap {
  display: flex;
  align-items: stretch;
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.04);
  overflow: hidden;
}

.phone-input-wrap:focus-within {
  border-color: var(--accent);
}

.phone-prefix {
  display: flex;
  align-items: center;
  padding: 0 10px;
  color: var(--text-muted);
  font-size: 15px;
  background: rgba(255, 255, 255, 0.05);
  border-right: 1px solid var(--border-strong);
}

.phone-input-wrap input {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  border: none;
  background: none;
  color: var(--text);
  padding: 0 12px;
  font-size: 15px;
}

.phone-input-wrap input:focus {
  outline: none;
}

.time12-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.time12-wrap input,
.time12-wrap select {
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 0 8px;
  font-size: 15px;
}

.time12-wrap input {
  width: 56px;
  text-align: center;
}

/* Hide the native up/down spinner arrows — typing is the only way to change
   these fields, not scrolling or clicking. */
.time12-wrap input::-webkit-outer-spin-button,
.time12-wrap input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.time12-wrap input[type="number"] {
  -moz-appearance: textfield;
}

.time12-wrap input:focus,
.time12-wrap select:focus {
  outline: none;
  border-color: var(--accent);
}

.time12-colon {
  color: var(--text-muted);
  font-weight: 700;
}

/* The dropdown's open option list is a native popup that doesn't inherit
   the select's own background — style it explicitly everywhere, or options
   render as light-on-light in most browsers. */
select option {
  background: var(--surface-strong);
  color: var(--text);
}

.btn {
  height: 44px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 60%), var(--accent);
  color: var(--accent-text);
}

.btn-primary:active {
  background: var(--accent-hover);
}

.btn:disabled {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  cursor: not-allowed;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-danger {
  background: var(--danger-strong);
  color: #fff;
}

.btn-danger:active {
  background: var(--danger-hover);
}

.btn-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 8px;
  vertical-align: -2px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: currentColor;
  animation: spin 0.8s linear infinite;
}

.btn-spinner[hidden] {
  display: none;
}

.btn-link {
  background: none;
  color: var(--text-muted);
  height: auto;
  padding: 8px 0;
  text-decoration: underline;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.account-item {
  height: 48px;
  border-radius: 10px;
  border: 1px solid var(--accent-border);
  background: var(--accent-soft);
  color: #a7efa6;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  padding: 0 14px;
}

.account-item:active {
  background: rgba(3, 209, 0, 0.24);
}

/* ---------------------------------------------------------------- dashboard header */
.topbar {
  flex: 0 0 auto;
  background: rgba(20, 21, 27, 0.72);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  backdrop-filter: blur(20px) saturate(140%);
  color: var(--header-text);
  padding: calc(14px + var(--safe-top)) 16px 0;
  border-bottom: 1px solid var(--border);
}

.topbar-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 14px;
}

.topbar-title {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  order: 2;
}

.topbar-account-name {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
  flex: 0 1 auto;
  order: 1;
  line-height: 1;
}

/* Below this width, title + account name + both icons can't all fit on one
   line without cramming — drop the account name to its own smaller row
   under the title instead, so the icons and title both keep their full
   size and the title never gets clipped. */
@media (max-width: 420px) {
  .topbar-row {
    gap: 2px 10px;
  }

  .topbar-account-name {
    flex: 1 1 100%;
    order: 3;
    max-width: none;
    font-size: 11px;
  }
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.02));
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn:active {
  background: rgba(255, 255, 255, 0.18);
}

.icon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.tabs {
  display: flex;
  gap: 3px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px;
  margin-bottom: 12px;
}

.tab-btn {
  flex: 1 1 0;
  border: none;
  border-radius: 9px;
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  padding: 9px 0;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab-btn.active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.13);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 4px rgba(0, 0, 0, 0.3);
}

/* Each tab's own scrollable content area — deliberately named differently
   from the top-level .view/.view.active pair above (which the six main app
   screens use) so the two switching systems can never collide. */
.tab-panel {
  display: none;
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 14px calc(24px + var(--safe-bottom));
}

.tab-panel.active {
  display: block;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.search-wrap {
  flex: 1 1 auto;
  min-width: 0;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 16px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.search-icon {
  flex: 0 0 auto;
  display: flex;
  color: var(--text-muted);
}

.search-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  border: none;
  background: none;
  outline: none;
  color: var(--text);
  font-size: 14px;
  padding: 0;
}

.search-input::placeholder {
  color: #6b6b78;
}

.search-clear {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}

.search-clear:active {
  background: rgba(255, 255, 255, 0.18);
  color: var(--text);
}

.toolbar-add {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.02));
  color: #ffffff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.toolbar-add:active {
  background: rgba(255, 255, 255, 0.18);
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-action {
  border: none;
  font-family: inherit;
  cursor: pointer;
}

.badge-ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge-pending {
  background: var(--pending-soft);
  color: var(--pending);
}

.badge-neutral {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  margin-top: 60px;
  padding: 0 20px;
}

.empty-state p {
  margin: 4px 0;
}

.empty-state-hint {
  font-size: 13px;
}

/* Entity card: a thin, scannable row by default. Tapping the row expands
   it downward to reveal details and actions. Shared by user and device
   rows so both look and behave identically. */
.entity-card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 8px 20px -12px rgba(0, 0, 0, 0.6);
  transition: border-color 0.15s ease;
}

.entity-card.expanded {
  border-color: var(--border-strong);
}

.entity-row-top {
  width: 100%;
  border: none;
  background: none;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font: inherit;
}

.entity-row-top:active {
  background: rgba(255, 255, 255, 0.04);
}

.entity-info {
  flex: 1 1 auto;
  min-width: 0;
}

.user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-external-id {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}

.fingerprint-indicator {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
}

.device-imei {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-imei.connected {
  color: var(--text);
}

.device-imei.not-connected {
  color: #55555f;
}

.device-detail {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.device-contact-warning {
  margin-top: 12px;
  font-size: 12px;
  color: var(--danger);
}

.entity-expanded {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  padding: 0 14px;
  transition: max-height 0.22s ease, opacity 0.18s ease, padding 0.22s ease;
}

.entity-card.expanded .entity-expanded {
  max-height: 220px;
  opacity: 1;
  padding: 0 14px 14px;
}

.entity-expanded.icon-indent {
  padding-left: 54px;
}

.entity-card.expanded .entity-expanded.icon-indent {
  padding-left: 54px;
}

.row-actions {
  display: flex;
  gap: 4px;
  margin-top: 10px;
}

.delete-row-btn,
.edit-row-btn {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 10px 2px;
  cursor: pointer;
}

.delete-row-btn:active {
  color: var(--danger);
}

.edit-row-btn:active {
  color: var(--accent);
}

.biometric-chip {
  width: 100%;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.biometric-chip.not-enrolled {
  background: var(--accent-soft);
  border: 1.5px solid var(--accent-border);
  color: #a7efa6;
}

.biometric-chip.enrolled {
  background: var(--ok-soft);
  border: 1px solid rgba(3, 209, 0, 0.3);
  color: #a7efa6;
  cursor: default;
}

.chip-icon {
  font-size: 14px;
}

.chip-label {
  flex: 1 1 auto;
  text-align: left;
}

.user-actions {
  justify-content: flex-end;
  gap: 4px;
}

.user-actions .edit-row-btn,
.user-actions .delete-row-btn {
  flex: 0 0 auto;
  padding: 10px 6px;
  font-size: 11px;
  white-space: nowrap;
}

.user-actions .delete-row-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

/* ---------------------------------------------------------------- popups
   A fixed-size window that drops down from the top of the screen, used for
   every popup (add user, add device, confirm, enroll) so they all share one
   consistent format. */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 6, 10, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: calc(88px + var(--safe-top));
  z-index: 100;
}

.sheet {
  background: var(--surface-strong);
  -webkit-backdrop-filter: blur(24px) saturate(140%);
  backdrop-filter: blur(24px) saturate(140%);
  border: 1px solid var(--border-strong);
  width: min(90vw, 340px);
  max-height: calc(100vh - 88px - var(--safe-top) - 24px);
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.65);
  animation: popup-in 0.18s ease-out;
}

.sheet-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: #ffffff;
}

.schedule-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
}

@keyframes popup-in {
  from { opacity: 0; transform: translateY(-14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.sheet-actions {
  display: flex;
  gap: 12px;
}

/* Side-by-side buttons inside a popup should share width equally,
   regardless of how long their label is — the standalone full-width
   buttons on the main app screens don't have this ancestor, so they're
   unaffected. */
.sheet-actions .btn {
  flex: 1 1 0;
}

.confirm-message {
  font-size: 15px;
  margin: 0;
  color: var(--text);
}

/* Biometric enrollment scan step — sits inside the same .sheet popup as
   the confirm step, just centered instead of left-aligned. */
.scan-step {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.scan-spinner {
  width: 22px;
  height: 22px;
  margin: 0 auto;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.scan-message {
  font-size: 15px;
  color: var(--text);
  margin: 0;
}

.scan-timer {
  font-size: 40px;
  font-weight: 700;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
}

.scan-timer-small {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0;
}

.enroll-check-error {
  font-size: 13px;
  color: var(--pending);
  margin: 0;
}

.enroll-step-btn {
  width: 100%;
  display: block;
}

/* ---------------------------------------------------------------- toasts */
.toast-container {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(20px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 300;
  pointer-events: none;
}

.toast {
  background: var(--surface-strong);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--border-strong);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  max-width: 86vw;
  text-align: center;
  box-shadow: 0 8px 20px -8px rgba(0, 0, 0, 0.6);
  animation: toast-in 0.15s ease-out;
}

.toast.toast-error {
  background: rgba(127, 29, 29, 0.85);
  border-color: rgba(248, 113, 113, 0.4);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
