/* ── Reset ──────────────────────────────────────────────────────────────────── */

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

/* ── Tokens ─────────────────────────────────────────────────────────────────── */

:root {
  --bg:          #0f0f14;
  --surface:     #1a1a24;
  --surface2:    #22222e;
  --border:      #2a2a3a;
  --text:        #e8e8f0;
  --text-dim:    #8888a8;
  --accent:      #6366f1;
  --accent-h:    #818cf8;
  --danger:      #e05555;
  --warning:     #f0a030;
  --success:     #4ade80;
  --radius:      8px;
  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* ── Base ───────────────────────────────────────────────────────────────────── */

html, body, #app {
  height: 100%;
}

body {
  padding-bottom: 40px; /* room for fixed site footer */
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
}

/* ── Utility ────────────────────────────────────────────────────────────────── */

.hidden { display: none !important; }

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

.hint {
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 400;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

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

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--border); }

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

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }

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

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s;
}
.btn-icon:hover { color: var(--text); }

/* ── Inputs ─────────────────────────────────────────────────────────────────── */

label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 4px;
  margin-top: 14px;
}

input[type="text"],
input[type="password"],
input[type="search"],
textarea,
select {
  width: 100%;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
  appearance: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
}

input::placeholder, textarea::placeholder { color: var(--text-dim); }

textarea { resize: vertical; }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238888a8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ── Spinner ────────────────────────────────────────────────────────────────── */

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  margin: 14px auto;
}

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

/* ── Screens (shared) ───────────────────────────────────────────────────────── */

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  padding: 32px 24px;
}

.screen h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 20px;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.step {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-dim);
}

/* ── Start screen ───────────────────────────────────────────────────────────── */

.start-screen {
  align-items: center;
  text-align: center;
  gap: 0;
}

.brand h1 {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
}

.tagline {
  color: var(--text-dim);
  font-size: 14px;
  margin-top: 6px;
  margin-bottom: 20px;
}

.start-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 280px;
}

.start-actions .btn { width: 100%; padding: 12px 20px; }

.drop-hint {
  margin-top: 20px;
  font-size: 12px;
  color: var(--text-dim);
}

.disclaimer {
  margin-top: 24px;
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.6;
  text-align: center;
  max-width: 320px;
  line-height: 1.4;
}

/* ── How it works (start screen) ────────────────────────────────────────────── */

.how-it-works {
  list-style: none;
  margin: 0 0 28px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 280px;
  text-align: left;
}

.how-it-works li {
  font-size: 12px;
  color: var(--text-dim);
  padding-left: 14px;
  position: relative;
}

.how-it-works li::before {
  content: '—';
  position: absolute;
  left: 0;
  color: var(--accent);
}

.btn-help-link {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  margin-top: 14px;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  font-family: var(--font);
  transition: color 0.15s;
}

.btn-help-link:hover { color: var(--text); }

/* ── Help modal ─────────────────────────────────────────────────────────────── */

.help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.help-overlay.hidden { display: none !important; }

.help-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 28px 24px;
  max-width: 480px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}

.help-modal h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text);
}

.help-modal h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-h);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 18px 0 6px;
}

.help-modal h3:first-of-type { margin-top: 0; }

.help-modal p {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
}

.help-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-family: var(--font);
  transition: color 0.15s;
}

.help-close:hover { color: var(--text); }

/* ── Unlock screen ──────────────────────────────────────────────────────────── */

.unlock-screen .btn { margin-top: 10px; }

/* ── Create wizard ──────────────────────────────────────────────────────────── */

.create-screen .btn { margin-top: 10px; }

/* strength meter */
.strength-bar {
  height: 4px;
  background: var(--surface2);
  border-radius: 2px;
  margin: 8px 0 2px;
  overflow: hidden;
}

.strength-fill {
  height: 100%;
  width: 0;
  border-radius: 2px;
  transition: width 0.25s ease, background 0.25s ease;
}

.strength-fill.weak       { background: var(--danger); }
.strength-fill.fair       { background: var(--warning); }
.strength-fill.strong     { background: var(--accent); }
.strength-fill.very-strong { background: var(--success); }

.strength-label {
  font-size: 12px;
  color: var(--text-dim);
  height: 16px;
  margin-bottom: 4px;
}

/* warning step */
.warning-box {
  background: #1e1610;
  border: 1px solid #6b3d0a;
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 18px;
}

.warning-box p { font-size: 14px; margin-bottom: 10px; }
.warning-box p:last-child { margin-bottom: 0; }

.warning-headline {
  font-weight: 600;
  color: var(--warning);
}

.disclaimer-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}

.check-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  margin-top: 0;
  line-height: 1.4;
}

.check-label input[type="checkbox"] {
  width: auto;
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--accent);
}

/* recovery step */
.passphrase-reveal {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 16px;
  letter-spacing: 0.5px;
  word-break: break-all;
  color: var(--success);
  margin: 8px 0 14px;
  text-align: center;
  user-select: all;
}

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

.recovery-actions .btn { flex: 1; }

/* ── Vault toolbar ──────────────────────────────────────────────────────────── */

.vault-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 44px;
  flex-shrink: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.vault-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.3px;
}

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

/* ── Vault layout ───────────────────────────────────────────────────────────── */

.vault-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 260px 1fr;
  overflow: hidden;
  min-height: 0;
}

/* ── Section list (sidebar) ─────────────────────────────────────────────────── */

.section-list {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
}

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

.list-header input[type="search"] {
  flex: 1;
  padding: 6px 10px;
  font-size: 13px;
}

#section-items {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.section-item {
  display: flex;
  flex-direction: column;
  padding: 10px 14px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.1s;
}

.section-item:hover { background: var(--surface); }

.section-item.selected {
  background: var(--surface);
  border-left-color: var(--accent);
}

.section-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.section-type-label {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.list-empty {
  padding: 24px 14px;
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
}

/* ── Section detail (main panel) ────────────────────────────────────────────── */

.section-detail {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 20px 24px;
}

.detail-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 14px;
}

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

.detail-title {
  flex: 1;
  font-size: 18px;
  font-weight: 600;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 4px 8px;
  color: var(--text);
}

.detail-title:focus { border-color: var(--accent); background: var(--surface2); }

/* fields */
#fields-list { display: flex; flex-direction: column; gap: 8px; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1.5fr auto;
  gap: 8px;
  align-items: center;
}

.field-label { font-size: 13px; }
.field-value { font-size: 14px; }

.notes-label { margin-top: 18px; }

#btn-add-field { margin-top: 10px; align-self: flex-start; }
#btn-save      { margin-top: 18px; align-self: flex-start; }

/* add section form */
.add-section-form {
  max-width: 400px;
}

.add-section-form h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.add-section-form .btn { margin-top: 10px; }

/* ── Mobile ─────────────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .vault-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .section-list {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 40vh;
  }

  .section-detail {
    padding: 16px;
  }

  .field-row {
    grid-template-columns: 1fr 1fr auto;
  }

  .recovery-actions {
    flex-direction: column;
  }
}
