/* ---------------------------------------------------------------- toast */

.toast-host {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: 380px;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-panel);
  box-shadow: var(--shadow);
  font-size: 13px;
  cursor: pointer;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(8px) scale(.98);
  transition: opacity .18s var(--ease), transform .18s var(--ease);
}
.toast.in { opacity: 1; transform: none; }
.toast-success { border-color: var(--success); }
.toast-success .icon { color: var(--success); }
.toast-error { border-color: var(--danger); }
.toast-error .icon { color: var(--danger); }
.toast-info .icon { color: var(--accent); }

/* ---------------------------------------------------------------- modal */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(4, 7, 11, .62);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity .16s var(--ease);
  overflow-y: auto;
}
.modal-backdrop.in { opacity: 1; }
.modal {
  width: 100%;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  transform: translateY(10px) scale(.985);
  transition: transform .18s var(--ease);
}
.modal-backdrop.in .modal { transform: none; }
.modal-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-titles { flex: 1; min-width: 0; }
.modal-title { font-size: 16px; }
.modal-subtitle { margin-top: 3px; font-size: 12.5px; color: var(--text-faint); }
.modal-body { flex: 1; padding: 18px; overflow-y: auto; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}

/* -------------------------------------------------------------- confirm */

.confirm { display: flex; gap: 14px; }
.confirm-icon {
  display: grid;
  place-items: center;
  width: 42px; height: 42px;
  flex: none;
  border-radius: 12px;
  background: var(--bg-hover);
  color: var(--text-dim);
}
.confirm-icon.danger { background: var(--danger-soft); color: var(--danger); }
.confirm-copy { display: flex; flex-direction: column; gap: 10px; padding-top: 3px; }
.confirm-message { font-size: 14px; }
.confirm-detail { font-size: 12.5px; color: var(--text-faint); }

/* --------------------------------------------------------------- switch */

.switch-field {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  cursor: pointer;
  user-select: none;
}
.switch { position: relative; flex: none; margin-top: 1px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  display: block;
  width: 38px; height: 22px;
  border-radius: 999px;
  background: var(--bg-active);
  border: 1px solid var(--border-strong);
  transition: background .16s var(--ease), border-color .16s var(--ease);
}
.switch-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform .16s var(--ease), background .16s var(--ease);
}
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(16px); background: #fff; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.switch-copy { display: flex; flex-direction: column; gap: 2px; }
.switch-label { font-weight: 500; }

/* ----------------------------------------------------------------- tags */

.tags-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
}
.tags-control:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tag-list { display: contents; }
.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 4px 2px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
}
.tag-x {
  display: grid;
  place-items: center;
  width: 16px; height: 16px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
  opacity: .7;
}
.tag-x:hover { opacity: 1; background: rgba(255,255,255,.12); }
.tag-input {
  flex: 1;
  min-width: 140px;
  height: 26px;
  border: 0;
  background: transparent;
  padding: 0 4px;
}
.tag-input:focus { box-shadow: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg-hover);
  font-size: 11.5px;
  color: var(--text-dim);
}
.chip.accent { border-color: transparent; background: var(--accent-soft); color: var(--accent); }
.chip.success { border-color: transparent; background: var(--success-soft); color: var(--success); }
.chip.warning { border-color: transparent; background: var(--warning-soft); color: var(--warning); }
.chip.danger  { border-color: transparent; background: var(--danger-soft); color: var(--danger); }

/* -------------------------------------------------------- custom fields */

.custom-fields { display: flex; flex-direction: column; gap: 8px; }
.custom-field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px minmax(0, 1.4fr) 30px;
  gap: 7px;
  align-items: center;
}
.cf-bool {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  cursor: pointer;
  font-size: 13px;
}
.cf-add { align-self: flex-start; }
@media (max-width: 620px) {
  .custom-field-row { grid-template-columns: minmax(0,1fr) 30px; }
  .cf-type, .cf-value { grid-column: 1 / -1; }
}

.uri-list { display: flex; flex-direction: column; gap: 7px; }
.uri-row { display: flex; align-items: center; gap: 7px; }
.uri-icon { display: grid; place-items: center; width: 26px; color: var(--text-faint); flex: none; }

/* ---------------------------------------------------------------- image */

.image-row { display: flex; align-items: center; gap: 14px; }
.image-actions { display: flex; flex-direction: column; gap: 7px; align-items: flex-start; }
.image-preview {
  display: grid;
  place-items: center;
  width: 76px; height: 76px;
  flex: none;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
}
.image-preview.circle { border-radius: 50%; }
.image-preview.square { border-radius: var(--radius); }
.image-preview-img { width: 100%; height: 100%; object-fit: cover; }
.image-placeholder { color: var(--text-faint); }

/* ----------------------------------------------------------------- TOTP */

.totp-code {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 5px 8px 5px 5px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-input);
}
.totp-copy {
  border: 0;
  background: transparent;
  padding: 2px 6px;
  cursor: pointer;
  color: inherit;
  font: inherit;
}
.totp-digits {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: .06em;
  color: var(--text);
}
.totp-code.compact .totp-digits { font-size: 15px; }
.totp-code.expiring .totp-digits { color: var(--warning); }
.totp-code.error .totp-digits { color: var(--danger); font-size: 13px; }
.totp-timer { display: inline-flex; align-items: center; gap: 6px; }
.totp-seconds {
  min-width: 18px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  text-align: right;
}
.totp-ring {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--pct, 1) * 360deg), var(--bg-active) 0);
  mask: radial-gradient(circle, transparent 4px, #000 5px);
  -webkit-mask: radial-gradient(circle, transparent 4px, #000 5px);
}
.totp-code.expiring .totp-ring { background: conic-gradient(var(--warning) calc(var(--pct,1)*360deg), var(--bg-active) 0); }

.totp-setup { display: flex; flex-direction: column; gap: 14px; }
.totp-tabs { display: flex; gap: 4px; padding: 3px; border-radius: var(--radius); background: var(--bg-input); }
.totp-tabs .tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.totp-tabs .tab:hover { color: var(--text); }
.totp-tabs .tab.active { background: var(--bg-panel); color: var(--text); box-shadow: var(--shadow-sm); }

.qr-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 30px 20px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-input);
  color: var(--text-dim);
  text-align: center;
  cursor: pointer;
  transition: border-color .14s var(--ease), background .14s var(--ease);
}
.qr-drop:hover, .qr-drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.qr-drop-copy { display: flex; flex-direction: column; gap: 3px; }
.qr-drop-copy strong { font-size: 13.5px; color: var(--text); }
.qr-drop-copy span { font-size: 12px; color: var(--text-faint); }

.qr-preview { display: flex; justify-content: center; }
.qr-preview img, .saved-qr img {
  max-width: 190px;
  max-height: 190px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
  padding: 6px;
}
.saved-qr { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }

/* Persistent nodes that stay mounted so updates appear without a re-render. */
.totp-status:empty, .qr-preview:empty { display: none; }

.totp-status {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 12.5px;
  border: 1px solid var(--border);
  background: var(--bg-input);
}
.totp-status.ok { border-color: var(--success); background: var(--success-soft); }
.totp-status.ok .icon { color: var(--success); }
.totp-status.error { border-color: var(--danger); background: var(--danger-soft); }
.totp-status.error .icon { color: var(--danger); }
.totp-status.scanning .icon { color: var(--accent); }

/* ---------------------------------------------------------------- flags */

.flag {
  display: inline-block;
  flex: none;
  border-radius: 2px;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .22);
  vertical-align: -2px;
}
[data-theme="light"] .flag { box-shadow: 0 0 0 1px rgba(0, 0, 0, .12); }

.flag-empty {
  display: inline-block;
  flex: none;
  border-radius: 2px;
  background: var(--bg-active);
  box-shadow: 0 0 0 1px var(--border);
}

.country-tag { display: inline-flex; align-items: center; gap: 7px; min-width: 0; }
.chip .flag { margin-right: 1px; }

/* ------------------------------------------------------- country picker */

.country-picker { position: relative; }

.country-face {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 36px;
  padding: 0 8px 0 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color .14s var(--ease), box-shadow .14s var(--ease);
}
.country-face:hover { border-color: var(--border-strong); }
.country-picker.open .country-face {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.country-face-value { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.country-face-placeholder { flex: 1; color: var(--text-faint); }
.country-caret {
  color: var(--text-faint);
  transform: rotate(90deg);
  transition: transform .16s var(--ease);
}
.country-picker.open .country-caret { transform: rotate(-90deg); }
.country-clear {
  display: grid;
  place-items: center;
  width: 20px; height: 20px;
  border-radius: 50%;
  color: var(--text-faint);
  cursor: pointer;
}
.country-clear:hover { background: var(--bg-hover); color: var(--text); }

.country-popup {
  position: absolute;
  z-index: 60;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  display: none;
  flex-direction: column;
  max-height: 292px;
  overflow: hidden;
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.country-picker.open .country-popup { display: flex; }
.country-picker.drop-up .country-popup { top: auto; bottom: calc(100% + 5px); }

.country-search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}
.country-search-row .icon { color: var(--text-faint); flex: none; margin-left: 3px; }
.country-search { height: 30px; border: 0; background: transparent; padding: 0; }
.country-search:focus { box-shadow: none; }

.country-list { overflow-y: auto; padding: 5px; }
.country-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.country-option.active { background: var(--bg-hover); }
.country-option.selected { color: var(--accent); font-weight: 550; }
.country-option.selected.active { background: var(--accent-soft); }
.country-option-name { flex: 1; min-width: 0; }
.country-option-dial { font-family: var(--mono); font-size: 12px; color: var(--text-faint); }
.country-empty { padding: 18px; text-align: center; color: var(--text-faint); font-size: 13px; }
