:root {
  --bg: #F7F8FA;
  --surface: #FFFFFF;
  --text: #111827;
  --text2: #6B7280;
  --border: #E5E7EB;
  --primary: #2563EB;
  --primary-hover: #1D4ED8;
  --success: #059669;
  --warning: #D97706;
  --danger: #DC2626;
  --danger-hover: #B91C1C;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Menlo', 'Consolas', monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

.hidden { display: none !important; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px;
  min-height: 100vh;
}

@media (max-width: 640px) {
  #app { padding: 16px; }
}

.page { animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.center-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  text-align: center;
}

.brand { margin-bottom: 32px; }
.brand h1 { font-size: 24px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.brand p { font-size: 14px; color: var(--text2); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  min-height: 44px;
}
.btn:hover { background: var(--bg); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text2);
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-block { width: 100%; }

.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 36px; }

.field { margin-bottom: 12px; text-align: left; width: 100%; }
.field label { display: block; font-size: 13px; font-weight: 500; color: var(--text2); margin-bottom: 4px; }
.field label .required { color: var(--danger); }

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrap input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  min-height: 44px;
}
.input-wrap input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.input-wrap input::placeholder { color: #9CA3AF; }

.input-wrap .toggle-pw {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: var(--text2);
  display: flex;
  align-items: center;
}
.input-wrap .toggle-pw:hover { color: var(--text); }
.input-wrap .toggle-pw svg { width: 18px; height: 18px; }

.input-wrap input[type="password"] { padding-right: 40px; }

.strength-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin-top: 6px;
  overflow: hidden;
}
.strength-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s, background 0.3s;
}
.strength-label { font-size: 12px; margin-top: 2px; }

.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 400px;
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.form-actions .btn-primary { flex: 1; }

.error-msg {
  font-size: 13px;
  color: var(--danger);
  margin-top: 4px;
}

.recovery-panel {
  width: 100%;
  max-width: 400px;
  text-align: left;
}
.recovery-panel h3 { font-size: 16px; margin-bottom: 4px; }
.recovery-panel p { font-size: 13px; color: var(--text2); margin-bottom: 16px; }

.recovery-code {
  font-family: var(--mono);
  font-size: 16px;
  letter-spacing: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  word-break: break-all;
  line-height: 1.8;
  user-select: all;
  margin-bottom: 12px;
}

.recovery-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 14px;
  cursor: pointer;
}
.checkbox-field input { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
  align-items: center;
}

.search-box {
  flex: 1;
  min-width: 160px;
  position: relative;
}
.search-box input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  min-height: 40px;
}
.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.search-box svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text2);
}

.toolbar-secondary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.entry-list { display: flex; flex-direction: column; gap: 12px; }

.entry-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: box-shadow 0.15s;
}
.entry-card:hover { box-shadow: var(--shadow-md); }

.entry-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}
.entry-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  margin-right: 8px;
}
.entry-url {
  font-size: 13px;
  color: var(--text2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 8px;
}
.entry-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.entry-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 14px;
}
.entry-row-label {
  color: var(--text2);
  font-size: 12px;
  min-width: 48px;
  flex-shrink: 0;
}
.entry-row-value {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 13px;
}
.entry-row-value.masked { letter-spacing: 2px; }
.entry-row-actions { display: flex; gap: 4px; flex-shrink: 0; }

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text2);
}
.empty-state p { margin-bottom: 16px; font-size: 15px; }
.empty-state .btn { margin: 4px; }

#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  animation: fadeIn 0.15s ease;
}
#modal-overlay.hidden { display: none; }

#modal-container {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: none; } }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: var(--text2);
  border-radius: 4px;
  display: flex;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-close svg { width: 20px; height: 20px; }

.modal-body { padding: 20px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.confirm-body { text-align: center; padding: 24px 20px; }
.confirm-body p { margin-bottom: 16px; font-size: 15px; }
.confirm-body .danger-input {
  width: 100%;
  max-width: 200px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--mono);
  text-align: center;
  text-transform: uppercase;
}
.confirm-body .danger-input:focus {
  outline: none;
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(220,38,38,0.1);
}

.bulk-editor textarea {
  width: 100%;
  min-height: 320px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
  color: var(--text);
  background: var(--surface);
}
.bulk-editor textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.bulk-result { margin-top: 12px; }
.bulk-result .result-ok { color: var(--success); font-size: 13px; margin-bottom: 8px; }
.bulk-result .result-errors { list-style: none; }
.bulk-result .result-errors li {
  font-size: 13px;
  color: var(--danger);
  padding: 4px 0;
}

.danger-zone {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.danger-zone p {
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 8px;
}

#toast-layer {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
@media (max-width: 640px) {
  #toast-layer { right: 16px; left: 16px; bottom: 16px; }
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  color: #fff;
  pointer-events: auto;
  animation: toastIn 0.2s ease;
  max-width: 320px;
  word-break: break-word;
}
.toast.info { background: var(--primary); }
.toast.success { background: var(--success); }
.toast.warning { background: var(--warning); }
.toast.error { background: var(--danger); }

@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  color: var(--text2);
  transition: all 0.15s;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn svg { width: 16px; height: 16px; }

.icon-btn-danger:hover { background: #FEF2F2; color: var(--danger); }

.loading { position: relative; color: transparent !important; }
.loading::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  top: 50%;
  left: 50%;
  margin: -9px 0 0 -9px;
}
.loading.btn-ghost::after { border-color: rgba(0,0,0,0.1); border-top-color: var(--text2); }

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

.backoff-msg {
  font-size: 13px;
  color: var(--warning);
  margin-top: 8px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--text2);
  font-size: 12px;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
  font-family: var(--font);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.link-btn:hover { text-decoration: underline; }
.link-btn svg { width: 14px; height: 14px; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.note-preview {
  font-size: 13px;
  color: var(--text2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 4px;
}

@media (max-width: 640px) {
  .toolbar { gap: 6px; }
  .search-box { min-width: 100%; order: -1; }
  .toolbar-secondary { gap: 6px; }
  .btn { padding: 8px 14px; font-size: 13px; }
  .entry-card { padding: 12px; }
  .entry-row { flex-wrap: wrap; }
  .entry-row-value { min-width: 0; }
}
