/* dom - design foundation.
 *
 * Design decisions, briefly:
 * - Dark by default: this app is opened at night, at a gate, on a phone.
 *   A white screen would be a flashlight to the face.
 * - Every color/size flows from the custom properties below, so Batch 7's
 *   dashboard reuses the same language instead of inventing its own.
 * - System font stack: CSP forbids external fonts, and native fonts look
 *   right on every phone anyway.
 * - Touch targets are >= 48px tall (Apple/Google both recommend ~44-48px).
 */

:root {
  /* surfaces, darkest to lightest */
  --bg: #0b0f14;
  --bg-glow: #101a26;
  --surface: #151c26;
  --surface-raised: #1b2432;
  --border: #2a3648;

  /* text */
  --text: #e8edf4;
  --text-dim: #8b98ab;

  /* brass - the accent. Keys, hinges, door handles. */
  --accent: #e8b44c;
  --accent-strong: #f0c46a;
  --accent-ink: #241a05;

  --danger: #e05d5d;
  --danger-bg: rgba(224, 93, 93, 0.12);
  --ok: #55b87a;

  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  /* a faint glow rising from the bottom, like a porch light */
  background: radial-gradient(120% 90% at 50% 110%, var(--bg-glow) 0%, var(--bg) 60%);
  min-height: 100dvh; /* dvh: tracks the real visible height on mobile */
}

.shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

/* --- login ---------------------------------------------------------- */

.login-card {
  width: 100%;
  max-width: 22rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 40px 28px 32px;
}

.brand { text-align: center; margin-bottom: 28px; }

.brand-mark {
  width: 44px;
  height: 44px;
  fill: var(--accent);
}

.brand-name {
  font-size: 28px;
  font-weight: 650;
  letter-spacing: 0.04em;
  margin-top: 6px;
}

.brand-sub {
  color: var(--text-dim);
  font-size: 13px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  margin-top: 2px;
}

.login-form { display: grid; gap: 14px; margin-top: 4px; }

/* --- form fields ---------------------------------------------------- */

.field { display: grid; gap: 6px; }

.field-label {
  font-size: 13px;
  font-weight: 550;
  color: var(--text-dim);
}

.field input {
  font: inherit;
  font-size: 16px; /* below 16px, iOS Safari zooms the page on focus */
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 14px;
  min-height: 48px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(232, 180, 76, 0.22);
}

/* --- buttons -------------------------------------------------------- */

.btn {
  font: inherit;
  font-size: 16px;
  font-weight: 650;
  border: none;
  border-radius: var(--radius);
  min-height: 50px;
  padding: 13px 18px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
}

.btn:active { transform: scale(0.985); }

.btn-primary {
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  color: var(--accent-ink);
}

.btn-primary:hover { filter: brightness(1.06); }

.btn-block { width: 100%; margin-top: 6px; }

/* --- notices -------------------------------------------------------- */

.notice {
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 14px;
  margin-bottom: 16px;
  text-align: center;
}

.notice-error {
  background: var(--danger-bg);
  border: 1px solid rgba(224, 93, 93, 0.35);
  color: #f2a9a9;
}

/* --- dashboard ------------------------------------------------------- */

.dash {
  width: 100%;
  max-width: 24rem;
  display: grid;
  gap: 30px;
  align-content: start;
}

.dash-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dash-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: 0.04em;
}

.dash-brand-mark { width: 24px; height: 24px; fill: var(--accent); }

.user-chip {
  font-size: 13px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
}

/* device cards */

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

.device {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  min-height: 78px;
  padding: 16px 18px;
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
}

.device:hover { border-color: var(--accent); }
.device:active { transform: scale(0.985); background: var(--surface-raised); }

.device-icon {
  flex: none;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(232, 180, 76, 0.12);
}

.device-icon svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.device-label { flex: 1; }

.device-chevron { color: var(--text-dim); font-size: 22px; }

/* footer actions */

.dash-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
}

.btn-ghost {
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  color: var(--text-dim);
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.btn-ghost:hover { color: var(--text); border-color: var(--text-dim); }

.btn-danger-ghost:hover,
.btn-danger-ghost.armed {
  color: var(--danger);
  border-color: var(--danger);
}

/* --- bottom sheet ---------------------------------------------------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none; /* inert until .open */
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 6, 10, 0.6);
  opacity: 0;
  transition: opacity 0.25s;
}

.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 26rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 24px 24px 0 0;
  padding: 26px 20px calc(30px + env(safe-area-inset-bottom));
  transform: translateY(105%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0.22, 1);
}

.sheet.open { pointer-events: auto; }
.sheet.open .sheet-backdrop { opacity: 1; }
.sheet.open .sheet-panel { transform: translateY(0); }

.sheet-title {
  font-size: 19px;
  font-weight: 650;
  text-align: center;
  margin-bottom: 22px;
}

.sheet-status {
  min-height: 20px;
  margin-top: 14px;
  text-align: center;
  font-size: 14px;
  color: var(--text-dim);
}

.sheet-status.error { color: var(--danger); }

.sheet-cancel { width: 100%; margin-top: 14px; }

/* --- slide to unlock -------------------------------------------------- */

.slider {
  position: relative;
  height: 64px;
  border-radius: 32px;
  background: var(--bg);
  border: 1px solid var(--border);
  overflow: hidden;
  touch-action: none;  /* dragging the thumb must not scroll the page */
  user-select: none;
  -webkit-user-select: none;
}

.slider-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 60px; /* JS grows this as the thumb travels */
  background: linear-gradient(90deg, rgba(232, 180, 76, 0.3), rgba(232, 180, 76, 0.06));
}

.slider-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding-left: 34px; /* visually centered in the space right of the thumb */
  font-size: 15px;
  letter-spacing: 0.02em;
  /* the iPhone shimmer: an animated gradient clipped to the glyphs */
  color: transparent;
  background: linear-gradient(90deg,
      var(--text-dim) 40%, #ffffff 50%, var(--text-dim) 60%) 0 0 / 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  animation: shimmer 2.4s linear infinite;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

.slider-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  cursor: grab;
  will-change: transform;
}

.slider-thumb:active { cursor: grabbing; }

/* released mid-way: animate the snap-back (JS toggles .settling) */
.slider.settling .slider-thumb { transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1); }
.slider.settling .slider-fill  { transition: width 0.3s cubic-bezier(0.22, 1, 0.36, 1); }

/* thumb icons: exactly one visible per state */
.thumb-icon {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: var(--accent-ink);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  grid-area: 1 / 1; /* stack all icons in the same cell */
  opacity: 0;
}

.slider .thumb-arrow { opacity: 1; }
.slider.pending .thumb-arrow,
.slider.success .thumb-arrow,
.slider.error .thumb-arrow { opacity: 0; }

.slider.pending .thumb-spinner { opacity: 1; }
.thumb-spinner { stroke-dasharray: 42 18; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.slider.success .thumb-check { opacity: 1; }
.slider.success .slider-thumb {
  background: linear-gradient(180deg, #6fcf92, var(--ok));
}
.slider.success .thumb-check { stroke: #06250f; }

.slider.error .thumb-cross { opacity: 1; }
.slider.error .slider-thumb {
  background: linear-gradient(180deg, #ec8080, var(--danger));
}
.slider.error .thumb-cross { stroke: #2b0808; }
.slider.error { animation: shake 0.35s; }

@keyframes shake {
  20% { transform: translateX(-7px); }
  45% { transform: translateX(6px); }
  70% { transform: translateX(-4px); }
  90% { transform: translateX(2px); }
}

/* while busy or done, the label and further input make no sense */
.slider.pending .slider-label,
.slider.success .slider-label,
.slider.error .slider-label { animation: none; color: transparent; background: none; }
.slider.pending, .slider.success { pointer-events: none; }

/* respect users who turn animations off */
@media (prefers-reduced-motion: reduce) {
  .slider-label { animation: none; color: var(--text-dim); background: none; }
  .thumb-spinner { animation-duration: 1.8s; }
  .sheet-panel, .sheet-backdrop { transition: none; }
}
