:root {
  --background: hsl(0, 0%, 98%);
  --foreground: hsl(220, 20%, 10%);
  --card: hsl(0, 0%, 100%);
  --card-foreground: hsl(220, 20%, 10%);
  --primary: hsl(221, 83%, 53%);
  --primary-foreground: hsl(0, 0%, 100%);
  --secondary: hsl(220, 14%, 96%);
  --secondary-foreground: hsl(220, 20%, 10%);
  --muted: hsl(220, 14%, 96%);
  --muted-foreground: hsl(220, 10%, 46%);
  --accent: hsl(221, 83%, 53%);
  --accent-foreground: hsl(0, 0%, 100%);
  --destructive: hsl(0, 84%, 60%);
  --border: hsl(220, 13%, 91%);
  --input: hsl(220, 13%, 91%);
  --ring: hsl(221, 83%, 53%);
  --radius: 0.75rem;
  --success: hsl(142, 71%, 45%);
  --pending: hsl(28, 92%, 50%);
  --pending-soft: hsla(28, 92%, 50%, 0.12);
}

*, *::before, *::after {
  box-sizing: border-box;
  border-color: var(--border);
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--background);
  color: var(--foreground);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

html[data-admin-logged-in] #loginView {
  display: none !important;
}

html[data-admin-logged-in] #adminPanel {
  display: block !important;
}

.view { display: none; min-height: 100vh; width: 100%; }
body[data-view="loading"] .view { display: none; }
body[data-view="notfound"] #view-notfound,
body[data-view="admin"] #view-admin,
body[data-view="voucher"] #view-voucher { display: flex; }

#view-notfound { flex-direction: column; }
#view-admin {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem 1rem;
}
#view-voucher {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    max(4.75rem, calc(env(safe-area-inset-top) + 3.75rem))
    0
    2rem;
  box-sizing: border-box;
}

/* ---- 404 ---- */

.notfound-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--background);
  border-bottom: 1px solid var(--border);
}

.notfound-nav-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 4rem;
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.notfound-nav-inner span {
  font-weight: 600;
  font-size: 1rem;
}

.notfound-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6rem 1.5rem 3rem;
  text-align: center;
}

.notfound-content h1 {
  font-size: clamp(4rem, 12vw, 7rem);
  font-weight: 700;
  line-height: 1;
  margin: 0 0 1rem;
  color: var(--foreground);
}

.notfound-content h2 {
  font-size: clamp(1.25rem, 3vw, 1.75rem);
  font-weight: 600;
  margin: 0 0 0.75rem;
}

.notfound-content p {
  color: var(--muted-foreground);
  font-size: 1rem;
  max-width: 28rem;
  margin: 0 auto;
  line-height: 1.6;
}

.notfound-footer {
  border-top: 1px solid var(--border);
  padding: 2rem 1.5rem;
  text-align: center;
}

.notfound-footer p {
  font-size: 0.75rem;
  color: var(--muted-foreground);
  margin: 0;
}

.logo-sm { width: 1.75rem; height: 1.75rem; }

/* ---- Admin ---- */

.admin-wrap {
  width: 100%;
  max-width: 24rem;
  margin: 0 auto;
  padding: 1rem 0;
}

.admin-header {
  text-align: center;
}

.admin-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
}

.admin-header p {
  color: var(--muted-foreground);
  font-size: 0.875rem;
  margin: 0.25rem 0 0;
}

.admin-login-card,
.admin-card {
  margin-top: 1.5rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 1.5rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

#adminPanel {
  display: flex;
  flex-direction: column;
  gap: 0;
}

#adminPanel .form-group:last-of-type {
  margin-bottom: 1.25rem;
}

.admin-panel-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  padding-top: 0.25rem;
  border-top: 1px solid var(--border);
}

.admin-panel-actions .error-msg {
  margin-top: 0;
}

.admin-panel-actions .cloud-badge {
  align-self: center;
  margin-top: 0;
}

.admin-panel-actions .admin-logout {
  align-self: center;
  margin-top: 0.25rem;
}

.admin-login-card h2 {
  font-size: 1.125rem;
  margin: 0 0 1rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
}

.input {
  width: 100%;
  height: 2.5rem;
  padding: 0 0.75rem;
  border: 1px solid var(--input);
  border-radius: calc(var(--radius) - 2px);
  background: var(--background);
  color: var(--foreground);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 2px hsla(221, 83%, 53%, 0.2);
}

.input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.input-action-btn {
  margin-top: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  font-family: inherit;
}

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

.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
  height: 2.5rem;
  padding: 0 1rem;
}

.btn-primary:hover:not(:disabled) {
  background: hsl(221, 83%, 48%);
}

.btn-outline {
  background: var(--background);
  color: var(--foreground);
  border: 1px solid var(--input);
  height: 2.5rem;
  padding: 0 1rem;
}

.btn-outline:hover:not(:disabled) {
  background: var(--muted);
}

.btn-ghost {
  background: transparent;
  color: var(--foreground);
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: calc(var(--radius) - 2px);
}

.btn-ghost:hover {
  background: var(--muted);
}

.btn-full { width: 100%; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

.link-result {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.625rem;
  padding: 0.875rem;
  background: var(--muted);
  border-radius: var(--radius);
  margin-top: 0;
}

.link-result a {
  width: 100%;
  font-size: 0.75rem;
  color: var(--primary);
  text-decoration: underline;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.link-result-btns {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.error-msg {
  color: var(--destructive);
  font-size: 0.875rem;
  margin-top: 0.75rem;
}

.cloud-badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  margin-top: 0.75rem;
}

.cloud-badge--wait { background: var(--muted); color: var(--muted-foreground); }
.cloud-badge--on { background: hsla(142, 71%, 45%, 0.15); color: var(--success); }
.cloud-badge--off { background: hsla(0, 84%, 60%, 0.12); color: var(--destructive); }

.admin-logout {
  margin-top: 1rem;
  background: none;
  border: none;
  color: var(--muted-foreground);
  font-size: 0.8125rem;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

/* ---- Voucher ---- */

.voucher-header {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10;
  width: auto;
  max-width: none;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding:
    max(1.25rem, env(safe-area-inset-top))
    2rem
    1rem
    2rem;
  background: var(--background);
}

.voucher-header .logo-sm {
  width: 2.25rem;
  height: 2.25rem;
}

.voucher-header span {
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: 1.125rem;
}

.voucher-icon {
  margin-top: 0.75rem;
  width: 3.5rem;
  height: 3.5rem;
  display: block;
  border: none;
  outline: none;
  box-shadow: none;
  background: none;
}

.voucher-amount {
  margin-top: 0.5rem;
  display: flex;
  align-items: baseline;
  gap: 0.375rem;
}

.voucher-amount span {
  font-size: 1.875rem;
  font-weight: 700;
}

.voucher-divider-wrap {
  width: 100%;
  max-width: 28rem;
  padding: 0 1.5rem;
  margin-top: 1.5rem;
}

.voucher-divider {
  border-top: 1px solid var(--border);
}

.voucher-card-wrap {
  width: 100%;
  max-width: 28rem;
  padding: 0 1.5rem;
  margin-top: 1.5rem;
}

.voucher-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.25rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  font-weight: 500;
}

.voucher-recipient {
  display: grid;
  grid-template-columns: 5.5rem minmax(0, 1fr);
  grid-template-areas:
    "qr status"
    "qr desc";
  gap: 0.625rem 0.875rem;
  padding: 0.875rem;
  background: var(--secondary);
  border-radius: 0.75rem;
  align-items: start;
}

body[data-view="voucher"]:not([data-voucher-ready]) #vRecipient {
  color: transparent;
}

html[data-voucher-cached] body[data-view="voucher"] #vRecipient,
body[data-view="voucher"][data-voucher-ready] #vRecipient {
  color: inherit;
}

.voucher-qr {
  grid-area: qr;
  width: 100%;
  max-width: 5.5rem;
  height: auto;
  aspect-ratio: 1;
  padding: 0.375rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  align-self: center;
  justify-self: center;
  display: block;
  object-fit: contain;
}

.voucher-recipient-info {
  display: contents;
}

.voucher-desc {
  grid-area: desc;
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--muted-foreground);
  line-height: 1.55;
  margin: 0;
}

.voucher-status {
  grid-area: status;
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 0.4375rem;
  font-weight: 600;
  font-size: 0.625rem;
  letter-spacing: 0.02em;
  color: var(--pending);
  background: var(--pending-soft);
  padding: 0.3125rem 0.5625rem;
  border-radius: 999px;
  margin-bottom: 0;
  width: fit-content;
  max-width: 100%;
}

.voucher-status-dots {
  display: inline-flex;
  align-items: center;
  gap: 0.125rem;
  margin-left: 0.125rem;
}

.voucher-status-dots i {
  display: block;
  width: 0.1875rem;
  height: 0.1875rem;
  border-radius: 50%;
  background: var(--pending);
  opacity: 0.35;
  animation: voucher-pending-dot 1.2s ease-in-out infinite;
}

.voucher-status-dots i:nth-child(2) { animation-delay: 0.15s; }
.voucher-status-dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes voucher-pending-dot {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-0.125rem); }
}

@media (prefers-reduced-motion: reduce) {
  .voucher-status-dots i {
    animation: none;
    opacity: 0.8;
  }
}

.voucher-desc .link-like {
  color: var(--primary);
  text-decoration: underline;
  cursor: pointer;
}

.voucher-inner-divider {
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

.voucher-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.voucher-row:last-child { margin-bottom: 0; }

.voucher-row-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted-foreground);
  font-size: 0.75rem;
  font-weight: 500;
}

.voucher-row-left svg {
  width: 0.875rem;
  height: 0.875rem;
}

.voucher-row-value {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--foreground);
}

.voucher-row-value.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  white-space: nowrap;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  text-align: right;
}

.voucher-row-value.mono::-webkit-scrollbar {
  display: none;
}

.voucher-row-value.green { color: var(--success); }

.voucher-timer {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  padding: 0.375rem 0 0.125rem;
}

.voucher-timer-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.125rem;
  min-width: 0;
  text-align: center;
}

.voucher-timer-label {
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--muted-foreground);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0;
  line-height: 1.2;
}

.voucher-timer-value {
  font-size: 0.875rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 700;
  color: var(--foreground);
  letter-spacing: 0.04em;
  margin: 0;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.voucher-cta-wrap {
  width: 100%;
  max-width: 28rem;
  padding: 1.5rem 1.5rem 2rem;
}

.voucher-cta {
  width: 100%;
  height: 3.5rem;
  border-radius: 9999px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.voucher-cta:active {
  transform: scale(0.98);
}

.voucher-error {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted-foreground);
}

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }

  #view-voucher {
    justify-content: center;
    padding:
      max(3.75rem, calc(env(safe-area-inset-top) + 2.75rem))
      0
      max(1.5rem, env(safe-area-inset-bottom));
  }

  .voucher-header {
    padding:
      max(0.875rem, env(safe-area-inset-top))
      1rem
      0.75rem
      1rem;
    gap: 0.625rem;
  }

  .voucher-header .logo-sm {
    width: 1.875rem;
    height: 1.875rem;
  }

  .voucher-header span {
    font-size: 1rem;
  }

  .voucher-icon {
    margin-top: 0.5rem;
  }

  .voucher-divider-wrap,
  .voucher-card-wrap {
    margin-top: 1.25rem;
  }

  .voucher-cta-wrap {
    padding-top: 1.25rem;
    padding-bottom: 0.5rem;
  }
}

@media (min-width: 1024px) {
  .voucher-header .logo-sm {
    width: 2.5rem;
    height: 2.5rem;
  }

  .voucher-header span {
    font-size: 1.25rem;
  }

  .voucher-header {
    padding:
      max(1.5rem, env(safe-area-inset-top))
      2.5rem
      1.25rem
      2.5rem;
    gap: 0.875rem;
  }

  #view-voucher {
    padding-top: max(5.25rem, calc(env(safe-area-inset-top) + 4.25rem));
  }
}
