:root{
  --ink: #1B2A4A;
  --paper: #FBF6EC;
  --card: #FFFDF8;
  --marigold: #E8A93C;
  --rust: #C65D3B;
  --charcoal: #2A2118;
  --line: #D9CBB0;
  --danger: #B0432E;
  --radius: 6px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--charcoal);
  font-family: 'Inter', sans-serif;
  min-height: 100vh;
}
h1, h2, h3, .display { font-family: 'Fraunces', serif; }
.mono { font-family: 'Space Mono', monospace; }

header.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  background: var(--ink);
  color: var(--paper);
}
header.topbar .brand {
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 0.02em;
}
header.topbar .brand span { color: var(--marigold); }
header.topbar .who { display: flex; align-items: center; gap: 14px; font-size: 14px; }
header.topbar button.logout {
  background: transparent;
  border: 1px solid rgba(251,246,236,0.4);
  color: var(--paper);
  padding: 7px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}
header.topbar button.logout:hover { border-color: var(--marigold); color: var(--marigold); }
header.topbar a.topbar-link {
  background: transparent;
  border: 1px solid rgba(251,246,236,0.4);
  color: var(--paper);
  padding: 7px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  text-decoration: none;
  display: inline-block;
}
header.topbar a.topbar-link:hover { border-color: var(--marigold); color: var(--marigold); }

main { max-width: 1000px; margin: 0 auto; padding: 28px 20px 80px; }
.hidden { display: none !important; }

.login-wrap {
  max-width: 400px;
  margin: 60px auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 28px;
}
.login-wrap h1 { margin: 0 0 4px; font-size: 26px; }
.login-wrap p.sub { margin: 0 0 24px; font-size: 14px; color: #6b5e4a; }

.toggle-row {
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 18px;
}
.toggle-row button {
  flex: 1;
  padding: 9px 0;
  border: none;
  background: var(--paper);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: #6b5e4a;
  cursor: pointer;
}
.toggle-row button.active { background: var(--ink); color: var(--paper); }

label { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: #6b5e4a; margin: 14px 0 6px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  background: var(--paper);
  color: var(--charcoal);
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--marigold); outline-offset: 1px; }
textarea { resize: vertical; min-height: 70px; }

.field-hint { font-size: 12px; color: #8a7a5f; margin-top: 4px; }

/* Terms checkbox row — used on login.html (signup) and finish-setup.html.
   Previously duplicated as an inline <style> block on each page; now lives
   here once so both stay in sync automatically. */
.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13.5px;
  font-weight: normal;
  text-transform: none;
  letter-spacing: normal;
  color: var(--charcoal);
  margin: 14px 0 4px;
  cursor: pointer;
}
.checkbox-label input[type=checkbox] {
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  cursor: pointer;
  flex-shrink: 0;
}
.checkbox-label a {
  color: var(--rust);
  font-weight: 600;
  text-decoration: underline;
}

.btn {
  display: inline-block;
  border: none;
  border-radius: var(--radius);
  padding: 11px 18px;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.btn-primary { background: var(--marigold); color: var(--ink); }
.btn-primary:hover { background: #d99a2c; }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--charcoal); }
.btn-danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: white; }
.btn-block { width: 100%; margin-top: 20px; }

.error-msg { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; }
.success-msg { color: #3E7A4E; font-size: 13px; margin-top: 10px; min-height: 16px; }

.overlay {
  position: fixed; inset: 0;
  background: rgba(27,42,74,0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal {
  background: var(--card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 26px 24px;
}
.modal h2 { margin: 0 0 4px; font-size: 20px; }
.modal .close-x {
  float: right;
  background: none; border: none;
  font-size: 20px; cursor: pointer; color: #6b5e4a;
}
.modal-actions { display: flex; gap: 10px; margin-top: 22px; }
.modal-actions .btn { flex: 1; }
.img-preview {
  width: 100%; height: 130px;
  background: var(--paper);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  margin-top: 8px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  color: #b6a888; font-size: 12px;
}
.img-preview img { width: 100%; height: 100%; object-fit: contain; }

.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid rgba(27,42,74,0.3); border-top-color: var(--ink);
  border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast-stack {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: calc(100vw - 40px);
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(27,42,74,0.2);
  color: var(--paper);
  opacity: 0;
  transform: translateY(-8px);
  animation: toast-in 0.25s ease forwards, toast-out 0.3s ease forwards 2.7s;
}
.toast.success { background: #3E7A4E; }
.toast.error { background: var(--danger); }
@keyframes toast-in { to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px); } }

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: #FCEFD4;
  border: 1px solid var(--marigold);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.banner p { margin: 0; font-size: 13.5px; color: var(--charcoal); }
.banner .banner-actions { display: flex; gap: 10px; align-items: center; }
.banner .dismiss-x {
  background: none; border: none; cursor: pointer;
  font-size: 18px; color: #8a7a5f; line-height: 1; padding: 4px;
}

/* ---- Mobile-first adjustments (shared across every page) ---- */
@media (max-width: 640px) {
  header.topbar {
    padding: 14px 16px;
    flex-wrap: wrap;
    row-gap: 10px;
  }
  header.topbar .who {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
    row-gap: 8px;
  }
  main { padding: 20px 14px 60px; }

  .login-wrap {
    margin: 24px auto 40px;
    padding: 24px 18px;
    max-width: 100%;
  }

  .overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 92vh;
    padding: 22px 18px;
  }
  .modal-actions { flex-direction: column; }
  .modal-actions .btn { width: 100%; }

  .banner { flex-direction: column; align-items: flex-start; }
  .banner .banner-actions { width: 100%; }
  .banner .banner-actions .btn { flex: 1; text-align: center; }

  .toast-stack { left: 12px; right: 12px; top: 12px; max-width: none; }
}
