/* ── Reset & Variables ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #242838;
  --bg4: #2e3347;
  --border: #333849;
  --text: #e8eaf0;
  --text2: #9ba3b8;
  --text3: #636b82;
  --accent: #6c63ff;
  --accent-hover: #8079ff;
  --accent-dim: rgba(108, 99, 255, 0.15);
  --green: #22c55e;
  --red: #ef4444;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', monospace;
  --sidebar-w: 220px;
  --list-w: 320px;
}

html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; overflow: hidden; }

.hidden { display: none !important; }

/* ── Screen Layout ─────────────────────────────────────────────────────────── */
.screen { width: 100%; height: 100vh; }

#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 30% 20%, rgba(108,99,255,0.12) 0%, transparent 60%),
              radial-gradient(ellipse at 70% 80%, rgba(34,197,94,0.06) 0%, transparent 60%),
              var(--bg);
}

#app-screen {
  display: flex;
  flex-direction: row;
}

/* ── Auth Card ─────────────────────────────────────────────────────────────── */
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  box-shadow: var(--shadow);
}

.auth-logo { text-align: center; margin-bottom: 32px; }
.auth-logo svg { color: var(--accent); }
.auth-logo h1 { font-size: 28px; font-weight: 700; margin: 8px 0 4px; letter-spacing: -0.5px; }
.auth-logo p { color: var(--text2); font-size: 13px; }

.auth-form h2 { font-size: 18px; font-weight: 600; margin-bottom: 20px; }
.form-hint { font-size: 12px; color: var(--text2); margin-bottom: 20px; line-height: 1.4; }

.auth-loading { text-align: center; padding: 20px; }
.auth-loading p { color: var(--text2); margin-top: 16px; font-size: 14px; }

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 16px;
}
.sidebar-header svg { color: var(--accent); flex-shrink: 0; }

.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: none;
  background: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 13px;
  text-align: left;
  width: 100%;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.nav-icon { font-size: 14px; width: 18px; text-align: center; flex-shrink: 0; }
.nav-count {
  margin-left: auto;
  font-size: 11px;
  background: var(--bg4);
  color: var(--text3);
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}
.nav-item.active .nav-count { background: var(--accent-dim); color: var(--accent); }

.sidebar-footer {
  padding: 10px 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 1px;
}

/* ── List Panel ────────────────────────────────────────────────────────────── */
.list-panel {
  width: var(--list-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  border-right: 1px solid var(--border);
  background: var(--bg);
}

.list-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-wrap {
  position: relative;
}
.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text3);
  pointer-events: none;
}
#search-input {
  width: 100%;
  padding: 8px 10px 8px 32px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
#search-input:focus { border-color: var(--accent); }
#search-input::placeholder { color: var(--text3); }

#add-btn {
  width: 100%;
  justify-content: center;
}

.credentials-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ── Credential Row Items ──────────────────────────────────────────────────── */
.credential-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
  user-select: none;
}
.credential-card:hover { background: var(--bg2); }
.credential-card.selected { background: var(--accent-dim); border-left: 2px solid var(--accent); }
.credential-card.selected .card-name { color: var(--accent); }

.card-icon { font-size: 20px; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: var(--bg3); border-radius: 8px; }
.card-info { flex: 1; min-width: 0; }
.card-name { font-weight: 600; font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.card-sub { font-size: 11px; color: var(--text3); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; margin-top: 1px; }

/* ── Detail Panel ──────────────────────────────────────────────────────────── */
.detail-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

.detail-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text3);
}
.detail-empty svg { opacity: 0.2; }
.detail-empty p { font-size: 14px; }

.detail-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.detail-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.detail-icon { font-size: 28px; width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; background: var(--bg3); border-radius: 12px; flex-shrink: 0; }
.detail-title-block { flex: 1; min-width: 0; }
.detail-title { font-size: 18px; font-weight: 700; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.detail-category { margin-top: 3px; }
.detail-actions { display: flex; gap: 6px; flex-shrink: 0; }

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Detail Fields ─────────────────────────────────────────────────────────── */
.detail-field label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 5px;
}

.field-value {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  height: 38px;
}
.field-value span {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  min-width: 0;
}
.field-value a {
  flex: 1;
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.field-value a:hover { text-decoration: underline; }

.field-value-text {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
  font-family: var(--font);
}

.password-dots { letter-spacing: 3px; font-family: var(--font-mono); color: var(--text2); }

.detail-meta {
  font-size: 11px;
  color: var(--text3);
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* ── Empty / Loading States ────────────────────────────────────────────────── */
.list-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 20px;
  color: var(--text3);
  text-align: center;
}
.list-empty svg { opacity: 0.25; }

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 11px; font-weight: 600; color: var(--text2); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.4px; }
.required { color: var(--red); }

input[type="text"], input[type="password"], input[type="url"], input[type="search"], select, textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--text3); }
select { cursor: pointer; }
select option { background: var(--bg3); }
textarea { resize: vertical; font-size: 13px; line-height: 1.5; }

.input-wrap { position: relative; }
.input-wrap input { padding-right: 38px; }
.toggle-pw {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  border: none; background: none; cursor: pointer; font-size: 13px; color: var(--text3);
}
.toggle-pw:hover { color: var(--text); }

.strength-bar { height: 3px; background: var(--bg4); border-radius: 2px; margin-top: 5px; overflow: hidden; }
.strength-bar div { height: 100%; border-radius: 2px; transition: width 0.3s, background-color 0.3s; width: 0%; }
.pw-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 5px; }
.strength-label { font-size: 11px; font-weight: 600; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  border: none; font-family: var(--font); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all 0.12s; white-space: nowrap;
}
.btn.primary { background: var(--accent); color: white; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: var(--bg4); }
.btn.danger { background: rgba(239,68,68,0.1); color: var(--red); border: 1px solid rgba(239,68,68,0.25); }
.btn.danger:hover { background: rgba(239,68,68,0.18); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.97); }

.btn-icon {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  border: none; background: none; color: var(--text2);
  cursor: pointer; font-size: 12px; font-family: var(--font);
  transition: background 0.12s, color 0.12s; width: 100%;
}
.btn-icon:hover { background: var(--bg3); color: var(--text); }
.btn-icon.danger:hover { color: var(--red); }

.btn-text { border: none; background: none; color: var(--accent); font-size: 12px; cursor: pointer; font-family: var(--font); }
.btn-text:hover { color: var(--accent-hover); }

.btn-sm {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg3); color: var(--text2);
  font-size: 11px; font-weight: 600; font-family: var(--font); cursor: pointer;
  transition: all 0.12s; flex-shrink: 0; white-space: nowrap;
}
.btn-sm:hover { background: var(--bg4); color: var(--text); border-color: var(--accent); }
.btn-sm.show-btn.active { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }

/* ── Modals ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
  backdrop-filter: blur(3px);
}

.modal {
  width: 100%; max-width: 480px; max-height: 90vh;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden;
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 14px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close {
  width: 26px; height: 26px; border: none; background: var(--bg3);
  border-radius: 5px; color: var(--text2); cursor: pointer; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--bg4); color: var(--text); }

.modal-body { flex: 1; overflow-y: auto; padding: 18px 22px; }
.modal-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 14px 22px; border-top: 1px solid var(--border);
}

/* ── Error / Badge / Toast ─────────────────────────────────────────────────── */
.error-msg {
  color: var(--red); font-size: 13px; margin-top: 10px;
  padding: 9px 12px; background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.2); border-radius: var(--radius-sm);
}

.badge {
  display: inline-block; padding: 2px 9px;
  background: var(--accent-dim); color: var(--accent);
  border-radius: 20px; font-size: 11px; font-weight: 600;
}

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  padding: 9px 18px; border-radius: 8px; font-size: 13px; font-weight: 600;
  z-index: 9999; pointer-events: none; max-width: 340px; text-align: center;
  animation: slideUp 0.2s ease;
}
.toast.success { background: #166534; color: #bbf7d0; border: 1px solid #22c55e40; }
.toast.error   { background: #7f1d1d; color: #fecaca; border: 1px solid #ef444440; }
.toast.info    { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }

@keyframes slideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Spinner ───────────────────────────────────────────────────────────────── */
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 2px; }

/* ── Mode Toggle ───────────────────────────────────────────────────────────── */
.mode-toggle {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}
.mode-btn {
  flex: 1;
  padding: 6px 4px;
  border: none;
  border-radius: 4px;
  background: none;
  color: var(--text3);
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
.mode-btn.active { background: var(--bg2); color: var(--text); }
.mode-btn:hover:not(.active) { color: var(--text2); }

/* ── File Drop Zone ────────────────────────────────────────────────────────── */
.file-drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}
.file-drop-zone:hover, .file-drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.file-drop-zone svg { color: var(--text3); margin-bottom: 8px; }
.file-drop-zone p { color: var(--text2); font-size: 13px; margin-bottom: 4px; }
.file-hint { font-size: 11px; color: var(--text3); }

#file-selected {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
}
#file-selected-icon { font-size: 28px; flex-shrink: 0; }
#file-selected-name { font-size: 13px; font-weight: 600; color: var(--text); }

/* ── Document Cards ────────────────────────────────────────────────────────── */
.doc-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}
.doc-card:hover { background: var(--bg2); }
.doc-card.selected { background: var(--accent-dim); border-left: 2px solid var(--accent); }
.doc-card.selected .card-name { color: var(--accent); }
.doc-type-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg4);
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Document Viewer ───────────────────────────────────────────────────────── */
.modal-wide { max-width: 880px; }
.doc-viewer-body {
  min-height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px;
}
.doc-viewer-has-preview {
  align-items: stretch;
  justify-content: flex-start;
  padding: 0;
  gap: 0;
}
.doc-viewer-has-preview .doc-pdf { border-radius: 0; }
.doc-viewer-has-preview > a { margin: 12px 20px; align-self: center; }
.doc-loading { text-align: center; color: var(--text2); }
.doc-loading p { margin-top: 12px; font-size: 13px; }
.doc-image { max-width: 100%; max-height: 70vh; border-radius: var(--radius); object-fit: contain; }
.doc-pdf { width: 100%; height: 72vh; border: none; border-radius: var(--radius); }
.doc-unsupported { text-align: center; color: var(--text2); }
.doc-unsupported svg { opacity: 0.3; margin-bottom: 12px; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --list-w: 260px; }
}
@media (max-width: 680px) {
  .sidebar { display: none; }
  :root { --list-w: 100vw; }
  .detail-panel { display: none; }
  .detail-panel.mobile-show { display: flex; position: fixed; inset: 0; z-index: 100; }
}
