/* ─── Reset & Base ─────────────────────────────────────────────────────── */

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f5f5f7;
  color: #1d1d1f;
  min-height: 100dvh;
}

/* ─── Layout ───────────────────────────────────────────────────────────── */

.app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ─── Header ───────────────────────────────────────────────────────────── */

.header {
  background: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #e5e5e5;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header h1 {
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* ─── Buttons ──────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid #d1d1d6;
  border-radius: 8px;
  background: #fff;
  color: #1d1d1f;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover {
  background: #f0f0f2;
}

.btn-primary {
  background: #007aff;
  color: #fff;
  border-color: #007aff;
}

.btn-primary:hover {
  background: #0066d6;
}

.btn-danger {
  color: #ff3b30;
  border-color: #ff3b30;
}

.btn-danger:hover {
  background: #fff5f5;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
}

.btn-icon {
  padding: 6px 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 6px;
  font-size: 16px;
  line-height: 1;
}

.btn-icon:hover {
  background: #f0f0f2;
}

/* ─── Auth screens ─────────────────────────────────────────────────────── */

.auth-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  text-align: center;
}

.auth-card h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}

.auth-card p {
  color: #6e6e73;
  font-size: 14px;
  margin-bottom: 24px;
}

.auth-card .icon {
  font-size: 48px;
  margin-bottom: 16px;
}

/* ─── Form ─────────────────────────────────────────────────────────────── */

.form-group {
  margin-bottom: 16px;
  text-align: left;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #6e6e73;
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d1d6;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s;
}

.form-input:focus {
  outline: none;
  border-color: #007aff;
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

.password-field {
  position: relative;
}

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

.password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: #6e6e73;
  padding: 4px;
}

/* ─── Search ───────────────────────────────────────────────────────────── */

.search-bar {
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid #e5e5e5;
}

.search-bar .form-input {
  background: #f5f5f7;
  border-color: transparent;
}

.search-bar .form-input:focus {
  background: #fff;
  border-color: #007aff;
}

/* ─── Credential list ──────────────────────────────────────────────────── */

.credential-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px;
}

.credential-card {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  transition: box-shadow 0.15s;
}

.credential-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.cred-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.cred-icon {
  font-size: 28px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f7;
  border-radius: 10px;
  flex-shrink: 0;
}

.cred-info {
  flex: 1;
  min-width: 0;
}

.cred-service {
  font-size: 15px;
  font-weight: 600;
}

.cred-username {
  font-size: 13px;
  color: #6e6e73;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.cred-badge {
  display: inline-block;
  font-size: 12px;
  color: #e67e00;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 6px;
  padding: 2px 8px;
  margin-top: 6px;
}

.cred-password-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #f0f0f2;
}

.cred-password {
  flex: 1;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 13px;
  color: #1d1d1f;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cred-password.masked {
  color: #6e6e73;
}

/* ─── Empty state ──────────────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #6e6e73;
}

.empty-state .icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 15px;
}

/* ─── Modal ────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.15s;
}

.modal {
  background: #fff;
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 24px 20px;
  animation: slideUp 0.2s ease-out;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid #e5e5e5;
}

/* ─── Password generator ───────────────────────────────────────────────── */

.gen-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.gen-options label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  cursor: pointer;
}

.gen-output {
  display: flex;
  gap: 8px;
  align-items: center;
}

.gen-output code {
  flex: 1;
  background: #f5f5f7;
  padding: 10px 12px;
  border-radius: 8px;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 14px;
  word-break: break-all;
}

/* ─── Service presets ──────────────────────────────────────────────────── */

.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.preset-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-size: 11px;
  color: #6e6e73;
  transition: all 0.15s;
}

.preset-btn:hover {
  background: #f0f0f2;
  border-color: #007aff;
}

.preset-btn .icon {
  font-size: 24px;
}

/* ─── Toast ────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1d1d1f;
  color: #fff;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 200;
  animation: fadeIn 0.2s;
  pointer-events: none;
}

/* ─── Loading ──────────────────────────────────────────────────────────── */

.loading {
  text-align: center;
  padding: 40px;
  color: #6e6e73;
}

.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid #e5e5e5;
  border-top-color: #007aff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ─── Error ────────────────────────────────────────────────────────────── */

.error-msg {
  color: #ff3b30;
  font-size: 13px;
  margin-top: 8px;
}

/* ─── FAB ──────────────────────────────────────────────────────────────── */

.fab {
  position: fixed;
  bottom: 24px;
  right: max(24px, calc((100vw - 640px) / 2 + 24px));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #007aff;
  color: #fff;
  border: none;
  font-size: 28px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s;
  z-index: 50;
}

.fab:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(0, 122, 255, 0.4);
}

/* ─── Animations ───────────────────────────────────────────────────────── */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

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

/* ─── Responsive ───────────────────────────────────────────────────────── */

@media (min-width: 641px) {
  .modal-overlay {
    align-items: center;
  }
  .modal {
    border-radius: 16px;
    max-height: 80dvh;
  }
}
