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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #0f1117;
  color: #e2e8f0;
  min-height: 100vh;
}

#app { display: flex; flex-direction: column; min-height: 100vh; }

nav#topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid #2d3148;
  background: #12141d;
}

nav#topnav[hidden] { display: none; }

nav .nav-brand { font-weight: 700; letter-spacing: -0.5px; color: #f8fafc; }

nav .nav-links { display: flex; gap: 8px; align-items: center; }

nav .nav-links button {
  background: transparent;
  border: 1px solid transparent;
  color: #94a3b8;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}

nav .nav-links button:hover { color: #f8fafc; background: #1a1d27; }

nav .nav-links button.active { color: #f8fafc; border-color: #2d3148; background: #1a1d27; }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 24px;
  overflow-x: hidden;
}

.view[hidden] { display: none; }

.view { width: 100%; max-width: 1100px; }

.view h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: #f8fafc;
  margin-bottom: 8px;
}

.view p.sub { color: #64748b; font-size: 0.9rem; margin-bottom: 24px; }

/* --- auth forms --- */

.auth-card {
  max-width: 380px;
  margin: 10vh auto 0;
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 16px;
  padding: 32px;
}

.auth-card h1 { text-align: center; }

.auth-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }

input, textarea, select {
  background: #0f1117;
  border: 1px solid #2d3148;
  border-radius: 8px;
  color: #e2e8f0;
  padding: 10px 12px;
  font-size: 0.9rem;
  font-family: inherit;
}

input:focus, textarea:focus, select:focus { outline: 2px solid #6366f1; }

button.primary, .auth-card button[type="submit"], #snapshotForm button[type="submit"] {
  background: #6366f1;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

button.primary:hover, .auth-card button[type="submit"]:hover { background: #4f46e5; }

button.secondary {
  background: transparent;
  color: #c7d2fe;
  border: 1px solid #3730a3;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

button.secondary:hover { background: #1e1b4b; }

.hint { margin-top: 16px; font-size: 0.78rem; color: #64748b; line-height: 1.5; }

.hint a { color: #818cf8; }

.error { margin-top: 12px; color: #ef4444; font-size: 0.85rem; min-height: 1em; }

/* --- recovery phrase display --- */

.recovery-phrase-card { max-width: 480px; }

.phrase-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 20px 0;
  background: #0f1117;
  border: 1px solid #2d3148;
  border-radius: 10px;
  padding: 16px;
}

.phrase-word {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  font-size: 0.9rem;
  color: #f8fafc;
}

.phrase-word-index { color: #64748b; font-size: 0.75rem; min-width: 1.2em; }

#recoveryPhraseDownload { margin-bottom: 16px; width: 100%; }

.phrase-confirm {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: #94a3b8;
  margin-bottom: 16px;
  cursor: pointer;
}

.phrase-confirm input { width: auto; }

#recoveryPhraseContinue:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- backup status --- */

.backup-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: #94a3b8;
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 8px;
  padding: 8px 14px;
  margin-bottom: 20px;
}

.backup-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.backup-status.ok .dot { background: #22c55e; }
.backup-status.stale .dot { background: #f59e0b; }
.backup-status.none .dot { background: #64748b; }

/* --- dashboard (chart) --- */

.card {
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 16px;
  padding: 32px;
  width: 100%;
}

.chart-wrap { position: relative; height: 480px; }

.legend { display: flex; gap: 24px; margin-bottom: 24px; flex-wrap: wrap; }

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: #94a3b8;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
}

.legend-item:hover { color: #cbd5e1; }
.legend-item.muted { color: #475569; }
.legend-item.pseudo { cursor: default; }

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
  transition: background 0.15s, box-shadow 0.15s;
}

.legend-item.muted .legend-dot {
  background: transparent !important;
  box-shadow: inset 0 0 0 2px var(--dot-color);
}

.legend-dot.pseudo { background: transparent; border: 2px dashed var(--dot-color); }

.chart-tooltip {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  background: #1e2130;
  border: 1px solid #2d3148;
  border-radius: 6px;
  padding: 14px;
  font-size: 12px;
  color: #94a3b8;
  z-index: 10;
  white-space: nowrap;
}

.chart-tooltip .ttl-title {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: #f8fafc;
  margin-bottom: 6px;
}

.chart-tooltip .ttl-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
}

.chart-tooltip .ttl-swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.chart-tooltip .ttl-swatch.pseudo { background: transparent; border: 2px dashed currentColor; }
.chart-tooltip .ttl-growth { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace; white-space: pre; }

.chart-tooltip .ttl-footer {
  margin-top: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 600;
  color: #f8fafc;
}

.chart-tooltip .g-pos { color: #22c55e; }
.chart-tooltip .g-neg { color: #ef4444; }
.chart-tooltip .g-neu { color: #94a3b8; }

/* --- manage view --- */

table.snapshots {
  width: 100%;
  border-collapse: collapse;
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 12px;
  overflow: hidden;
  font-size: 0.85rem;
}

table.snapshots th, table.snapshots td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid #2d3148;
}

table.snapshots th { color: #64748b; font-weight: 600; font-size: 0.75rem; text-transform: uppercase; }

table.snapshots tr:last-child td { border-bottom: none; }

table.snapshots button {
  background: transparent;
  border: 1px solid #2d3148;
  color: #94a3b8;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.78rem;
  cursor: pointer;
  margin-right: 6px;
}

table.snapshots button:hover { color: #f8fafc; }
table.snapshots button.danger:hover { color: #ef4444; border-color: #ef4444; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

/* --- admin view --- */

.admin-card { margin-bottom: 24px; max-width: 640px; }

.admin-card h2 { font-size: 1rem; margin-bottom: 12px; }

.admin-card .hint.warn { color: #f59e0b; margin-top: 0; margin-bottom: 16px; }

.admin-card select { display: block; width: 100%; margin-bottom: 16px; }

.admin-msg { margin-top: 10px; font-size: 0.85rem; color: #94a3b8; min-height: 1em; }

.admin-msg.error { color: #ef4444; }

.admin-msg.ok { color: #22c55e; }

.restore-confirm {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: #94a3b8;
  margin-bottom: 16px;
}

.restore-confirm input[type="text"] { width: 140px; }

button.danger-btn {
  background: transparent;
  color: #fca5a5;
  border: 1px solid #7f1d1d;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

button.danger-btn:hover:not(:disabled) { background: #450a0a; }
button.danger-btn:disabled { opacity: 0.4; cursor: not-allowed; }

#triggerBackupBtn:disabled { opacity: 0.6; cursor: not-allowed; }

#snapshotForm {
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
}

#snapshotForm .field-group { margin-bottom: 16px; }

#snapshotForm .field-group h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: #64748b;
  margin-bottom: 8px;
}

#snapshotForm .field-row { display: flex; gap: 10px; flex-wrap: wrap; }

#snapshotForm .field-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: #94a3b8;
  min-width: 150px;
}

#snapshotForm .form-actions { display: flex; gap: 10px; margin-top: 8px; }

#snapshotForm button[type="button"] {
  background: transparent;
  border: 1px solid #2d3148;
  color: #94a3b8;
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
}

#importText { width: 100%; margin-bottom: 16px; }

#importStatus { font-size: 0.85rem; color: #94a3b8; margin-top: 12px; }
