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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f4f6f9;
  color: #1a1a2e;
  min-height: 100vh;
}

/* ---- Header ---- */
.app-header {
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.logo { font-weight: 700; font-size: 1.1rem; text-decoration: none; color: #3b5bdb; }
.header-user { display: flex; align-items: center; gap: 0.75rem; font-size: 0.9rem; min-width: 0; }
.header-user span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }

/* ---- Avatar ---- */
.avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.avatar-placeholder {
  width: 32px; height: 32px; border-radius: 50%;
  background: #3b5bdb; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 0.8rem; flex-shrink: 0;
}

/* ---- Content ---- */
.content { max-width: 960px; margin: 0 auto; padding: 2rem 1.5rem; }
.loading { color: #94a3b8; padding: 2rem 0; }
.empty { color: #94a3b8; font-size: 0.95rem; }

/* ---- Page header ---- */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 0.75rem;
  margin-bottom: 1rem;
}
.page-header h2 { font-size: 1.3rem; font-weight: 700; }
.page-header h3 { font-size: 1.1rem; font-weight: 600; }

/* ---- Sort bar ---- */
.sort-bar {
  display: flex; align-items: center; gap: 0.5rem;
  margin-bottom: 1.25rem;
  font-size: 0.85rem; color: #64748b;
}
.sort-select {
  border: 1px solid #d1d5db;
  border-radius: 7px;
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  font-family: inherit;
  background: #fff;
  color: #374151;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}
.sort-select:focus { border-color: #3b5bdb; box-shadow: 0 0 0 3px rgba(59,91,219,0.1); }

/* ---- Breadcrumb ---- */
.breadcrumb { font-size: 0.875rem; color: #64748b; margin-bottom: 1.5rem; }
.breadcrumb a { color: #3b5bdb; text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* ---- Grid ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }

/* ---- Card ---- */
.card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.card:hover { box-shadow: 0 6px 20px rgba(0,0,0,0.08); transform: translateY(-2px); }
.card-body { padding: 1rem; }
.card-title { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.3rem; line-height: 1.3; }
.card-meta { font-size: 0.78rem; color: #94a3b8; }

/* ---- Thumbnails ---- */
.thumb { width: 100%; height: 130px; object-fit: cover; display: block; }
.thumb-placeholder { height: 50px; background: linear-gradient(135deg, #dbe4ff, #e0f2fe); }

/* ---- Notebook header ---- */
.notebook-header { display: flex; gap: 1.5rem; align-items: flex-start; margin-bottom: 2rem; }
.nb-thumb { width: 100px; height: 75px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.nb-thumb-placeholder {
  width: 100px; height: 75px; border-radius: 8px; flex-shrink: 0;
  background: linear-gradient(135deg, #dbe4ff, #e0f2fe);
}
.notebook-info { flex: 1; min-width: 0; }
.notebook-info h2 { font-size: 1.4rem; font-weight: 700; margin-bottom: 0.25rem; }
.notebook-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; flex-wrap: wrap; }

/* ---- Note view ---- */
.note-view { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 1.75rem; }
.note-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 0.5rem; gap: 1rem; }
.note-header h2 { font-size: 1.3rem; font-weight: 700; line-height: 1.3; }
.note-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
.note-meta { font-size: 0.8rem; color: #94a3b8; margin-bottom: 1.5rem; }
.note-body { font-size: 0.95rem; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }

/* ---- Login ---- */
.login-container { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 14px;
  padding: 2.5rem 2rem; width: 100%; max-width: 360px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.06);
}
.login-card h1 { text-align: center; margin-bottom: 1.75rem; font-size: 1.6rem; color: #3b5bdb; }
.login-card form { display: flex; flex-direction: column; gap: 1.1rem; }

/* ---- Form elements ---- */
label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.875rem; font-weight: 500; color: #374151; }
input[type="text"],
input[type="password"],
textarea {
  border: 1px solid #d1d5db;
  border-radius: 7px;
  padding: 0.55rem 0.8rem;
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
  color: inherit;
}
input:focus, textarea:focus {
  border-color: #3b5bdb;
  box-shadow: 0 0 0 3px rgba(59,91,219,0.12);
}
textarea { resize: vertical; min-height: 120px; }

/* ---- File upload ---- */
.file-upload { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.file-upload input[type="file"] { display: none; }
.file-pick-btn {
  padding: 0.4rem 0.85rem;
  border: 1px solid #d1d5db;
  border-radius: 7px;
  background: #f8fafc;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
  font-weight: 500;
  color: #374151;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.file-pick-btn:hover { background: #eef2ff; border-color: #3b5bdb; color: #3b5bdb; }
.file-pick-name {
  font-size: 0.82rem; color: #94a3b8; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; max-width: 200px;
}
.file-pick-name.has-file { color: #374151; }

/* ---- Buttons ---- */
button {
  padding: 0.5rem 1rem;
  border: 1px solid #d1d5db;
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
  font-size: 0.875rem;
  font-family: inherit;
  font-weight: 500;
  color: #374151;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
button:hover { background: #f1f5f9; }
.btn-primary { background: #3b5bdb; color: #fff; border-color: #3b5bdb; }
.btn-primary:hover { background: #2f4ac0; border-color: #2f4ac0; }
.btn-danger { color: #dc2626; border-color: #fca5a5; }
.btn-danger:hover { background: #fef2f2; }
#logout-btn { font-size: 0.8rem; padding: 0.35rem 0.75rem; }

/* ---- Modal ---- */
dialog.modal {
  position: fixed;
  inset: 0;
  margin: auto;
  height: fit-content;
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 1.75rem;
  width: calc(100% - 2rem);
  max-width: 500px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.18);
}
.modal h3 { margin-bottom: 1.25rem; font-size: 1.1rem; font-weight: 700; }
.modal form { display: flex; flex-direction: column; gap: 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }
dialog.modal::backdrop { background: rgba(15,23,42,0.5); }

/* ---- Error ---- */
.error-msg { color: #dc2626; font-size: 0.85rem; display: none; }
.error-msg.visible { display: block; }

/* ---- Divider ---- */
.section-divider { border: none; border-top: 1px solid #e2e8f0; margin: 1.5rem 0; }

/* ---- Contributor chips ---- */
.contributor-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.contributor-chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 20px;
  padding: 0.15rem 0.55rem 0.15rem 0.25rem; font-size: 0.8rem;
}
.chip-avatar { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.chip-placeholder {
  width: 20px; height: 20px; border-radius: 50%;
  background: #3b5bdb; color: #fff; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.6rem; font-weight: 700;
}

/* ---- Username hover ---- */
.u-hover { cursor: default; }
.u-hover:hover { text-decoration: underline dotted; }

/* ---- User tooltip ---- */
.user-tooltip {
  position: fixed;
  z-index: 1000;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  display: none;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  color: #1a1a2e;
}
.tooltip-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.tooltip-placeholder {
  width: 36px; height: 36px; border-radius: 50%;
  background: #3b5bdb; color: #fff;
  display: none; align-items: center; justify-content: center;
  font-weight: 600; font-size: 0.85rem; flex-shrink: 0;
}

/* ---- Mobile ---- */
@media (max-width: 600px) {
  .content { padding: 1rem; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }

  .notebook-header { flex-direction: column; gap: 1rem; }
  .nb-thumb { width: 100%; height: 160px; }
  .nb-thumb-placeholder { width: 100%; height: 120px; }

  .note-header { flex-direction: column; }
  .note-actions { align-self: flex-start; }
  .note-view { padding: 1.25rem; }

  .header-user span { display: none; }

  dialog.modal { padding: 1.25rem; }
}
