:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #1c1f26;
  --text-muted: #6b7280;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 920px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Top nav */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
}
.navbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text);
}
.brand span { color: var(--primary); }
.nav-links { display: flex; align-items: center; gap: 16px; }
.nav-links a, .nav-links button.linklike {
  color: var(--text-muted);
  font-size: 0.95rem;
}
.nav-links .user-pill {
  background: var(--bg);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Page shells */
.page { padding: 40px 0 80px; }
.narrow { max-width: 420px; margin: 0 auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

h1 { font-size: 1.6rem; margin: 0 0 6px; }
h2 { font-size: 1.2rem; margin: 0 0 14px; }
p.subtitle { color: var(--text-muted); margin: 0 0 24px; }

/* Forms */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
.field input:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.field .hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #eceef1; }
.btn-danger { background: #fff; color: var(--danger); border: 1px solid #f3c6c6; }
.btn-danger:hover { background: #fef2f2; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-sm { padding: 6px 10px; font-size: 0.8rem; }

.form-footer { margin-top: 18px; font-size: 0.9rem; color: var(--text-muted); text-align: center; }

/* Alerts / reminder */
.alert {
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 0.88rem;
  margin-bottom: 20px;
}
.alert-info { background: #eef2ff; color: #3730a3; border: 1px solid #e0e7ff; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

/* Dashboard */
.dash-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.note-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow);
}
.note-card h3 {
  margin: 0;
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}
.note-meta { font-size: 0.8rem; color: var(--text-muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.badge-public { background: #ecfdf5; color: #047857; }
.badge-private { background: #f1f5f9; color: #475569; }
.badge-locked { background: #fff7ed; color: #c2410c; }

.note-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

/* Editor */
.editor-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.editor-toolbar .right { display: flex; gap: 8px; flex-wrap: wrap; }
textarea.note-body {
  min-height: 360px;
  resize: vertical;
  font-size: 1rem;
  line-height: 1.6;
}
input.note-title {
  font-size: 1.3rem;
  font-weight: 700;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 6px 0;
  width: 100%;
  background: transparent;
}
input.note-title:focus {
  outline: none;
  border-bottom-color: var(--primary);
}

.share-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.share-row input {
  flex: 1;
  min-width: 160px;
  border: none;
  background: transparent;
  font-family: monospace;
  font-size: 0.9rem;
}
.share-row input:focus { outline: none; }

/* Public note reading view */
.read-view {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  box-shadow: var(--shadow);
}
.read-view h1 { margin-bottom: 4px; }
.read-view .meta { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 24px; }
.read-view .body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 1.05rem; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 18, 25, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}
.modal p { color: var(--text-muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* Toasts */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 200;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.88rem;
  box-shadow: 0 4px 14px rgba(0,0,0,0.2);
  max-width: 320px;
  animation: toast-in 0.2s ease;
}
.toast.success { background: #166534; }
.toast.error { background: #991b1b; }
@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Loading */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.5);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.btn-secondary .spinner, .btn-danger .spinner {
  border-color: rgba(0,0,0,0.2);
  border-top-color: var(--text);
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-block { text-align: center; padding: 40px; color: var(--text-muted); }

footer.site-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  padding: 30px 0;
}

@media (max-width: 560px) {
  .card, .read-view { padding: 20px; }
  .dash-header { flex-direction: column; align-items: stretch; }
}
