/* ── Theme tokens ─────────────────────────────────────────── */
:root {
  --primary: #0d9488;
  --primary-hover: #0f766e;
  --primary-light: #ccfbf1;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --bg: #f9fafb;
  --bg-white: #ffffff;
  --text: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --border-focus: #0d9488;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --radius: 0.5rem;
  --radius-lg: 0.75rem;
}

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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Nav ──────────────────────────────────────────────────── */
.navbar {
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 50;
}

.navbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.navbar-brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}

.navbar-brand .subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: none;
}

@media (min-width: 768px) {
  .navbar-brand .subtitle { display: inline; }
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-links a {
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
  transition: background 0.15s, color 0.15s;
}

.nav-links a:hover {
  background: var(--bg);
  color: var(--text);
}

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.35rem;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 999px;
  background: var(--primary);
  color: white;
  margin-left: 0.25rem;
}

.nav-auth {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.nav-user {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ── Auth-state visibility ────────────────────────────────── */
.show-when-signed-in { display: none; }
.show-when-signed-out { display: flex; }
.show-when-admin { display: none; }
.hide-when-admin { display: flex; }

body.signed-in .show-when-signed-in { display: flex; }
body.signed-in .show-when-signed-out { display: none; }

body.signed-out .show-when-signed-in { display: none; }
body.signed-out .show-when-signed-out { display: flex; }

body.admin-active .show-when-admin { display: flex; }
body.admin-active .hide-when-admin { display: none; }

/* Block-level variants */
.show-when-signed-in-block { display: none; }
body.signed-in .show-when-signed-in-block { display: block; }

.show-when-signed-out-block { display: block; }
body.signed-in .show-when-signed-out-block { display: none; }

.show-when-admin-block { display: none; }
body.admin-active .show-when-admin-block { display: block; }

/* ── Main container ───────────────────────────────────────── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

/* ── Section ──────────────────────────────────────────────── */
.section {
  margin-bottom: 2rem;
}

.section-box {
  background: var(--bg-white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.section-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

/* ── Hero ─────────────────────────────────────────────────── */
.hero {
  text-align: center;
  margin-bottom: 2rem;
}

.hero h2 {
  font-size: 1.875rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.hero p {
  color: var(--text-secondary);
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  text-decoration: none;
  line-height: 1.5;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  background: #e5e7eb;
  color: var(--text);
}
.btn-secondary:hover { background: #d1d5db; }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-outline:hover {
  background: var(--bg);
  color: var(--text);
}

.btn-sm {
  padding: 0.25rem 0.625rem;
  font-size: 0.8rem;
}

.btn .icon-plus::before { content: "+"; font-size: 1.1em; font-weight: 700; }

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

/* ── Note card ────────────────────────────────────────────── */
.note-card {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  transition: box-shadow 0.15s;
}

.note-card:hover {
  box-shadow: var(--shadow-md);
}

.note-card--private {
  border-left: 3px solid var(--primary);
}

.note-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.note-card-author {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.note-card-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.note-card-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.375rem;
}

.note-card-content {
  font-size: 0.875rem;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

/* ── Badge ────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge--private {
  background: var(--primary-light);
  color: var(--primary);
}

/* ── Empty state ──────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ── Admin table ──────────────────────────────────────────── */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.admin-table th {
  text-align: left;
  padding: 0.75rem 0.5rem;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.admin-table td {
  padding: 0.625rem 0.5rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.admin-table tr:hover td {
  background: var(--bg);
}

.table-content-cell {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Modal ────────────────────────────────────────────────── */
#modal-container {
  display: none;
}

#modal-container.open {
  display: block;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal {
  background: var(--bg-white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 28rem;
  padding: 1.5rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal-header h3 {
  font-size: 1.25rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-body { }

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.modal-actions .btn {
  flex: 1;
}

/* ── Inputs ───────────────────────────────────────────────── */
.label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
  resize: vertical;
}

.input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}

/* ── Sign-in prompt ───────────────────────────────────────── */
.sign-in-prompt {
  text-align: center;
  padding: 2rem;
}

.sign-in-prompt p {
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

/* ── Footer ───────────────────────────────────────────────── */
.footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 640px) {
  .navbar-inner { flex-wrap: wrap; }
  .nav-links { order: 3; width: 100%; justify-content: center; }
  .section-header { flex-direction: column; gap: 0.75rem; align-items: flex-start; }
  .notes-grid { grid-template-columns: 1fr; }
}
