/* =====================================================
   Melatonin — Common Component Styles
   Flat, minimal, no animations or decorative effects
   ===================================================== */

/* ── Header ── */
.app-header {
  position: fixed;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%; max-width: 540px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-4);
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.header-title {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text);
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
}

.header-right { width: 40px; display: flex; align-items: center; justify-content: flex-end; }
.header-right a { font-size: var(--text-sm); color: var(--muted); }
.header-right a:hover { color: var(--accent); text-decoration: none; }

/* ── Hamburger ── */
.hamburger {
  width: 40px; height: 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  border-radius: var(--r-md);
}
.hamburger:hover { background: var(--surface); }

.hamburger-line {
  display: block;
  width: 18px; height: 2px;
  background: var(--subtext);
  border-radius: var(--r-full);
}

/* ── Nav Backdrop ── */
.nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 17, 27, 0.7);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms ease;
}
.nav-backdrop.visible { opacity: 1; pointer-events: all; }

/* ── Nav Drawer ── */
.nav-drawer {
  position: fixed;
  top: 0; left: 0;
  width: var(--nav-w);
  height: 100dvh;
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  z-index: 300;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 280ms ease;
  overflow-y: auto;
}
.nav-drawer.open { transform: translateX(0); }

.nav-header {
  padding: var(--sp-5) var(--sp-4);
  border-bottom: 1px solid var(--border);
}

.nav-logo {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--accent);
  margin-bottom: var(--sp-4);
}

.nav-user {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  background: var(--surface);
  border-radius: var(--r-md);
}

.nav-avatar {
  width: 36px; height: 36px;
  border-radius: var(--r-full);
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--bg-deep);
  flex-shrink: 0;
  text-transform: uppercase;
}

.nav-user-info { overflow: hidden; }
.nav-username {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-email {
  display: block;
  font-size: var(--text-xs);
  color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.nav-body { flex: 1; padding: var(--sp-3) var(--sp-2); }

.nav-section { margin-bottom: var(--sp-1); }

.nav-section-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  padding: var(--sp-3) var(--sp-3) var(--sp-1);
}

.nav-link {
  display: block;
  padding: var(--sp-3) var(--sp-3);
  border-radius: var(--r-md);
  color: var(--subtext);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
}
.nav-link:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }

.nav-footer {
  padding: var(--sp-3) var(--sp-2);
  border-top: 1px solid var(--border);
}

.nav-logout-btn {
  display: block;
  width: 100%;
  padding: var(--sp-3) var(--sp-3);
  border-radius: var(--r-md);
  color: var(--danger);
  font-size: var(--text-sm);
  font-weight: 500;
  text-align: left;
}
.nav-logout-btn:hover { background: var(--surface); }

/* ── Page Content ── */
.page-content {
  margin-top: var(--header-h);
  min-height: calc(100dvh - var(--header-h));
  padding: var(--sp-5) var(--sp-4) var(--sp-8);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  border: 1px solid transparent;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.btn:active { opacity: 0.8; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary  { background: var(--accent); color: var(--bg-deep); }
.btn-primary:hover { background: var(--ctp-lavender); text-decoration: none; }

.btn-secondary { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn-secondary:hover { background: var(--accent-dim); text-decoration: none; }

.btn-ghost { background: var(--surface); color: var(--subtext); }
.btn-ghost:hover { background: var(--surface-hi); color: var(--text); text-decoration: none; }

.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: rgba(243,139,168,0.1); text-decoration: none; }

.btn-block { width: 100%; }
.btn-lg { padding: var(--sp-4) var(--sp-6); font-size: var(--text-base); }
.btn-sm { padding: var(--sp-2) var(--sp-3); font-size: var(--text-xs); }

/* Loading spinner on button */
.btn.loading { color: transparent; position: relative; }
.btn.loading::after {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  border: 2px solid var(--bg-deep);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Forms ── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}

.form-label { font-size: var(--text-sm); font-weight: 500; color: var(--subtext); }

.form-input {
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: var(--text-base);
  outline: none;
  -webkit-appearance: none;
}
.form-input::placeholder { color: var(--muted); }
.form-input:focus { border-color: var(--accent); }
.form-input.error { border-color: var(--danger); }

.form-hint  { font-size: var(--text-xs); color: var(--muted); }
.form-error { font-size: var(--text-xs); color: var(--danger); display: none; }
.form-error.visible { display: block; }

.input-wrapper { position: relative; }
.input-wrapper .form-input { padding-right: 44px; }
.input-toggle-btn {
  position: absolute;
  right: var(--sp-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: var(--text-sm);
  padding: var(--sp-1);
}
.input-toggle-btn:hover { color: var(--subtext); }

/* ── Note Cards ── */
.note-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  margin-bottom: var(--sp-3);
}

.note-title { font-size: var(--text-base); font-weight: 600; color: var(--text); margin-bottom: var(--sp-1); }

.note-meta {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-xs);
  color: var(--muted);
  margin-bottom: var(--sp-3);
}
.note-meta-dot { color: var(--surface-top); }
.note-owner { color: var(--ctp-lavender); }

.note-divider { height: 1px; background: var(--border); margin-bottom: var(--sp-3); }

.note-body { font-size: var(--text-sm); color: var(--subtext); line-height: 1.65; white-space: pre-wrap; word-break: break-word; }

/* ── Toast ── */
.toast-container {
  position: fixed;
  top: calc(var(--header-h) + var(--sp-3));
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - var(--sp-8));
  max-width: 480px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  font-weight: 500;
  background: var(--surface-hi);
  border: 1px solid var(--border);
  opacity: 0;
  transition: opacity 200ms ease;
  pointer-events: all;
  color: var(--text);
}
.toast.visible { opacity: 1; }
.toast-success { border-color: var(--ctp-green); }
.toast-error   { border-color: var(--danger); }
.toast-info    { border-color: var(--info); }

/* ── Avatar ── */
.nav-avatar,
.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-full);
  background: var(--accent);
  font-weight: 700;
  color: var(--bg-deep);
  text-transform: uppercase;
  flex-shrink: 0;
  user-select: none;
}
.avatar-md { width: 52px;  height: 52px;  font-size: var(--text-md); }
.avatar-lg { width: 80px;  height: 80px;  font-size: var(--text-xl); }
.avatar-xl { width: 96px; height: 96px; font-size: var(--text-2xl); }

/* ── Section Header ── */
.section-title    { font-size: var(--text-xl); font-weight: 700; margin-bottom: var(--sp-1); }
.section-subtitle { font-size: var(--text-sm); color: var(--muted); }

/* ── Divider ── */
.divider {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin: var(--sp-5) 0;
  color: var(--muted);
  font-size: var(--text-xs);
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── Empty State ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--sp-12) var(--sp-6);
  gap: var(--sp-3);
  color: var(--muted);
}
.empty-state-title    { font-size: var(--text-base); font-weight: 600; color: var(--subtext); }
.empty-state-subtitle { font-size: var(--text-sm); }

/* ── Loading ── */
.spinner {
  display: inline-block;
  width: 28px; height: 28px;
  border: 2px solid var(--surface-hi);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-12);
  color: var(--muted);
  font-size: var(--text-sm);
}

/* ── Profile fields ── */
.profile-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  margin-bottom: var(--sp-5);
}
.profile-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.profile-field:last-child { border-bottom: none; }
.profile-field-label { font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.profile-field-value { font-size: var(--text-base); color: var(--text); }

/* ── Settings ── */
.settings-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  margin-bottom: var(--sp-4);
}
.settings-group-label {
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
}
.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.settings-item:last-child { border-bottom: none; }
.settings-item-label { font-size: var(--text-sm); font-weight: 500; color: var(--text); }
.settings-item-desc  { font-size: var(--text-xs); color: var(--muted); }
.settings-item-info  { display: flex; flex-direction: column; gap: 2px; }

.settings-nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.settings-nav-item:last-child { border-bottom: none; }
.settings-nav-item:hover { background: var(--bg-alt); }
.settings-nav-chevron { color: var(--muted); font-size: var(--text-sm); }

/* Toggle switch */
.toggle { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0;
  background: var(--surface-hi);
  border-radius: var(--r-full);
  cursor: pointer;
  transition: background 200ms ease;
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle-track::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: white;
  top: 3px; left: 3px;
  transition: transform 200ms ease;
}
.toggle input:checked + .toggle-track::after { transform: translateX(18px); }

/* ── Password strength ── */
.strength-bar  { height: 3px; border-radius: var(--r-full); background: var(--surface-hi); margin-top: var(--sp-2); }
.strength-fill { height: 100%; border-radius: var(--r-full); width: 0; transition: width 200ms ease, background 200ms ease; }

/* ── Notes count chip ── */
.notes-count {
  font-size: var(--text-xs);
  color: var(--muted);
  margin-bottom: var(--sp-3);
}

/* ── Prose ── */
.prose h2  { font-size: var(--text-base); color: var(--accent); margin: var(--sp-6) 0 var(--sp-2); padding-bottom: var(--sp-2); border-bottom: 1px solid var(--border); }
.prose p   { font-size: var(--text-sm); line-height: 1.75; margin-bottom: var(--sp-3); }
.prose ul  { padding-left: var(--sp-5); margin-bottom: var(--sp-3); }
.prose ul li { font-size: var(--text-sm); color: var(--subtext); line-height: 1.75; list-style: disc; margin-bottom: var(--sp-1); }
.prose strong { color: var(--text); font-weight: 600; }
