:root {
  --bg-primary: #090d16;
  --bg-secondary: #0f172a;
  --glass-bg: rgba(30, 41, 59, 0.72);
  --glass-bg-hover: rgba(51, 65, 85, 0.85);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-border-focus: rgba(59, 130, 246, 0.5);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-sub: #64748b;
  --accent-blue: #3b82f6;
  --accent-glow: #60a5fa;
  --accent-cyan: #06b6d4;
  --danger-color: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.15);
  --success-color: #10b981;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  background-color: var(--bg-primary);
  background-image: radial-gradient(circle at 50% 0%, #1e293b 0%, #090d16 100%);
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  padding-top: var(--safe-top);
  padding-bottom: calc(75px + var(--safe-bottom));
}

/* ========================================================
   Header & App Bar
   ======================================================== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--glass-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.4);
}

.brand-icon svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #fff;
}

.brand-badge {
  font-size: 0.65rem;
  padding: 2px 6px;
  background: rgba(59, 130, 246, 0.2);
  color: var(--accent-glow);
  border-radius: var(--radius-full);
  border: 1px solid rgba(59, 130, 246, 0.3);
  font-weight: 600;
  letter-spacing: 0.5px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: var(--text-main);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:active {
  transform: scale(0.92);
  background: var(--glass-bg-hover);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.icon-btn.panic {
  background: var(--danger-bg);
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--danger-color);
}

/* ========================================================
   Main Container
   ======================================================== */
.container {
  flex: 1;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Status Bar Info */
.stats-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-value {
  color: var(--text-main);
  font-weight: 600;
}

/* Quick Action Strip */
.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.action-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(10px);
}

.action-card:active {
  transform: scale(0.97);
  border-color: var(--accent-blue);
  background: var(--glass-bg-hover);
}

.action-card-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.action-card-icon svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.action-card.camera .action-card-icon {
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-cyan);
}

.action-card-text h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 2px;
}

.action-card-text p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ========================================================
   Gallery Grid
   ======================================================== */
.gallery-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}

.gallery-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (min-width: 600px) {
  .gallery-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 900px) {
  .gallery-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.gallery-card {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.gallery-card:active {
  transform: scale(0.96);
  border-color: var(--accent-blue);
}

.gallery-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background-color: #0f172a;
}

.gallery-card-badge {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 10px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, transparent 100%);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.85);
  pointer-events: none;
}

.gallery-card-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 75%;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 50px 20px;
  background: var(--glass-bg);
  border: 2px dashed var(--glass-border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.empty-icon {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-full);
  background: rgba(59, 130, 246, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-glow);
  margin-bottom: 4px;
}

.empty-icon svg {
  width: 32px;
  height: 32px;
  fill: currentColor;
}

.empty-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-main);
}

.empty-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  max-width: 300px;
  line-height: 1.4;
}

/* ========================================================
   Bottom Navigation Bar
   ======================================================== */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 10px 16px calc(10px + var(--safe-bottom)) 16px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--glass-border);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 500;
  transition: color 0.2s;
  padding: 4px 8px;
}

.nav-item svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.nav-item.active, .nav-item:active {
  color: var(--accent-glow);
}

.nav-fab {
  position: relative;
  top: -16px;
  width: 54px;
  height: 54px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
  color: #fff;
  border: 4px solid var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
  transition: transform 0.2s, box-shadow 0.2s;
}

.nav-fab:active {
  transform: scale(0.92);
  box-shadow: 0 2px 10px rgba(59, 130, 246, 0.4);
}

.nav-fab svg {
  width: 26px;
  height: 26px;
  fill: #fff;
}

/* ========================================================
   Lock Screen (Cofre Trancado)
   ======================================================== */
.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg-primary);
  background-image: radial-gradient(circle at 50% 20%, #1e293b 0%, #090d16 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.lock-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.vault-vault-wheel {
  width: 90px;
  height: 90px;
  border-radius: var(--radius-full);
  border: 3px solid var(--accent-blue);
  box-shadow: 0 0 25px rgba(59, 130, 246, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  background: rgba(30, 41, 59, 0.6);
  position: relative;
  animation: pulse-glow 3s infinite ease-in-out;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 20px rgba(59, 130, 246, 0.3); }
  50% { box-shadow: 0 0 35px rgba(59, 130, 246, 0.7); }
}

.vault-vault-wheel svg {
  width: 44px;
  height: 44px;
  fill: var(--accent-glow);
}

.lock-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: 1px;
}

.lock-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 28px;
}

/* Secret Input & Pinpad */
.pin-display {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 24px;
}

.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: var(--radius-full);
  border: 2px solid var(--text-sub);
  transition: all 0.2s ease;
}

.pin-dot.filled {
  background: var(--accent-glow);
  border-color: var(--accent-blue);
  box-shadow: 0 0 8px rgba(96, 165, 250, 0.6);
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 76px);
  gap: 14px;
  margin-bottom: 20px;
}

.pin-btn {
  width: 76px;
  height: 76px;
  border-radius: var(--radius-full);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: var(--text-main);
  font-size: 1.5rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pin-btn:active {
  background: var(--accent-blue);
  transform: scale(0.92);
  color: #fff;
}

.pin-btn.btn-text {
  font-size: 0.9rem;
}

.pin-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

/* Keypad or Text Key Toggle */
.key-toggle-btn {
  background: none;
  border: none;
  color: var(--accent-glow);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
}

.text-key-container {
  display: none;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 280px;
  margin-bottom: 20px;
}

.text-key-container.active {
  display: flex;
}

.secret-text-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: #fff;
  font-size: 1.1rem;
  text-align: center;
  outline: none;
}

.secret-text-input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.3);
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.3);
}

.btn-primary:active {
  transform: scale(0.97);
}

/* ========================================================
   Modo Disfarce (Calculadora Camuflada)
   ======================================================== */
.calc-screen {
  position: fixed;
  inset: 0;
  z-index: 101;
  background: #17171c;
  display: none;
  flex-direction: column;
  justify-content: flex-end;
  padding: 24px;
  padding-bottom: calc(24px + var(--safe-bottom));
}

.calc-screen.active {
  display: flex;
}

.calc-display {
  text-align: right;
  font-size: 3rem;
  font-weight: 300;
  color: #fff;
  padding: 20px 10px;
  min-height: 80px;
  word-break: break-all;
}

.calc-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.calc-btn {
  aspect-ratio: 1;
  border-radius: var(--radius-full);
  border: none;
  font-size: 1.5rem;
  background: #2e2f38;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.15s;
}

.calc-btn:active {
  filter: brightness(1.3);
}

.calc-btn.op {
  background: #4b5efc;
}

.calc-btn.top {
  background: #4e505f;
}

/* ========================================================
   Lightbox Modal
   ======================================================== */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.94);
  display: none;
  flex-direction: column;
  justify-content: space-between;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.lightbox.active {
  display: flex;
}

.lightbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 16px 12px 16px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
}

.lightbox-title {
  font-size: 0.9rem;
  color: #fff;
  max-width: 60%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lightbox-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  touch-action: none;
}

.lightbox-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: transform 0.2s ease-out;
  user-select: none;
}

.lightbox-actions {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 16px 20px calc(16px + var(--safe-bottom)) 20px;
  background: linear-gradient(to top, rgba(0,0,0,0.85), transparent);
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: #cbd5e1;
  font-size: 0.75rem;
  cursor: pointer;
}

.action-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

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

/* ========================================================
   Settings / SQLite DB Modal
   ======================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(6px);
}

.modal-overlay.active {
  display: flex;
}

.modal-sheet {
  width: 100%;
  max-width: 600px;
  background: #0f172a;
  border-top: 1px solid var(--glass-border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 20px calc(24px + var(--safe-bottom)) 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 85vh;
  overflow-y: auto;
  animation: slide-up 0.25s ease-out;
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-handle {
  width: 40px;
  height: 5px;
  border-radius: var(--radius-full);
  background: var(--text-sub);
  margin: 0 auto 6px auto;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet-title {
  font-size: 1.2rem;
  font-weight: 700;
}

.sheet-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sheet-section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-sub);
  font-weight: 600;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
}

.settings-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-label h4 {
  font-size: 0.95rem;
  color: var(--text-main);
  font-weight: 600;
}

.settings-label p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-secondary {
  padding: 10px 14px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: var(--text-main);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-secondary:active {
  background: var(--glass-bg-hover);
}

.btn-secondary svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* ========================================================
   Toast Notification
   ======================================================== */
.toast {
  position: fixed;
  bottom: calc(85px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(50px);
  background: rgba(30, 41, 59, 0.95);
  color: #fff;
  border: 1px solid var(--glass-border);
  padding: 10px 18px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 120;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.toast.active {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Inputs ocultos de arquivo */
#camera-input, #gallery-input, #db-file-input {
  display: none;
}

/* ========================================================
   v2 - Criptografia & Sincronização
   ======================================================== */
input, textarea { user-select: text; -webkit-user-select: text; }

.sync-chip {
  margin-left: auto;
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid var(--glass-border);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  cursor: pointer;
  white-space: nowrap;
}
.sync-chip[data-state="ok"] { color: var(--success-color); border-color: rgba(16, 185, 129, 0.35); }
.sync-chip[data-state="busy"] { color: var(--accent-glow); border-color: rgba(59, 130, 246, 0.4); }
.sync-chip[data-state="err"] { color: var(--danger-color); border-color: rgba(239, 68, 68, 0.4); }

.gallery-card.pending::after {
  content: '';
  position: absolute;
  top: 8px; right: 8px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #f59e0b;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.5);
}
.gallery-card { position: relative; }

.pin-btn-spacer { display: block; }

.setup-screen {
  position: fixed;
  inset: 0;
  z-index: 105;
  background: var(--bg-primary);
  background-image: radial-gradient(circle at 50% 20%, #1e293b 0%, #090d16 100%);
  display: none;
  overflow-y: auto;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
}
.setup-screen.active { display: block; }
.setup-panel {
  display: none;
  flex-direction: column;
  gap: 12px;
  max-width: 420px;
  margin: 0 auto;
  min-height: 100%;
  justify-content: center;
  text-align: center;
}
.setup-panel .secret-text-input { width: 100%; }
.setup-panel .btn-primary { width: 100%; }
.setup-text, .dlg-text { color: var(--text-muted); font-size: 0.9rem; line-height: 1.45; }
.setup-msg, .dlg-msg { min-height: 1.2em; font-size: 0.85rem; }
.setup-check { display: flex; gap: 10px; align-items: center; justify-content: center; color: var(--text-main); font-size: 0.9rem; }
.setup-check input { transform: scale(1.3); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.code-box {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent-glow);
  background: rgba(15, 23, 42, 0.8);
  border: 1px dashed rgba(96, 165, 250, 0.5);
  border-radius: var(--radius-md);
  padding: 16px;
  word-break: break-all;
  user-select: all;
  -webkit-user-select: all;
  text-align: center;
}

#dialog { z-index: 95; }
.dialog-body { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.dialog-body .secret-text-input { width: 100%; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.danger-btn { color: var(--danger-color) !important; border-color: rgba(239, 68, 68, 0.4) !important; }
.dialog-actions .btn-primary, .dialog-actions .btn-secondary { width: auto; flex: 1; justify-content: center; }
.calc-btn[data-calc="0"] { aspect-ratio: auto; }
