:root {
  color-scheme: dark light;
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #21262d;
  --border: #30363d;
  --text: #f0f6fc;
  --muted: #8b949e;
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.14);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.14);
  --info-bg: rgba(56, 189, 248, 0.14);
  --radius: 16px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa;
    --surface: #ffffff;
    --surface-2: #f0f3f6;
    --border: #d0d7de;
    --text: #1f2328;
    --muted: #59636e;
    --accent: #0969da;
    --accent-strong: #0550ae;
    --success: #1a7f37;
    --success-bg: rgba(26, 127, 55, 0.12);
    --danger: #cf222e;
    --danger-bg: rgba(207, 34, 46, 0.1);
    --info-bg: rgba(9, 105, 218, 0.1);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

.shell {
  max-width: 540px;
  margin-inline: auto;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(2rem, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-block-end: 1.25rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand-icon {
  border-radius: 6px;
}

.brand-name {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.card h1,
.card h2 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
  line-height: 1.3;
}

.card h1 {
  font-size: 1.35rem;
}

.centered {
  text-align: center;
}

.centered-text {
  text-align: center;
}

.muted {
  color: var(--muted);
  margin: 0 0 1rem;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.35rem 0 0;
}

.eyebrow {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 0.35rem;
}

/* Status Pill */
.status-row,
.row-between,
.qr-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.95rem;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
}

.status-in {
  color: var(--success);
  background: var(--success-bg);
}

.status-out {
  color: var(--muted);
  background: var(--surface-2);
}

.status-unknown {
  color: var(--accent);
  background: var(--info-bg);
}

/* QR Stage */
.qr-stage {
  display: flex;
  justify-content: center;
  margin-block: 1rem;
}

.qr-frame {
  position: relative;
  background: #ffffff;
  padding: 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  width: min(332px, 100%);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.qr-frame img {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  transition: filter 0.2s ease, opacity 0.2s ease;
}

.qr-frame.is-stale img {
  filter: blur(12px);
  opacity: 0.35;
}

.qr-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: rgba(13, 17, 23, 0.72);
  color: #ffffff;
  padding: 1rem;
  text-align: center;
}

.qr-overlay-title {
  margin: 0;
  font-weight: 700;
  font-size: 1.05rem;
}

.qr-placeholder {
  width: 100%;
  min-height: 220px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.75rem;
  background: var(--surface-2);
}

.qr-controls {
  margin-block-start: 0.75rem;
}

/* Forms & Controls */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-block-end: 1.1rem;
}

.label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

label {
  font-weight: 600;
  font-size: 0.95rem;
}

input[type="text"],
input[type="password"],
input[type="time"],
input[type="number"],
select {
  font: inherit;
  font-size: max(1rem, 1em);
  min-height: 48px;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  width: 100%;
}

input:user-invalid {
  border-color: var(--danger);
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  margin-block: 0.5rem;
}

.checkbox-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  min-width: 22px;
  margin-top: 2px;
  accent-color: var(--accent);
  cursor: pointer;
}

.checkbox-row label {
  font-weight: 500;
  cursor: pointer;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font: inherit;
  font-size: max(0.95rem, 1em);
  font-weight: 600;
  min-height: 48px;
  padding: 0.6rem 1rem;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

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

.btn-full {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: #04131c;
}

@media (prefers-color-scheme: light) {
  .btn-primary {
    color: #ffffff;
  }
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-strong);
  color: #ffffff;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
  min-height: 40px;
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger);
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.25rem 0;
  cursor: pointer;
}

.btn-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Alerts */
.alert {
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  font-size: 0.92rem;
  margin-block: 0.75rem;
}

.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.alert-info {
  background: var(--info-bg);
  color: var(--text);
  border: 1px solid var(--accent);
}

.alert-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success);
}

/* Check-ins list */
.checkins-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.checkin-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  background: var(--surface-2);
}

.checkin-kind {
  font-weight: 600;
}

.checkin-kind-in {
  color: var(--success);
}

.checkin-kind-out {
  color: var(--muted);
}

/* Native Modal Dialog */
dialog {
  width: min(560px, calc(100vw - 1.5rem));
  max-height: calc(100dvh - 2rem);
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  overflow: auto;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
  overflow: hidden;
  overscroll-behavior: contain;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-block-end: 1rem;
}

.dialog-header h1 {
  margin: 0;
  font-size: 1.2rem;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-block-start: 1.25rem;
}

.settings-section {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin: 0 0 1rem;
}

.settings-section legend {
  font-weight: 700;
  padding-inline: 0.35rem;
}

.pause-row {
  margin-block: 0.75rem 1rem;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  background: var(--surface-2);
}

.schedule-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.schedule-day {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  background: var(--bg);
}

.schedule-day-title {
  font-weight: 700;
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.schedule-blocks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

@media (max-width: 460px) {
  .schedule-blocks {
    grid-template-columns: 1fr;
  }
}

.schedule-block-cell {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.schedule-block-cell input[type="time"] {
  min-height: 44px;
  padding: 0.4rem 0.6rem;
}
