:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --secondary: #f3f4f6;
  --secondary-hover: #e5e7eb;
  --secondary-text: #374151;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --bg-app: #f9fafb;
  --bg-card: #ffffff;
  --bg-header: #fcfcfc;
  --bg-input: #ffffff;
  --bg-code: #f3f4f6;
  --bg-nav: #ffffff;
  --border: #e5e7eb;
  --text-main: #111827;
  --text-muted: #6b7280;
  --text-code: #334155;
  --sidebar-bg: #1f2937;
  --sidebar-text: #e5e7eb;
  --sidebar-active: #374151;
  --toast-bg: #1f2937;
  --toast-text: #ffffff;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', monospace;
  --radius: 8px;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --secondary: #374151;
    --secondary-hover: #4b5563;
    --secondary-text: #f3f4f6;
    --danger: #f87171;
    --danger-hover: #ef4444;
    --bg-app: #111827;
    --bg-card: #1f2937;
    --bg-header: #1f2937;
    --bg-input: #111827;
    --bg-code: #111827;
    --bg-nav: #1f2937;
    --border: #374151;
    --text-main: #f9fafb;
    --text-muted: #9ca3af;
    --text-code: #e5e7eb;
    --sidebar-bg: #111827;
    --sidebar-text: #e5e7eb;
    --sidebar-active: #374151;
    --toast-bg: #374151;
    --toast-text: #f9fafb;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.3), 0 1px 2px 0 rgba(0, 0, 0, 0.2);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
}

/* Layout */
.app-layout {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.brand {
  padding: 24px;
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
}

.logo-icon {
  width: 24px;
  height: 24px;
}

.nav-menu {
  flex: 1;
  padding: 0 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: #9ca3af;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  text-align: left;
  transition: all 0.2s;
}

.nav-item svg {
  width: 18px;
  height: 18px;
}

.nav-item:hover {
  background: rgba(255,255,255,0.05);
  color: #fff;
}

.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
}

.sidebar-footer {
  padding: 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #9ca3af;
  margin-bottom: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6b7280;
}
.status-dot.ready { background: #10b981; box-shadow: 0 0 8px #10b98166; }
.status-dot.error { background: #ef4444; }
.status-dot.loading { animation: pulse 1.5s infinite; }

@keyframes pulse { 0% { opacity: 0.4; } 50% { opacity: 1; } 100% { opacity: 0.4; } }

.btn-install {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.btn-install:hover { background: rgba(255,255,255,0.15); }

/* Content Area */
.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px;
  padding-top: calc(32px + env(safe-area-inset-top));
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
  padding-left: calc(40px + env(safe-area-inset-left));
  padding-right: calc(40px + env(safe-area-inset-right));
}

.section-header {
  margin-bottom: 32px;
}
.section-header h2 { margin: 0 0 8px 0; font-size: 24px; font-weight: 700; }
.section-header p { margin: 0; color: var(--text-muted); }

.tab-content { display: none; animation: fadeIn 0.2s ease-out; }
.tab-content.active { display: block; }

.vault-shell {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.vault-subtabs {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  width: fit-content;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  box-shadow: var(--shadow);
}

.vault-subtab {
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  padding: 10px 16px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.vault-subtab:hover {
  color: var(--text-main);
}

.vault-subtab.active {
  color: #fff;
  background: var(--primary);
}

.vault-page {
  display: none;
}

.vault-page.active {
  display: block;
}

.vault-hero-card {
  overflow: hidden;
  border-color: color-mix(in srgb, var(--primary) 20%, var(--border));
}

.vault-hero-body {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 20px;
  background: var(--bg-card);
}

.vault-hero-copy h3,
.vault-placeholder-body h3 {
  margin: 12px 0 8px;
  font-size: 24px;
}

.vault-hero-copy p,
.vault-placeholder-body p {
  margin: 0;
  color: var(--text-muted);
  max-width: 58ch;
}

.vault-hero-glyph,
.vault-placeholder-icon {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 88px;
  height: 88px;
  border-radius: 24px;
  color: var(--primary);
  background: rgba(79, 70, 229, 0.09);
  box-shadow: inset 0 0 0 1px rgba(79, 70, 229, 0.12);
}

.vault-hero-glyph svg,
.vault-placeholder-icon svg {
  width: 42px;
  height: 42px;
}

.vault-placeholder-card {
  border-style: dashed;
}

.vault-placeholder-body {
  display: flex;
  align-items: center;
  gap: 18px;
}

.vault-identity-select {
  max-width: 400px;
  margin-bottom: 20px;
}

.totp-hero-card {
  border-color: color-mix(in srgb, var(--primary) 18%, var(--border));
}

.totp-hero-body {
  align-items: center;
}

.totp-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 16px;
}

.totp-toolbar-compact {
  justify-content: flex-end;
}

.totp-toolbar h3 {
  margin: 0 0 4px;
  font-size: 22px;
}

.totp-toolbar p {
  margin: 0;
  color: var(--text-muted);
}

.totp-toolbar-actions {
  margin-top: 0;
}

.totp-state-card {
  border-style: dashed;
}

.totp-state-body {
  display: flex;
  align-items: center;
  gap: 18px;
}

.totp-inline-actions {
  margin-top: 16px;
}

.totp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
}

.totp-site-card {
  display: flex;
  flex-direction: column;
}

.totp-site-card.favorites {
  border-color: var(--border);
}

.totp-site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.totp-site-header h3 {
  margin: 0;
  font-size: 18px;
}

.totp-site-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 12px;
}

.totp-collapse-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
}

.totp-collapse-btn svg {
  width: 16px;
  height: 16px;
  transition: transform 0.2s ease;
}

.totp-collapse-btn[aria-expanded="false"] svg {
  transform: rotate(-90deg);
}

.totp-site-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg-card);
}

.totp-site-table-head {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(140px, 1fr) auto auto;
  gap: 16px;
  align-items: center;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-header);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.totp-site-list.hidden {
  display: none;
}

.totp-entry-card {
  position: relative;
  overflow: hidden;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
}

.totp-entry-card:last-child {
  border-bottom: 0;
}

.totp-entry-shell {
  display: flex;
  align-items: stretch;
  gap: 12px;
  padding: 10px 12px;
  position: relative;
  z-index: 1;
  background: var(--bg-card);
  transition: transform 0.18s ease;
}

.totp-entry-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  justify-content: center;
}

.totp-action-btn {
  width: 30px;
  height: 30px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.totp-action-btn:hover {
  background: var(--secondary);
  border-color: var(--border);
}

.totp-action-btn svg {
  width: 18px;
  height: 18px;
}

.totp-action-btn.is-favorite {
  color: var(--primary);
}

.totp-entry-main {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(140px, 1fr) auto;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.totp-entry-copy {
  min-width: 0;
}

.totp-entry-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}

.totp-entry-title h4 {
  margin: 0;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.totp-entry-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.totp-entry-runtime {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
  min-width: 140px;
}

.totp-code {
  min-width: 102px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg-code);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 21px;
  font-weight: 600;
  text-align: right;
  letter-spacing: 0.08em;
}

.totp-code.is-revealed {
  color: var(--primary);
  background: var(--bg-code);
}

.totp-timer {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  color: var(--text-muted);
  font-size: 11px;
}

.totp-copy-btn {
  align-self: flex-end;
  min-width: 64px;
}

.totp-copy-btn:disabled {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.totp-timer-bar {
  position: relative;
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--secondary);
  overflow: hidden;
}

.totp-timer-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  width: calc(var(--totp-progress, 0.5) * 100%);
  background: var(--primary);
}

.totp-entry-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--secondary);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
}

.totp-entry-chip.favorite {
  background: var(--secondary);
  color: var(--secondary-text);
}

.totp-entry-gesture {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 84px;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
  z-index: 0;
}

.totp-entry-gesture svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.totp-entry-gesture span {
  line-height: 1;
}

.totp-entry-gesture.favorite {
  right: 0;
  background: var(--primary);
  padding: 0 14px 0 8px;
  justify-content: flex-end;
}

.totp-entry-gesture.delete {
  left: 0;
  background: var(--danger);
  padding: 0 8px 0 14px;
  justify-content: flex-start;
}

.totp-entry-card.is-swiping-right .totp-entry-gesture.favorite,
.totp-entry-card.is-swiping-left .totp-entry-gesture.delete {
  opacity: 1;
}

.totp-empty-inline {
  color: var(--text-muted);
  font-size: 13px;
  padding: 16px;
}

.totp-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.totp-modal-content {
  max-width: 460px;
}

.setting-select-wrapper select {
  padding-right: 42px;
  font-weight: 500;
  background: var(--bg-input);
  border-radius: 10px;
}

.setting-select-wrapper::after {
  right: 14px;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* Cards & Grid */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}
@media (min-width: 1024px) {
  .card-grid { grid-template-columns: 1fr 1fr; }
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-header);
}
.card-header h3 { 
  margin: 0; 
  font-size: 16px; 
  font-weight: 600;
}

#notesBreadcrumb {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 20ch;
}

.card-body { padding: 20px; }

.badge {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--secondary);
  color: var(--text-muted);
  font-weight: 600;
}

/* Forms */
.form-group { margin-bottom: 16px; }
label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 500; color: var(--text-muted); }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-sans);
  font-size: 16px; /* Prevents iOS zoom on focus */
  transition: border-color 0.15s, box-shadow 0.15s;
  background-color: var(--bg-input);
  color: var(--text-main);
}

::placeholder {
  color: var(--text-muted);
  opacity: 1;
}
@media (min-width: 768px) {
  input, select, textarea { font-size: 14px; }
}
textarea { font-family: var(--font-mono); font-size: 13px; resize: vertical; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.select-wrapper { position: relative; }
.select-wrapper::after {
  content: '';
  position: absolute;
  right: 12px; top: 50%; transform: translateY(-50%);
  border: 5px solid transparent; border-top-color: var(--text-muted);
  pointer-events: none;
}
select { appearance: none; background: var(--bg-input); color: var(--text-main); }

.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
}
.btn svg { width: 16px; height: 16px; }
.full-width { width: 100%; }

.btn.is-busy {
  position: relative;
  pointer-events: none;
}

.btn.is-busy::before {
  content: '';
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  display: inline-block;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary { background: var(--secondary); color: var(--secondary-text); border-color: var(--border); }
.btn-secondary:hover { background: var(--secondary-hover); }

.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fecaca; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--secondary); }

.btn-icon {
  padding: 4px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon svg {
  width: 20px;
  height: 20px;
}
.btn-icon:hover { background: var(--secondary); color: var(--primary); }

.actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
}

.textarea-wrapper { position: relative; }
.btn-icon-overlay {
  position: absolute;
  top: 8px; right: 8px;
  padding: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-muted);
}
.btn-icon-overlay:hover { color: var(--primary); border-color: var(--primary); }

/* Results & Code */
.result-box {
  margin-top: 16px;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  position: relative;
}
.result-content, .code-block {
  font-family: var(--font-mono);
  font-size: 12px;
  word-break: break-all;
  color: var(--text-code);
  max-height: 120px;
  overflow-y: auto;
}
.actions-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.btn-copy {
  position: absolute;
  top: 8px; right: 8px;
  font-size: 11px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  border-radius: 4px;
  cursor: pointer;
}
.btn-copy:hover { border-color: var(--primary); color: var(--primary); }

.hidden { display: none !important; }

.stego-mode-switch {
  margin-bottom: 0;
}

.stego-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
}

.stego-checkbox-label input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary);
}

.stego-subgroup {
  margin-top: 12px;
}

.stego-preview-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

@media (min-width: 768px) {
  .stego-preview-panel {
    grid-template-columns: 1fr 1fr;
  }
}

.stego-preview-panel-single {
  grid-template-columns: 1fr;
}

.stego-preview-frame {
  min-height: 220px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-code);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.stego-preview-image {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 320px;
  object-fit: contain;
  background: var(--bg-card);
}

.stego-preview-empty {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 16px;
}

.stego-inline-status {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-muted);
}

.stego-inline-status.is-success {
  color: #059669;
}

.stego-inline-status.is-warning {
  color: #b45309;
}

.stego-inline-status.is-error {
  color: var(--danger);
}

.stego-input-invalid {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

#btnStegoEncode:disabled,
#btnStegoDecode:disabled,
#btnStegoDownload:disabled,
#btnCopyStegoDecoded:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.stego-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.stego-meta-item {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  padding: 10px;
}

.stego-meta-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.stego-meta-value {
  font-size: 13px;
  color: var(--text-main);
  font-weight: 600;
}

.stego-actions-row {
  justify-content: flex-start;
}

#stegoDecodedMeta {
  margin-bottom: 12px;
}

#stegoDecodedVerification {
  margin-bottom: 12px;
}

.stego-analysis {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  overflow: hidden;
}

.stego-analysis summary {
  cursor: pointer;
  padding: 12px 14px;
  font-weight: 600;
  list-style: none;
  background: var(--bg-header);
}

.stego-analysis summary::-webkit-details-marker {
  display: none;
}

.stego-analysis-content {
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

/* Keys Tab Specifics */
.empty-state {
  text-align: center;
  padding: 40px 20px;
}
.empty-icon {
  width: 64px; height: 64px;
  background: var(--secondary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
  color: var(--text-muted);
}
.empty-icon svg { width: 32px; height: 32px; }

.key-field {
  margin-bottom: 24px;
}
.code-display {
  background: var(--bg-code);
  padding: 12px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  word-break: break-all;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  color: var(--text-code);
  max-height: 160px;
  overflow-y: auto;
  white-space: pre-wrap;
}
.code-display.blur code { filter: blur(4px); transition: filter 0.2s; cursor: pointer; }
.code-display.blur:hover code { filter: blur(0); }

.danger-zone {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px dashed var(--border);
}
.danger-zone h4 { color: var(--danger); margin: 0 0 16px 0; }

/* Contacts */
.split-view {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}
@media (min-width: 1024px) {
  .split-view { grid-template-columns: 350px 1fr; }
}

.contacts-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.contact-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
.contact-info {
  display: flex;
  align-items: center;
  min-width: 0; /* Allow shrinking */
}
.contact-info h4 { margin: 0 0 4px 0; font-size: 14px; }
.contact-key { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-actions { display: flex; gap: 8px; flex-shrink: 0; }

@media (max-width: 480px) {
  .contact-item {
    flex-direction: column;
    align-items: flex-start;
  }
  .contact-actions {
    width: 100%;
    justify-content: flex-end;
    margin-top: 8px;
  }
}

.divider {
  display: flex; align-items: center; text-align: center; color: var(--text-muted); font-size: 12px; margin: 20px 0;
}
.divider::before, .divider::after { content: ''; flex: 1; border-bottom: 1px solid var(--border); }
.divider span { padding: 0 10px; }

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 2000;
}
.toast {
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 12px 16px;
  border-radius: 6px;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  animation: slideIn 0.3s ease-out;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
}
.toast.success { border-left: 4px solid #10b981; }
.toast.error { border-left: 4px solid #ef4444; }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Verify Status */
.verify-status {
  margin-top: 16px;
  padding: 12px;
  border-radius: 6px;
  font-weight: 600;
  text-align: center;
}
.verify-status.valid { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.verify-status.invalid { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* Mode Switch (Segmented Control) */
.mode-switch {
  display: flex;
  background: var(--bg-code);
  padding: 3px;
  border-radius: 8px;
  gap: 4px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  align-items: stretch;
}

.radio-label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s ease-out;
  text-align: center;
  user-select: none;
  position: relative;
  border: 1px solid transparent;
  margin: 0; /* Override generic label margin */
}

.radio-label:hover {
  color: var(--text-main);
}

.radio-label input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

/* Active State */
.radio-label:has(input:checked) {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  border-color: rgba(0,0,0,0.05);
}

/* Mobile Responsiveness */
.bottom-nav {
  display: none;
}

@media (max-width: 768px) {
  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    display: none;
  }

  .content-area {
    padding: 20px;
    padding-top: calc(20px + env(safe-area-inset-top));
    padding-bottom: calc(148px + env(safe-area-inset-bottom));
  }

  .bottom-nav {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    align-items: end;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: color-mix(in srgb, var(--bg-nav) 86%, transparent);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-top: 1px solid var(--border);
    padding: 10px 8px calc(10px + env(safe-area-inset-bottom));
    gap: 2px;
    z-index: 50;
    box-shadow: 0 -10px 30px rgba(15, 23, 42, 0.1);
  }

  .bottom-nav-more {
    position: relative;
    min-width: 0;
  }

  .bottom-nav-more-menu {
    position: absolute;
    right: 6px;
    bottom: calc(100% + 14px);
    display: none;
    min-width: 196px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: color-mix(in srgb, var(--bg-card) 92%, transparent);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
    flex-direction: column;
    gap: 6px;
    transform-origin: bottom right;
    overflow: hidden;
  }

  .bottom-nav-more-menu::after {
    content: '';
    position: absolute;
    right: 18px;
    bottom: -8px;
    width: 16px;
    height: 16px;
    background: inherit;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    transform: rotate(45deg);
  }

  .bottom-nav-more-menu.is-open {
    display: flex;
    animation: fadeIn 0.18s ease-out;
  }

  .bottom-nav .nav-item {
    flex-direction: column;
    gap: 4px;
    font-size: 10px;
    padding: 8px 4px;
    color: var(--text-muted);
    background: transparent;
    border-radius: 14px;
    width: 100%;
    min-width: 0;
    justify-content: center;
    text-align: center;
  }

  .bottom-nav .nav-item svg {
    width: 22px;
    height: 22px;
  }

  .bottom-nav-more-menu .nav-item {
    width: 100%;
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    padding: 12px 12px;
    font-size: 13px;
    border-radius: 12px;
    position: relative;
    z-index: 1;
  }

  .bottom-nav-more-menu .nav-item svg {
    width: 18px;
    height: 18px;
  }

  .bottom-nav .nav-item.active {
    color: var(--primary);
    background: rgba(79, 70, 229, 0.12);
  }

  .bottom-nav .nav-item:hover {
    background: rgba(0,0,0,0.05);
  }

  .vault-subtabs {
    width: 100%;
    justify-content: space-between;
  }

  .vault-subtab {
    flex: 1;
  }

  .setting-select-wrapper select {
    font-size: 16px;
  }

  .vault-hero-body,
  .vault-placeholder-body {
    flex-direction: column;
    align-items: flex-start;
  }

  .totp-toolbar,
  .totp-state-body,
  .totp-entry-main {
    flex-direction: column;
    align-items: stretch;
  }

  .totp-toolbar-actions,
  .totp-inline-actions {
    width: 100%;
  }

  .totp-toolbar-actions .btn,
  .totp-inline-actions .btn {
    flex: 1;
  }

  .totp-grid,
  .totp-form-grid {
    grid-template-columns: 1fr;
  }

  .totp-site-table-head {
    display: none;
  }

  .totp-entry-actions {
    display: none;
  }

  .totp-entry-gesture {
    display: flex;
  }

  .totp-entry-shell {
    padding: 10px 12px;
  }

  .totp-entry-main {
    grid-template-columns: 1fr;
  }

  .totp-code {
    width: 100%;
    text-align: left;
  }

  .totp-entry-runtime {
    width: 100%;
    align-items: stretch;
  }

  .totp-copy-btn {
    align-self: stretch;
  }

  /* Adjust Toast position on mobile */
  .toast-container {
    bottom: 80px;
    left: 20px;
    right: 20px;
    width: auto;
  }
  
  .toast {
    min-width: 0;
    width: 100%;
  }

  /* Adjust Card Grid for very small screens if needed */
  .card-grid {
    gap: 16px;
  }
  
  .section-header h2 {
    font-size: 20px;
  }

  .actions {
    flex-direction: column;
  }
  .actions .btn {
    width: 100%;
  }
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}

.modal-overlay.hidden {
  display: none;
}

.modal-content {
  background: var(--bg-card);
  padding: 24px;
  border-radius: var(--radius);
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  border: 1px solid var(--border);
}

.modal-content h3 {
  margin-top: 0;
  margin-bottom: 8px;
  color: var(--text-main);
}

.modal-content p {
  color: var(--text-muted);
  margin-bottom: 20px;
}


@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.shake {
  animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
  border-color: var(--danger) !important;
}

/* Password Toggle */
.password-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}
.password-wrapper input {
  padding-right: 40px;
}
.btn-toggle-pw {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-toggle-pw:hover {
  color: var(--primary);
}

/* Dark Mode Override */
body.dark-mode {
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --secondary: #374151;
  --secondary-hover: #4b5563;
  --secondary-text: #f3f4f6;
  --danger: #f87171;
  --danger-hover: #ef4444;
  --bg-app: #111827;
  --bg-card: #1f2937;
  --bg-header: #1f2937;
  --bg-input: #111827;
  --bg-code: #111827;
  --bg-nav: #1f2937;
  --border: #374151;
  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --text-code: #e5e7eb;
  --sidebar-bg: #111827;
  --sidebar-text: #e5e7eb;
  --sidebar-active: #374151;
  --toast-bg: #374151;
  --toast-text: #f9fafb;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.3), 0 1px 2px 0 rgba(0, 0, 0, 0.2);
}

/* Backup Nudge */
.backup-nudge {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.2);
  color: #d97706;
  padding: 12px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
body.dark-mode .backup-nudge {
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.1);
  border-color: rgba(251, 191, 36, 0.2);
}


.note-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px; /* Touch friendly */
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s;
}
.note-item:hover { background: var(--bg-header); }
.note-item.active { background: var(--secondary); border-left: 3px solid var(--primary); }

.note-icon {
  color: var(--text-muted);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.note-content {
  flex: 1;
  min-width: 0; /* For truncation */
}

.note-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.note-title-text {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 8px;
}

.note-date {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Light Mode Override */
body.light-mode {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --secondary: #f3f4f6;
  --secondary-hover: #e5e7eb;
  --secondary-text: #374151;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --bg-app: #f9fafb;
  --bg-card: #ffffff;
  --bg-header: #fcfcfc;
  --bg-input: #ffffff;
  --bg-code: #f3f4f6;
  --bg-nav: #ffffff;
  --border: #e5e7eb;
  --text-main: #111827;
  --text-muted: #6b7280;
  --text-code: #334155;
  --sidebar-bg: #1f2937;
  --sidebar-text: #e5e7eb;
  --sidebar-active: #374151;
  --toast-bg: #1f2937;
  --toast-text: #ffffff;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}


/* Checkbox Label */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  transition: all 0.15s;
}

.checkbox-label:hover {
  border-color: var(--primary);
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--primary);
}

/* Switch Toggle */
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
}

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 24px;
}

.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--secondary-hover);
  transition: .4s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: '';
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--primary);
}

input:checked + .slider:before {
  transform: translateX(24px);
}

/* Lock Screen */
.lock-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-app);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at top, color-mix(in srgb, var(--primary) 10%, transparent) 0%, transparent 44%),
    var(--bg-app);
}

.lock-screen.is-passcode-mode {
  padding: 0;
  justify-content: stretch;
}

.lock-card {
  width: min(100%, 420px);
  padding: 32px 28px;
  border-radius: 24px;
  border: 1px solid color-mix(in srgb, var(--primary) 18%, var(--border));
  background: color-mix(in srgb, var(--bg-card) 94%, var(--primary) 6%);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.18);
  text-align: center;
}

.lock-screen.is-passcode-mode .lock-card {
  width: 100%;
  max-width: none;
  height: 100%;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
}

.lock-screen.is-passcode-mode .lock-auth-panel {
  width: min(100%, 420px);
}

.lock-icon {
  font-size: 64px;
  margin-bottom: 20px;
  animation: pulse 2s infinite;
}

.lock-message {
  color: var(--text-muted);
  margin: 0 0 24px 0;
}

.lock-auth-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.passcode-modal-content {
  max-width: 420px;
}

.passcode-fullscreen-modal {
  z-index: 10001;
}

.passcode-fullscreen-modal .modal-content {
  width: 100%;
  max-width: none;
  height: 100%;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background:
    radial-gradient(circle at top, color-mix(in srgb, var(--primary) 10%, transparent) 0%, transparent 44%),
    var(--bg-app);
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.passcode-fullscreen-modal .passcode-modal-copy,
.passcode-fullscreen-modal .passcode-shell,
.passcode-fullscreen-modal .actions {
  width: min(100%, 420px);
}

.passcode-modal-copy {
  margin-bottom: 18px;
  text-align: center;
}

.passcode-shell {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.passcode-dots {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.passcode-dot {
  height: 12px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--primary) 24%, var(--border));
  background: color-mix(in srgb, var(--bg-app) 75%, var(--bg-card));
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.08);
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.passcode-dot.filled {
  background: var(--primary);
  border-color: var(--primary);
  transform: scale(1.04);
}

.passcode-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
}

.passcode-input:focus {
  outline: none;
}

.passcode-keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.passcode-key {
  border: 1px solid color-mix(in srgb, var(--primary) 12%, var(--border));
  border-radius: 16px;
  padding: 14px 12px;
  background: color-mix(in srgb, var(--bg-card) 94%, var(--primary) 6%);
  color: var(--text-main);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.passcode-key:hover {
  background: color-mix(in srgb, var(--bg-card) 82%, var(--primary) 18%);
  border-color: color-mix(in srgb, var(--primary) 30%, var(--border));
}

.passcode-key:active {
  transform: scale(0.98);
}

.passcode-key:disabled,
.passcode-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.passcode-key-muted {
  color: var(--text-muted);
}

@media (max-width: 640px) {
  .lock-card {
    width: 100%;
    padding: 28px 20px;
    border-radius: 20px;
  }

  .passcode-key {
    padding: 13px 10px;
  }
}

