:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #22223a;
  --primary: #6c63ff;
  --primary-dark: #5548e0;
  --danger: #e94560;
  --success: #27ae60;
  --text: #e8e8f0;
  --text-sub: #8888aa;
  --border: #2a2a45;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
}

#app {
  position: relative;
  height: 100dvh;
  overflow: hidden;
}

/* ── Screens ── */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  transform: translateX(30px);
  overflow: hidden;
}

.screen.active {
  opacity: 1;
  pointer-events: all;
  transform: translateX(0);
}

.screen.slide-back { transform: translateX(-30px); }

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  padding: 16px 16px;
  padding-top: calc(16px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  min-height: 60px;
  flex-shrink: 0;
}

header h2 {
  flex: 1;
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}

.icon-btn:hover, .icon-btn:active { background: var(--surface2); }

/* ── Scrollable content ── */
.scroll-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
}

/* ── Lock Screen ── */
#screen-lock {
  background: var(--bg);
  justify-content: center;
  align-items: center;
}

.lock-container {
  width: 100%;
  max-width: 380px;
  padding: 40px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.lock-logo {
  font-size: 64px;
  line-height: 1;
  filter: drop-shadow(0 4px 16px rgba(108,99,255,0.5));
}

.lock-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 1px;
}

.lock-subtitle {
  font-size: 13px;
  color: var(--text-sub);
  text-align: center;
}

.input-group {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Inputs ── */
input[type="text"],
input[type="password"],
input[type="search"],
input[type="url"],
input[type="number"],
textarea,
select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  padding: 14px 16px;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
}

input[type="password"] { letter-spacing: 2px; }
input[type="password"]::placeholder { letter-spacing: 0; }

textarea { resize: vertical; min-height: 80px; }

.password-field {
  position: relative;
}

.password-field input { padding-right: 50px; }

.eye-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-sub);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

/* ── Buttons ── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  padding: 14px 20px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  width: 100%;
}

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

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-sub); border: 1px solid var(--border); }

.btn:disabled { opacity: 0.5; pointer-events: none; }

/* FAB */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 28px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(108,99,255,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s;
  z-index: 10;
}

.fab:active { transform: scale(0.93); }

/* ── Error / Hint text ── */
.error-msg {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  min-height: 18px;
}

.hint-msg {
  color: var(--text-sub);
  font-size: 13px;
  text-align: center;
}

/* ── Search bar ── */
.search-bar {
  padding: 12px 16px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-bar input {
  background: var(--surface2);
  padding: 10px 16px;
}

/* ── Vault cards ── */
.vault-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  margin-bottom: 10px;
}

.vault-card:active { transform: scale(0.98); background: var(--surface2); }

.vault-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.vault-info { flex: 1; min-width: 0; }
.vault-name { font-weight: 600; font-size: 16px; }
.vault-count { font-size: 12px; color: var(--text-sub); margin-top: 2px; }

.vault-arrow { color: var(--text-sub); font-size: 18px; }

/* ── Entry list items ── */
.entry-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 8px;
}

.entry-item:active { background: var(--surface2); }

.entry-avatar {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  flex-shrink: 0;
  color: var(--primary);
}

.entry-info { flex: 1; min-width: 0; }
.entry-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-username { font-size: 12px; color: var(--text-sub); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Tag chips ── */
.tag-filters {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex-shrink: 0;
  scrollbar-width: none;
}

.tag-filters::-webkit-scrollbar { display: none; }

.tag-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.tag-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── Entry detail ── */
.detail-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}

.detail-row {
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.detail-row:last-child { border-bottom: none; }

.detail-label {
  font-size: 11px;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.detail-value-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.detail-value {
  flex: 1;
  font-size: 15px;
  word-break: break-all;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.detail-value.masked { letter-spacing: 4px; font-size: 14px; }

.copy-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 4px;
}

.copy-btn.copied { background: var(--success); border-color: var(--success); color: #fff; }

/* Clipboard countdown badge */
#clipboard-badge {
  position: fixed;
  bottom: calc(88px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30, 30, 50, 0.92);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 18px;
  font-size: 13px;
  color: var(--text-sub);
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 100;
}

#clipboard-badge.visible { opacity: 1; }

/* ── Form ── */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  font-size: 13px;
  color: var(--text-sub);
  margin-bottom: 6px;
  display: block;
}

.form-row {
  display: flex;
  gap: 10px;
}

.tag-input-area {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 46px;
  cursor: text;
  align-items: center;
}

.tag-input-area input {
  border: none;
  background: none;
  padding: 0;
  width: 80px;
  flex: 1;
  min-width: 60px;
  font-size: 14px;
}

.tag-badge {
  background: var(--primary);
  color: #fff;
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.tag-badge button {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  padding: 0;
  font-size: 14px;
  line-height: 1;
}

/* ── Strength bar ── */
.strength-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin-top: 8px;
  overflow: hidden;
}

.strength-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s, background 0.3s;
}

.strength-label {
  font-size: 12px;
  margin-top: 4px;
  text-align: right;
}

/* ── Generator panel ── */
.gen-result {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 18px;
  text-align: center;
  letter-spacing: 2px;
  word-break: break-all;
  margin-bottom: 12px;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gen-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.toggle-option {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.toggle-option.on { border-color: var(--primary); }

.toggle-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
  transition: background 0.15s;
}

.toggle-option.on .toggle-dot { background: var(--primary); }

.toggle-label { font-size: 13px; }

.length-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.length-row input[type="range"] {
  flex: 1;
  background: none;
  border: none;
  padding: 0;
  accent-color: var(--primary);
}

.length-display {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  min-width: 28px;
  text-align: center;
}

/* ── Settings ── */
.settings-section {
  margin-bottom: 20px;
}

.settings-title {
  font-size: 12px;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  padding: 0 4px;
}

.settings-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 8px;
}

.settings-item:active { background: var(--surface2); }

.settings-item-icon { font-size: 20px; }
.settings-item-text { flex: 1; }
.settings-item-label { font-size: 15px; font-weight: 500; }
.settings-item-desc { font-size: 12px; color: var(--text-sub); margin-top: 2px; }

/* ── Modal / Dialog ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal-sheet {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 24px 20px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  width: 100%;
  max-height: 85dvh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.25s ease;
}

.modal-overlay.open .modal-sheet { transform: translateY(0); }

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 20px;
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 16px;
}

/* ── Color picker ── */
.color-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.color-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: border-color 0.15s, transform 0.1s;
}

.color-dot.selected { border-color: var(--text); transform: scale(1.1); }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-sub);
}

.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-text { font-size: 15px; }
.empty-sub { font-size: 13px; margin-top: 6px; color: var(--text-sub); opacity: 0.7; }

/* ── Loading ── */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

@keyframes spin { to { transform: rotate(360deg); } }

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── Utility ── */
.hidden { display: none !important; }
.text-danger { color: var(--danger); }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }

/* ── Vault color border ── */
.vault-color-bar {
  width: 4px;
  border-radius: 2px;
  align-self: stretch;
  flex-shrink: 0;
}
