@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=Space+Mono:wght@400;700&display=swap');

:root {
  --bg: #0a0c10;
  --surface: #12151c;
  --surface-raised: #171c27;
  --border: #1e2330;
  --border-soft: #191d29;
  --text: #e7eaf0;
  --text-muted: #8891a5;
  --text-faint: #545c70;
  --accent: #6d5ef5;
  --accent-soft: #6d5ef522;
  --led: #35d488;
  --led-soft: #35d48822;
  --danger: #f1636b;
  --danger-soft: #f1636b1a;
  --radius: 10px;
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'Space Mono', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
}

body {
  background-image:
    radial-gradient(circle at 15% 0%, #6d5ef51a 0%, transparent 45%),
    radial-gradient(circle at 85% 100%, #35d4881a 0%, transparent 40%);
  background-attachment: fixed;
}

::selection { background: var(--accent-soft); color: var(--text); }

a { color: inherit; }

button {
  font-family: var(--font-body);
  cursor: pointer;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

.mono { font-family: var(--font-mono); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  transition: border-color .15s ease, transform .1s ease, background .15s ease;
}
.btn:hover { border-color: var(--text-faint); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(180deg, var(--accent), #5847e0);
  border-color: transparent;
  box-shadow: 0 1px 0 0 #ffffff22 inset, 0 8px 24px -8px #6d5ef588;
}
.btn-primary:hover { filter: brightness(1.08); }

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

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

.btn-block { width: 100%; }

input[type="text"], input[type="password"], input[type="url"], textarea, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 11px 13px;
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
  transition: border-color .15s ease;
}
input:focus, textarea:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--text-faint); }

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  cursor: pointer;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14' fill='none'%3E%3Cpath d='M3 5.5L7 9.5L11 5.5' stroke='%238891a5' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
}
select:focus { border-color: var(--accent); }
select option {
  background: var(--surface-raised);
  color: var(--text);
}

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
}

.field { margin-bottom: 16px; }

.hint { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; line-height: 1.5; }
.error-text { font-size: 13px; color: var(--danger); margin-top: 10px; display: none; }
.error-text.show { display: block; }

/* ---------- Login / signup ---------- */

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
}

.mobile-only-brand { display: none; margin-bottom: 26px; }

@media (max-width: 900px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-visual { display: none; }
  .mobile-only-brand { display: flex; }
}

.auth-visual {
  position: relative;
  padding: 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid var(--border-soft);
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--led); box-shadow: 0 0 12px 2px var(--led-soft); }
.brand-logo { width: 24px; height: 24px; border-radius: 6px; display: block; flex-shrink: 0; }

.brand-block { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-icon { width: 40px; height: 40px; border-radius: 10px; display: block; flex-shrink: 0; }
.brand-copy { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.brand-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
}
.brand-title .brand-accent { color: var(--led); }
.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar .brand-block { padding: 8px 10px 24px; }

.mobile-topbar { display: none; }

.visual-copy { max-width: 460px; }
.visual-copy .eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--led);
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-bottom: 14px;
}
.visual-copy h1 {
  font-family: var(--font-display);
  font-size: 40px;
  line-height: 1.12;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 16px;
}
.visual-copy p {
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.6;
  margin: 0;
}

.key-stage {
  position: relative;
  height: 210px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 8px 0;
}

.key-svg { position: relative; z-index: 2; filter: drop-shadow(0 20px 40px #00000080); }
.key-led { transform-origin: center; animation: pulse 2.2s ease-in-out infinite; }
.key-ring { animation: spin 14s linear infinite; transform-origin: 100px 60px; opacity: .5; }

@keyframes pulse {
  0%, 100% { opacity: .55; }
  50% { opacity: 1; }
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.stage-glow {
  position: absolute;
  width: 260px; height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--led-soft) 0%, transparent 70%);
  z-index: 1;
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-faint);
  border-top: 1px solid var(--border-soft);
  padding-top: 18px;
}
.status-strip .sep { color: var(--border); }

.auth-form-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.auth-card { width: 100%; max-width: 400px; }
.auth-card h2 {
  font-family: var(--font-display);
  font-size: 24px;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
.auth-card .sub { color: var(--text-muted); font-size: 14px; margin: 0 0 28px; line-height: 1.5; }

.tab-switch {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  margin-bottom: 26px;
}
.tab-switch button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
}
.tab-switch button.active { background: var(--surface-raised); color: var(--text); box-shadow: 0 1px 0 0 #ffffff10 inset; }

.step-note {
  margin-top: 18px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.6;
  display: none;
}
.step-note.show { display: block; }
.step-note strong { color: var(--text); }

.waiting-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--led);
  margin-top: 14px;
  display: none;
}
.waiting-row.show { display: flex; }
.spinner-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--led); animation: pulse 1s ease-in-out infinite; }

/* ---------- Dashboard ---------- */

.app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }

.nav-list { display: flex; flex-direction: column; gap: 4px; }

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }

  .mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 56px;
    padding: 0 10px 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border-soft);
    z-index: 40;
  }
  .mobile-topbar-brand {
    display: flex; align-items: center; gap: 10px;
    font-family: var(--font-display); font-weight: 700; font-size: 15px;
  }

  .sidebar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    border-right: none;
    border-top: 1px solid var(--border-soft);
    background: var(--surface);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
    z-index: 40;
  }
  .sidebar .brand-block,
  .sidebar .sidebar-footer { display: none; }

  .nav-list { flex-direction: row; gap: 2px; }
  .sidebar .nav-item {
    flex: 1;
    flex-direction: column;
    gap: 4px;
    padding: 8px 4px;
    font-size: 10.5px;
    text-align: center;
    white-space: nowrap;
  }
  .sidebar .nav-item span { overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .sidebar .nav-item svg { width: 18px; height: 18px; }

  .main { padding: 76px 16px 92px; }
}

.sidebar {
  border-right: 1px solid var(--border-soft);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar .brand { padding: 8px 10px 24px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  border: none;
  background: transparent;
  text-align: left;
  width: 100%;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--surface-raised); color: var(--text); }
.nav-item svg { opacity: .8; flex-shrink: 0; }

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--border-soft);
  padding-top: 14px;
}
.account-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  font-size: 13px;
}
.avatar {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--led));
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; font-size: 12px;
  color: #0a0c10;
}

.main { padding: 32px 40px; max-width: 980px; }
.main-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; gap: 16px; }
.main-header h1 { font-family: var(--font-display); font-size: 22px; margin: 0; letter-spacing: -0.01em; }
.main-header .sub { color: var(--text-muted); font-size: 13.5px; margin-top: 4px; }

@media (max-width: 640px) {
  .main-header { flex-direction: column; align-items: stretch; gap: 12px; }
  .main-header > .btn { width: 100%; }
}

.search-box {
  flex: 1; max-width: 340px; position: relative;
}
.search-box input { padding-left: 36px; }
.search-box svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); opacity: .5; }

.vault-grid { display: grid; gap: 10px; }

.vault-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: border-color .15s ease;
}
.vault-item:hover { border-color: var(--text-faint); }

.vault-item .item-icon {
  width: 38px; height: 38px; border-radius: 9px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; color: var(--accent);
  flex-shrink: 0;
}
.vault-item .item-main { flex: 1; min-width: 0; }
.vault-item .item-title { font-weight: 600; font-size: 14.5px; }
.vault-item .item-sub { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
.vault-item .item-actions { display: flex; gap: 4px; transition: opacity .1s; }
@media (hover: hover) {
  .vault-item .item-actions { opacity: 0; }
  .vault-item:hover .item-actions { opacity: 1; }
}
.icon-btn {
  width: 32px; height: 32px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent; color: var(--text-muted);
}
.icon-btn:hover { background: var(--surface-raised); border-color: var(--border); color: var(--text); }
@media (max-width: 760px) { .icon-btn { width: 36px; height: 36px; } }

.totp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }

.totp-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: border-color .15s ease;
}
.totp-card:hover { border-color: var(--text-faint); }
.totp-card-top { display: flex; align-items: center; gap: 12px; }
.totp-card-top .icon-btn { transition: opacity .1s; }
@media (hover: hover) {
  .totp-card-top .icon-btn { opacity: 0; }
  .totp-card:hover .totp-card-top .icon-btn { opacity: 1; }
}

.totp-code-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
}
.totp-code {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.totp-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--border-soft);
  margin-top: 10px;
  overflow: hidden;
}
.totp-progress-bar {
  height: 100%;
  background: var(--led);
  width: 100%;
  transition: width 1s linear;
}
.totp-progress-bar.low { background: var(--danger); }

.totp-advanced { margin-bottom: 16px; }
.totp-advanced summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
  user-select: none;
}
.totp-advanced summary:hover { color: var(--text); }
.totp-advanced .field:last-child { margin-bottom: 0; }

.qr-scanner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 7, 10, 0.92);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  padding: 20px;
}
.qr-scanner-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.qr-scanner-card h3 { font-family: var(--font-display); margin: 0 0 16px; font-size: 18px; text-align: center; }
.qr-video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}
.qr-video-wrap video { width: 100%; height: 100%; object-fit: cover; display: block; }
.qr-frame {
  position: absolute;
  inset: 12%;
  border: 2px solid var(--led);
  border-radius: 16px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.qr-scanner-card .sub { margin-top: 14px; color: var(--text-muted); font-size: 13px; }
.qr-scanner-card .error-text { margin-top: 4px; }
.qr-scanner-card .btn { margin-top: 14px; }

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}
.empty-state .key-stage { height: 130px; margin-bottom: 8px; }
.empty-state h3 { font-family: var(--font-display); color: var(--text); font-size: 17px; margin: 0 0 6px; }
.empty-state p { font-size: 13.5px; margin: 0 0 20px; }

/* Lock screen overlay on dashboard */
.lock-overlay {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.lock-card { text-align: center; max-width: 360px; padding: 32px; }
.lock-card h2 { font-family: var(--font-display); font-size: 20px; margin: 18px 0 8px; }
.lock-card p { color: var(--text-muted); font-size: 13.5px; line-height: 1.6; margin: 0 0 24px; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: #05060a99; backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  width: 100%; max-width: 440px; padding: 26px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}
.modal h3 { font-family: var(--font-display); margin: 0 0 20px; font-size: 18px; }
.modal-actions {
  display: flex; gap: 10px; margin-top: 22px;
  position: sticky; bottom: -26px;
  background: var(--surface);
  padding: 14px 0 2px;
  margin-bottom: -26px;
}

.credential-row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 8px;
}
.credential-row .led-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--led); flex-shrink: 0; }
.credential-row .cred-main { flex: 1; min-width: 0; }
.credential-row .cred-name { font-weight: 600; font-size: 14px; }
.credential-row .cred-meta { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; font-family: var(--font-mono); }

.toast-stack { position: fixed; bottom: 22px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: 9px;
  padding: 12px 16px; font-size: 13.5px; box-shadow: 0 12px 30px -10px #000000aa;
  animation: toast-in .18s ease;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 760px) {
  .toast-stack { left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
  .toast { width: 100%; }
}

.pw-field { display: flex; gap: 8px; }
.pw-field input { flex: 1; }
.mono-field { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .02em; resize: vertical; }

.seed-word-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}
.seed-word { position: relative; }
.seed-word-num {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-faint);
  border-right: 1px solid var(--border);
  pointer-events: none;
}
.seed-word-grid .seed-word-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 10px 10px 38px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  outline: none;
  transition: border-color .15s ease;
}
.seed-word-grid .seed-word-input:focus { border-color: var(--accent); }

@media (max-width: 420px) {
  .auth-form-wrap { padding: 20px; }
  .modal { padding: 20px; }
  .qr-scanner-card { padding: 16px; }
}
