/* ════════════════════════════════════
   CERTIQR — CSS
   Aesthetic: Premium credential vault
   Dark auth, cream library, dramatic QR
   ════════════════════════════════════ */

/* ── Variables ────────────────────── */
:root {
  --gold:        #C8973A;
  --gold-light:  #E8B85A;
  --dark:        #0C0F1A;
  --dark-2:      #151829;
  --dark-3:      #1E2235;
  --cream:       #F6F4EF;
  --cream-2:     #EDE9E1;
  --text-dark:   #1A1A2E;
  --text-mid:    #5A5870;
  --text-light:  #9898A8;
  --white:       #FFFFFF;
  --danger:      #E05252;
  --ok:          #3BAD6E;
  --radius-sm:   10px;
  --radius:      18px;
  --radius-lg:   24px;
  --shadow:      0 4px 24px rgba(0,0,0,0.10);
  --shadow-lg:   0 8px 40px rgba(0,0,0,0.18);
  --font-brand:  'Cormorant Garamond', Georgia, serif;
  --font-ui:     'DM Sans', -apple-system, sans-serif;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Reset ────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-ui);
  background: var(--cream);
  color: var(--text-dark);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
input, button { font-family: var(--font-ui); }
.hidden { display: none !important; }

/* ══════════════════════════════════
   SCREEN SYSTEM
══════════════════════════════════ */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.screen.hidden { display: none; }

/* ══════════════════════════════════
   AUTH SCREENS (setup + login)
══════════════════════════════════ */
.auth-bg {
  position: relative;
  flex: 1;
  background: var(--dark);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Subtle noise grain overlay */
.auth-grain {
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
  background-size: 180px;
  opacity: 0.6;
  pointer-events: none;
}

/* Glow spots */
.auth-bg::before {
  content: '';
  position: absolute;
  width: 320px; height: 320px;
  background: radial-gradient(circle, rgba(200,151,58,0.12) 0%, transparent 70%);
  top: -60px; right: -60px;
  pointer-events: none;
}
.auth-bg::after {
  content: '';
  position: absolute;
  width: 240px; height: 240px;
  background: radial-gradient(circle, rgba(100,110,200,0.08) 0%, transparent 70%);
  bottom: 80px; left: -40px;
  pointer-events: none;
}

.auth-content {
  position: relative;
  width: 100%;
  max-width: 400px;
  padding: calc(var(--safe-top) + 40px) 24px calc(var(--safe-bottom) + 32px);
  display: flex;
  flex-direction: column;
  gap: 32px;
  align-items: center;
}

/* Brand mark */
.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.brand-icon {
  font-size: 48px;
  color: var(--gold);
  line-height: 1;
  animation: pulse-icon 3s ease-in-out infinite;
}
@keyframes pulse-icon {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.7; }
}
.brand-name {
  font-family: var(--font-brand);
  font-size: 40px;
  font-weight: 700;
  color: var(--white);
  letter-spacing: -0.5px;
}
.brand-sub {
  font-size: 13px;
  color: rgba(255,255,255,0.35);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Auth card */
.auth-card {
  width: 100%;
  background: var(--dark-2);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.auth-card h2 {
  font-family: var(--font-brand);
  font-size: 24px;
  font-weight: 600;
  color: var(--white);
}
.auth-hint {
  font-size: 13px;
  color: rgba(255,255,255,0.4);
  margin-top: -8px;
}
.field-group { display: flex; flex-direction: column; gap: 10px; }

/* Reset link (login screen) */
.reset-link {
  background: none;
  border: none;
  color: rgba(255,255,255,0.25);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 12px;
  letter-spacing: 0.03em;
}
.reset-link:active { color: rgba(255,255,255,0.5); }

/* ══════════════════════════════════
   SHARED FORM ELEMENTS
══════════════════════════════════ */
.field {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
/* Auth context */
.auth-card .field {
  background: var(--dark-3);
  border: 1.5px solid rgba(255,255,255,0.08);
  color: var(--white);
}
.auth-card .field::placeholder { color: rgba(255,255,255,0.25); }
.auth-card .field:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(200,151,58,0.12);
}
/* App context */
.email-card .field {
  background: var(--cream);
  border: 1.5px solid var(--cream-2);
  color: var(--text-dark);
}
.email-card .field::placeholder { color: var(--text-light); }
.email-card .field:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(200,151,58,0.10);
}

/* CTA button */
.cta {
  width: 100%;
  padding: 15px 20px;
  background: var(--gold);
  color: var(--dark);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: opacity 0.15s, transform 0.1s, background 0.2s;
}
.cta:active  { opacity: 0.85; transform: scale(0.98); }
.cta:disabled { background: #7A6030; color: rgba(255,255,255,0.4); cursor: default; }

/* Messages */
.msg {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.4;
}
.msg-error { background: rgba(224,82,82,0.12); color: #E05252; }
.msg-ok    { background: rgba(59,173,110,0.12); color: #2B9960; }
/* Dark context */
.auth-card .msg-error { background: rgba(224,82,82,0.18); }

/* ══════════════════════════════════
   TOP BAR
══════════════════════════════════ */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  background: var(--white);
  border-bottom: 1px solid var(--cream-2);
  min-height: 56px;
  gap: 8px;
  position: relative;
  z-index: 10;
}
.top-title {
  font-family: var(--font-brand);
  font-size: 20px;
  font-weight: 600;
  color: var(--text-dark);
  flex: 1;
  text-align: center;
}
.top-title.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Add button */
.add-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--dark);
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, opacity 0.15s;
  font-weight: 300;
}
.add-btn:active { transform: scale(0.92); opacity: 0.8; }

/* Back button */
.back-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--cream);
  color: var(--text-dark);
  border: 1.5px solid var(--cream-2);
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.back-btn:active { background: var(--cream-2); }

/* ══════════════════════════════════
   LIBRARY
══════════════════════════════════ */
.lib-count {
  padding: 8px 16px;
  font-size: 12px;
  color: var(--text-light);
  background: var(--cream);
  text-align: right;
  letter-spacing: 0.04em;
}

.file-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

/* Empty state */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 12px;
}
.empty-icon {
  font-size: 56px;
  color: var(--cream-2);
  line-height: 1;
  margin-bottom: 4px;
}
.empty-title { font-size: 17px; font-weight: 600; color: var(--text-mid); }
.empty-hint  { font-size: 14px; color: var(--text-light); text-align: center; }

/* File card */
.file-item {
  background: var(--white);
  border-radius: var(--radius);
  padding: 14px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 1.5px solid transparent;
  animation: slide-in 0.2s ease;
}
@keyframes slide-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.file-item:active {
  transform: scale(0.98);
  box-shadow: 0 2px 12px rgba(0,0,0,0.07);
  border-color: var(--gold);
}

.file-thumb {
  width: 52px; height: 52px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
}
.file-thumb.is-pdf { background: #FFF0E5; }
.file-thumb.is-img { background: #E8F0FF; }

.file-info { flex: 1; min-width: 0; }
.file-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-meta {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 3px;
}

.file-del {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 18px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.file-del:active { color: var(--danger); background: rgba(224,82,82,0.08); }

/* ══════════════════════════════════
   MODE TOGGLE
══════════════════════════════════ */
.mode-toggle {
  display: flex;
  gap: 4px;
  padding: 10px 12px;
  background: var(--white);
  border-bottom: 1px solid var(--cream-2);
}
.mode-btn {
  flex: 1;
  padding: 10px 8px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  background: var(--cream);
  color: var(--text-mid);
  transition: all 0.2s;
}
.mode-btn.active {
  background: var(--dark);
  color: var(--gold);
  font-weight: 600;
}

/* ══════════════════════════════════
   PANELS
══════════════════════════════════ */
.panel {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.panel.hidden { display: none; }

/* QR Panel */
.qr-panel-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 20px calc(var(--safe-bottom) + 20px);
  gap: 18px;
}
.qr-label {
  font-size: 14px;
  color: var(--text-mid);
  text-align: center;
}
.qr-frame {
  width: 240px; height: 240px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 3px solid var(--cream-2);
}
.qr-frame canvas, .qr-frame img { display: block; }

/* Loader */
.qr-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--text-light);
  font-size: 13px;
}
.spinner {
  width: 28px; height: 28px;
  border: 2.5px solid var(--cream-2);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.qr-actions {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 300px;
}
.btn-outline {
  flex: 1;
  padding: 11px 8px;
  border: 1.5px solid var(--cream-2);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--text-dark);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.btn-outline:active { border-color: var(--gold); background: rgba(200,151,58,0.05); }

.expiry-badge {
  font-size: 12px;
  color: var(--text-light);
  background: var(--cream-2);
  padding: 5px 12px;
  border-radius: 20px;
  letter-spacing: 0.02em;
}

/* Email Panel */
.email-panel-inner {
  padding: 24px 16px calc(var(--safe-bottom) + 16px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Share hero block */
.share-hero {
  background: var(--white);
  border-radius: var(--radius);
  padding: 28px 20px 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}
.share-hero-icon {
  font-size: 44px;
  line-height: 1;
  margin-bottom: 2px;
}
.share-hero-title {
  font-family: var(--font-brand);
  font-size: 22px;
  font-weight: 600;
  color: var(--text-dark);
}
.share-hero-sub {
  font-size: 14px;
  color: var(--text-mid);
  line-height: 1.55;
  max-width: 280px;
}
.share-hero .cta {
  margin-top: 4px;
}

/* Divider */
.share-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-light);
  font-size: 12px;
  letter-spacing: 0.04em;
}
.share-divider::before,
.share-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--cream-2);
}

/* Optional email card */
.email-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px 20px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-mid);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.email-note {
  font-size: 12px;
  color: var(--text-light);
  line-height: 1.5;
}

/* ══════════════════════════════════
   QR FULLSCREEN OVERLAY
══════════════════════════════════ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 20, 0.96);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  animation: fade-in 0.2s ease;
}
.overlay.hidden { display: none; }
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 24px;
}
.qr-fs-wrap {
  background: var(--white);
  padding: 20px;
  border-radius: var(--radius-lg);
  box-shadow: 0 0 60px rgba(200,151,58,0.15);
}
.qr-fs-wrap canvas, .qr-fs-wrap img { display: block; }

.overlay-label {
  color: rgba(255,255,255,0.55);
  font-size: 15px;
  letter-spacing: 0.04em;
}
.overlay-close {
  background: rgba(255,255,255,0.10);
  border: 1.5px solid rgba(255,255,255,0.15);
  color: var(--white);
  padding: 12px 36px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.overlay-close:active { background: rgba(255,255,255,0.2); }

/* ══════════════════════════════════
   TOAST
══════════════════════════════════ */
.toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 24px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--dark);
  color: var(--white);
  padding: 12px 24px;
  border-radius: 40px;
  font-size: 14px;
  font-weight: 500;
  z-index: 200;
  box-shadow: var(--shadow-lg);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

/* ══════════════════════════════════
   UTILITY
══════════════════════════════════ */
.hidden { display: none !important; }

/* Lib count bar */
.lib-count { display: block; }

/* ══════════════════════════════════
   ANDROID INSTALL BANNER
   Mostrato solo quando Chrome lancia
   beforeinstallprompt (Android)
══════════════════════════════════ */
.install-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 300;
  background: var(--dark-2);
  border-bottom: 1px solid rgba(200,151,58,0.25);
  padding: calc(var(--safe-top) + 10px) 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  animation: slide-down 0.3s ease;
  box-shadow: 0 4px 20px rgba(0,0,0,0.35);
}
@keyframes slide-down {
  from { transform: translateY(-100%); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}
.install-banner.hidden { display: none !important; }

.install-banner-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.install-banner-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  flex-shrink: 0;
}
.install-banner-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--white);
  white-space: nowrap;
}
.install-banner-sub {
  font-size: 11px;
  color: rgba(255,255,255,0.45);
  white-space: nowrap;
}

.install-banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.install-dismiss {
  background: none;
  border: none;
  color: rgba(255,255,255,0.35);
  font-size: 16px;
  padding: 4px 6px;
  cursor: pointer;
  line-height: 1;
}
.install-accept {
  background: var(--gold);
  color: var(--dark);
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s;
}
.install-accept:active { opacity: 0.8; }

/* ══════════════════════════════════
   WORKER NOT CONFIGURED WARNING
══════════════════════════════════ */
.worker-warning {
  width: 100%;
  background: rgba(200,151,58,0.10);
  border: 1.5px solid rgba(200,151,58,0.30);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ww-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--gold);
}
.ww-text {
  font-size: 13px;
  color: var(--text-mid);
  line-height: 1.5;
}
.ww-text code {
  background: rgba(0,0,0,0.07);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
  font-family: 'DM Mono', monospace;
}

/* ══════════════════════════════════
   ML SYSTEMS BRAND BAR
══════════════════════════════════ */
.ml-brand-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 5px 16px;
  background: var(--dark);
  border-bottom: 1px solid rgba(200,151,58,0.20);
}
.ml-brand-text {
  font-family: var(--font-brand);
  font-size: 13px;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 0.06em;
}
.ml-brand-dot {
  color: rgba(200,151,58,0.40);
  font-size: 12px;
}
.ml-brand-sub {
  font-size: 11px;
  color: rgba(255,255,255,0.35);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* ══════════════════════════════════
   HELP BUTTON
══════════════════════════════════ */
.help-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--cream);
  color: var(--text-mid);
  border: 1.5px solid var(--cream-2);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.help-btn:active { background: var(--dark); color: var(--gold); }

/* ══════════════════════════════════
   GUIDA SCREEN
══════════════════════════════════ */
.guide-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px calc(var(--safe-bottom) + 20px);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.guide-step {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px 14px;
  box-shadow: var(--shadow);
  animation: slide-in 0.2s ease;
}
.guide-step + .guide-step { margin-top: 8px; }

.guide-step-icon {
  font-size: 26px;
  line-height: 1;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cream);
  border-radius: 10px;
  flex-shrink: 0;
}
.guide-step-content { flex: 1; }
.guide-step-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 4px;
}
.guide-step-text {
  font-size: 13px;
  color: var(--text-mid);
  line-height: 1.55;
}
.guide-step-text strong { color: var(--text-dark); }

.guide-footer {
  margin-top: 20px;
  padding: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.guide-footer-brand {
  font-family: var(--font-brand);
  font-size: 15px;
  color: var(--gold);
  letter-spacing: 0.04em;
}
.guide-footer-version {
  font-size: 11px;
  color: var(--text-light);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
