/* ==========================================================
   密码备忘录 · 样式
   风格基调：简洁现代 —— 大圆角、干净留白、克制配色、跟随系统深浅色
   ========================================================== */

/* ===== 主题变量 ===== */
:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --card-soft: #f1f2f5;
  --border: #e4e6ea;
  --text: #14161a;
  --text-dim: #69707d;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --ok: #16a34a;
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.08);
  --shadow: 0 12px 40px rgba(16, 24, 40, 0.08);

  /* iOS 安全区：避开刘海 / 灵动岛 / 底部横条 */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* 深色模式：背景 #191919 / 卡片 #252525 */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191919;
    --card: #252525;
    --card-soft: #2e2e2e;
    --border: #383838;
    --text: #ededed;
    --text-dim: #9b9b9b;
    --accent: #4c8dff;
    --accent-hover: #6ba0ff;
    --accent-soft: rgba(76, 141, 255, 0.16);
    --ok: #34d399;
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.12);
    --shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  }
}

/* ===== 基础 ===== */
* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1 { margin: 0; font-size: 18px; font-weight: 600; }
h2 { margin: 0; font-size: 16px; font-weight: 600; }

.hidden { display: none !important; }

/* ===== 视图 ===== */
.view { min-height: 100dvh; }

.view-center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
}

/* 视图切换的轻量入场动画 */
@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
.view:not(.hidden) { animation: view-in 0.22s ease; }

/* ===== 启动检查 ===== */
.boot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: var(--text-dim);
  font-size: 13.5px;
}
.boot p { margin: 0; }

.spinner {
  width: 26px;
  height: 26px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 卡片 ===== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.lock-card {
  width: 100%;
  max-width: 380px;
  padding: 36px 32px 26px;
  text-align: center;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  margin: 0 auto 18px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 16px;
}

.lock-card .sub {
  margin: 8px 0 24px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.6;
}

/* ===== 输入框 ===== */
.fields { display: grid; gap: 10px; }

.field { position: relative; display: block; }

.field input {
  width: 100%;
  padding: 12px 44px 12px 14px;
  font: inherit;
  color: var(--text);
  background: var(--card-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
/* 无内嵌按钮的输入框不需要右侧留白 */
.fields .field input { padding-right: 14px; }

.field input::placeholder { color: var(--text-dim); }
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* 校验失败时的轻提示抖动 */
@keyframes shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.field input.shake {
  border-color: var(--danger);
  animation: shake 0.3s ease;
}

/* 输入框内的图标按钮 */
.icon-btn {
  position: absolute;
  top: 50%;
  right: 6px;
  display: flex;
  padding: 8px;
  color: var(--text-dim);
  background: none;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transform: translateY(-50%);
}
.icon-btn:hover { color: var(--text); }
.icon-btn .eye-off { display: none; }
.icon-btn.showing .eye { display: none; }
.icon-btn.showing .eye-off { display: block; }

/* 覆盖层顶部的返回按钮（不参与绝对定位） */
.icon-btn.flat {
  position: static;
  transform: none;
  margin-left: -8px;
}

/* ===== 按钮 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  transition: background-color 0.15s, transform 0.05s, opacity 0.15s;
}
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn.primary {
  color: #ffffff;
  background: var(--accent);
}
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn.ghost {
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border);
}
.btn.ghost:hover:not(:disabled) { color: var(--text); background: var(--card-soft); }

.btn.danger {
  color: var(--danger);
  background: var(--danger-soft);
}
.btn.danger:hover:not(:disabled) { background: color-mix(in srgb, var(--danger) 16%, transparent); }

.btn.block { width: 100%; margin-top: 16px; padding: 12px; }
.btn.small { padding: 8px 14px; font-size: 14px; border-radius: 10px; }

/* ===== 状态行 ===== */
.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 20px;
  margin-top: 16px;
  color: var(--text-dim);
  font-size: 12.5px;
}

.dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}
.dot.ok { background: var(--ok); }
.dot.err { background: var(--danger); }
.dot.busy { animation: pulse 1.1s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.3; } }

/* ===== 主视图：顶栏 ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 760px;
  margin: 0 auto;
  padding: calc(14px + var(--safe-top)) 20px 14px;
}

.search {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: var(--text-dim);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search input {
  flex: 1;
  min-width: 0;
  font: inherit;
  color: var(--text);
  background: none;
  border: 0;
  outline: none;
}
.search input::placeholder { color: var(--text-dim); }

/* ===== 主视图：内容区 ===== */
.content {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 20px calc(40px + var(--safe-bottom));
}

/* ----- 条目列表 ----- */
.item-list { display: grid; gap: 10px; }

.item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.08s, box-shadow 0.15s;
}
.item:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  box-shadow: 0 6px 20px rgba(16, 24, 40, 0.07);
}
.item:active { transform: scale(0.995); }

.item-avatar {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
}

.item-main { flex: 1; min-width: 0; }

.item-title {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-sub {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  color: var(--text-dim);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 列表内的快捷复制按钮 */
.item-copy {
  display: flex;
  flex: none;
  align-items: center;
  gap: 5px;
  padding: 7px 11px;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 9px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}
.item-copy:hover {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: transparent;
}
.item-copy.done {
  color: var(--ok);
  border-color: transparent;
  background: color-mix(in srgb, var(--ok) 12%, transparent);
}

/* ----- 空状态 ----- */
.empty {
  padding: 56px 24px;
  text-align: center;
  color: var(--text-dim);
}
.empty svg { opacity: 0.65; }
.empty-title {
  margin: 14px 0 4px;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
}
.empty-sub { margin: 0; font-size: 13px; }

/* ===== 覆盖层（详情 / 编辑） ===== */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  overflow-y: auto;
  background: var(--bg);
}

@keyframes sheet-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
.sheet:not(.hidden) { animation: sheet-in 0.2s ease; }

.sheet-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 20px calc(40px + var(--safe-bottom));
}

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(14px + var(--safe-top)) 0 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.sheet-head h2 {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet-body { padding-top: 20px; }

/* ----- 详情字段 ----- */
.detail-fields {
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
}
.field-row + .field-row { border-top: 1px solid var(--border); }

.field-label {
  flex: none;
  width: 52px;
  color: var(--text-dim);
  font-size: 13px;
}

.field-value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
/* 隐藏密码时使用等宽点号占位 */
.field-value.masked {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 2px;
}

.field-actions { display: flex; flex: none; gap: 4px; }

.mini-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 7px;
  color: var(--text-dim);
  background: none;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.15s, background-color 0.15s;
}
.mini-btn:hover { color: var(--accent); background: var(--accent-soft); }
.mini-btn.done { color: var(--ok); }

/* 详情页底部操作 */
.detail-fields + .btn { margin-top: 20px; }

/* ----- 编辑表单 ----- */
.form-row {
  display: block;
  margin-bottom: 18px;
}

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

.form-row input,
.form-row textarea {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-row input::placeholder,
.form-row textarea::placeholder { color: var(--text-dim); }
.form-row input:focus,
.form-row textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ===== 设置面板 ===== */
.group-title {
  margin: 0 0 8px;
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 500;
}
.group-title:not(:first-child) { margin-top: 24px; }

.group {
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.group-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  color: var(--text);
  text-align: left;
  background: none;
  border: 0;
  font: inherit;
  cursor: pointer;
  transition: background-color 0.15s;
}
.group-row + .group-row { border-top: 1px solid var(--border); }
.group-row:hover { background: var(--card-soft); }

.group-row-main { flex: 1; min-width: 0; }

.group-row-title { display: block; font-weight: 500; }

.group-row-sub {
  display: block;
  margin-top: 2px;
  color: var(--text-dim);
  font-size: 12.5px;
}

.group-arrow {
  flex: none;
  color: var(--text-dim);
  font-size: 18px;
}

.danger-text { color: var(--danger); }

.settings-note {
  margin: 24px 0 0;
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.7;
}

/* 说明提示框 */
.notice-box {
  padding: 12px 14px;
  color: var(--text-dim);
  background: var(--accent-soft);
  border-radius: 12px;
  font-size: 12.5px;
  line-height: 1.7;
}

/* ===== 模态框 ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  background: rgba(0, 0, 0, 0.45);
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: none; }
}
.modal:not(.hidden) .modal-card { animation: modal-in 0.16s ease; }

.modal-card {
  width: 100%;
  max-width: 340px;
  padding: 22px;
}
.modal-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
}
.modal-card p {
  margin: 0 0 16px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.6;
}
.modal-card input {
  width: 100%;
  padding: 11px 13px;
  font: inherit;
  color: var(--text);
  background: var(--card-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
}
.modal-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
.modal-actions .btn {
  padding: 9px 16px;
  font-size: 14px;
  border-radius: 10px;
}

/* ===== 轻提示 ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(32px + var(--safe-bottom));
  z-index: 100;
  padding: 11px 20px;
  color: var(--bg);
  background: var(--text);
  border-radius: 999px;
  font-size: 13.5px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
  transform: translateX(-50%);
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
.toast:not(.hidden) { animation: toast-in 0.18s ease; }

/* ===== 小屏适配 ===== */
@media (max-width: 560px) {
  .topbar-inner {
    flex-wrap: wrap;
    gap: 10px;
    padding: calc(12px + var(--safe-top)) 16px 12px;
  }
  .topbar-inner h1 { flex: 1; }
  .search { order: 3; flex-basis: 100%; }

  .content { padding: 14px 16px calc(40px + var(--safe-bottom)); }
  .lock-card { padding: 30px 22px 22px; }
  .sheet-inner { padding: 0 16px calc(40px + var(--safe-bottom)); }

  /* 小屏上列表项更紧凑，复制按钮只留图标 */
  .item { gap: 12px; padding: 13px 14px; }
  .item-copy span { display: none; }
  .item-copy { padding: 7px; }
}