/* Partitions chorale — style global */

:root {
  --primary: #6d28d9;
  --primary-dark: #5b21b6;
  --accent: #c026d3;
  --success: #15803d;
  --warning: #d97706;
  --danger: #b91c1c;
  --gray-50: #fafaf9;
  --gray-100: #f5f5f4;
  --gray-200: #e7e5e4;
  --gray-300: #d6d3d1;
  --gray-400: #a8a29e;
  --gray-500: #78716c;
  --gray-600: #57534e;
  --gray-700: #44403c;
  --gray-800: #292524;
  --gray-900: #1c1917;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.10);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.55;
  font-size: 15px;
}

.container { max-width: 1400px; margin: 0 auto; padding: 0 1.25rem; }

/* ---- Topbar ---- */
.topbar {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1.25rem; gap: 1rem;
}
.brand {
  font-weight: 700; font-size: 1.1rem; color: var(--primary);
  text-decoration: none;
}
.topnav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.topnav a {
  color: var(--gray-700); text-decoration: none; font-weight: 500;
  padding: 0.4rem 0.6rem; border-radius: var(--radius-sm);
}
.topnav a:hover { background: var(--gray-100); color: var(--primary); }
.topnav a.logout { color: var(--gray-500); }
.user-chip {
  padding: 0.25rem 0.6rem; border-radius: 999px;
  background: var(--gray-100); color: var(--gray-700); font-size: 0.85rem;
}

/* ---- Flash messages ---- */
.flash {
  padding: 0.75rem 1rem; border-radius: var(--radius); margin: 1rem 0;
  font-weight: 500;
}
.flash-success { background: #dcfce7; color: #14532d; border: 1px solid #86efac; }
.flash-error { background: #fee2e2; color: #7f1d1d; border: 1px solid #fca5a5; }
.flash-info { background: #dbeafe; color: #1e3a8a; border: 1px solid #93c5fd; }

main.container { padding-top: 1.25rem; padding-bottom: 3rem; }

h1 { font-size: 1.6rem; margin-bottom: 1rem; color: var(--gray-900); }
h2 { font-size: 1.25rem; margin: 1.5rem 0 0.75rem; }
h3 { font-size: 1rem; margin-bottom: 0.5rem; }
.muted { color: var(--gray-500); }
.small { font-size: 0.85rem; }

a { color: var(--primary); }
a:hover { color: var(--primary-dark); }

/* ---- Buttons ---- */
.btn {
  display: inline-block; padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm); border: 1px solid var(--gray-300);
  background: white; color: var(--gray-700); cursor: pointer;
  text-decoration: none; font-size: 0.9rem; font-weight: 500;
  transition: background 0.1s, border-color 0.1s;
}
.btn:hover { background: var(--gray-100); border-color: var(--gray-400); }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: white; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--gray-600); }
.btn-ghost:hover { background: var(--gray-100); color: var(--gray-900); }
.btn-danger { color: var(--danger); border-color: var(--gray-300); }
.btn-danger:hover { background: var(--danger); color: white; border-color: var(--danger); }
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.85rem; }
.btn-tiny { padding: 0.15rem 0.5rem; font-size: 0.8rem; }

/* ---- Forms ---- */
.form { display: flex; flex-direction: column; gap: 0.85rem; max-width: 720px; }
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.85rem;
}
.form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; color: var(--gray-700); font-weight: 500; }
.form label.checkbox { flex-direction: row; align-items: center; gap: 0.5rem; }
.form input, .form select, .form textarea {
  padding: 0.5rem 0.7rem; border: 1px solid var(--gray-300); border-radius: var(--radius-sm);
  font-size: 0.95rem; font-family: inherit; background: white;
}
.form input:focus, .form select:focus, .form textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(109, 40, 217, 0.15);
}
.form textarea { resize: vertical; min-height: 80px; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.form-compact textarea { width: 100%; margin-bottom: 0.5rem; }
.form-compact .checkbox { font-size: 0.85rem; margin-bottom: 0.5rem; }
.inline-form { display: inline-block; }
.inline-form input { font-size: 0.85rem; padding: 0.2rem 0.4rem; }

.auth-card {
  max-width: 400px; margin: 4rem auto;
  background: white; padding: 2rem; border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}
.auth-card h1 { text-align: center; color: var(--primary); }

/* ---- Search bar ---- */
.search-bar {
  display: flex; gap: 0.5rem; margin-bottom: 1.25rem;
  background: white; padding: 0.75rem; border-radius: var(--radius);
  box-shadow: var(--shadow); align-items: center; flex-wrap: wrap;
}
.search-bar input[type=search] {
  flex: 1; min-width: 250px;
  padding: 0.5rem 0.8rem; border: 1px solid var(--gray-300); border-radius: var(--radius-sm);
  font-size: 0.95rem;
}
.search-bar select {
  padding: 0.5rem 0.6rem; border: 1px solid var(--gray-300); border-radius: var(--radius-sm);
  font-size: 0.9rem; background: white;
}

/* ---- Layout with sidebar ---- */
.layout-with-sidebar {
  display: grid; grid-template-columns: 240px 1fr; gap: 1.5rem;
}
@media (max-width: 900px) { .layout-with-sidebar { grid-template-columns: 1fr; } }

.sidebar { background: white; padding: 1rem; border-radius: var(--radius); box-shadow: var(--shadow); height: fit-content; position: sticky; top: 70px; }
.sidebar h3 { margin-bottom: 0.5rem; color: var(--gray-700); }
.sidebar details { margin-top: 0.75rem; }
.sidebar summary { cursor: pointer; font-weight: 600; color: var(--gray-700); padding: 0.3rem 0; }
.sidebar summary:hover { color: var(--primary); }
.facet-list { list-style: none; max-height: 240px; overflow-y: auto; margin-top: 0.3rem; }
.facet-list li a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.25rem 0.5rem; border-radius: var(--radius-sm);
  text-decoration: none; color: var(--gray-700); font-size: 0.88rem;
}
.facet-list li a:hover { background: var(--gray-100); }
.facet-list li a.active { background: var(--primary); color: white; }
.facet-list .count { font-size: 0.75rem; color: var(--gray-500); }
.facet-list li a.active .count { color: rgba(255,255,255,0.85); }

/* ---- Chant grid ---- */
.chant-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0.85rem;
}
.chant-card {
  background: white; padding: 0.85rem; border-radius: var(--radius);
  box-shadow: var(--shadow); text-decoration: none; color: var(--gray-900);
  border: 1px solid transparent; transition: border-color 0.1s, box-shadow 0.1s;
  display: flex; flex-direction: column; gap: 0.4rem;
}
.chant-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); }
.chant-card-header { display: flex; justify-content: space-between; align-items: center; font-size: 0.78rem; }
.cote {
  background: var(--gray-100); color: var(--gray-700);
  padding: 0.1rem 0.45rem; border-radius: 3px; font-weight: 600;
  font-family: 'SF Mono', Menlo, monospace; font-size: 0.8rem;
}
.stars { color: var(--warning); font-size: 0.85rem; letter-spacing: 1px; }
.chant-title { font-size: 0.98rem; font-weight: 600; color: var(--gray-900); line-height: 1.3; }
.chant-meta { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.badge {
  display: inline-block; padding: 0.1rem 0.5rem;
  background: var(--gray-100); color: var(--gray-700);
  border-radius: 999px; font-size: 0.72rem; font-weight: 500;
}
.badge-moment { background: #ede9fe; color: var(--primary); }
.badge-lang { background: #fef3c7; color: #92400e; }
.badge-shared { background: #dcfce7; color: var(--success); }
.badge-danger { background: #fee2e2; color: var(--danger); }
.composer { font-size: 0.82rem; color: var(--gray-500); font-style: italic; }
.excerpt { font-size: 0.78rem; color: var(--gray-500); line-height: 1.4; }

/* ---- Pager ---- */
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; margin-top: 1.5rem; }
.pager a { text-decoration: none; padding: 0.4rem 0.8rem; background: white; border-radius: var(--radius-sm); border: 1px solid var(--gray-300); }
.empty { text-align: center; padding: 3rem; color: var(--gray-500); }

/* ---- Chant detail ---- */
.chant-header {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.chant-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.chant-layout { display: grid; grid-template-columns: 2fr 1fr; gap: 1.25rem; }
@media (max-width: 1100px) { .chant-layout { grid-template-columns: 1fr; } }

.pdf-viewer { width: 100%; height: 80vh; border: 1px solid var(--gray-200); border-radius: var(--radius); background: var(--gray-100); }

/* ---- Mobile (PWA) ---- */
@media (max-width: 700px) {
  body { font-size: 16px; }
  .container { padding: 0 0.75rem; }
  .topbar-inner { padding: 0.5rem 0.75rem; flex-wrap: wrap; gap: 0.4rem; }
  .topnav { gap: 0.4rem; }
  .topnav a { padding: 0.5rem 0.6rem; font-size: 0.9rem; }
  .user-chip { display: none; }
  h1 { font-size: 1.3rem; }
  .btn { padding: 0.6rem 0.9rem; }
  .btn-small { padding: 0.45rem 0.7rem; }
  .pdf-viewer { display: none; }              /* embed PDF inutilisable sur mobile */
  .chant-pdf::before {
    content: "📄 Le PDF s'ouvre dans votre lecteur — cliquez sur « Ouvrir dans lecteur » ci-dessus.";
    display: block; padding: 1rem; background: var(--gray-100); border-radius: var(--radius);
    color: var(--gray-700); text-align: center; font-size: 0.9rem;
  }
  .chant-layout { gap: 0.85rem; }
  .sidebar { position: static; padding: 0.75rem; }
  .sidebar details { margin-top: 0.5rem; }
  .search-bar { flex-direction: column; align-items: stretch; }
  .search-bar input[type=search] { min-width: 0; }
  .chant-grid { grid-template-columns: 1fr; }
}

.lyrics-card { margin-top: 1rem; }
.lyrics-card summary { cursor: pointer; padding: 0.5rem 0; }
.lyrics-card summary:hover { color: var(--primary); }
.lyrics-card[open] summary { margin-bottom: 0.5rem; }
.lyrics {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1rem; line-height: 1.65;
  white-space: pre-wrap; word-wrap: break-word;
  color: var(--gray-900);
  padding: 0.75rem; background: var(--gray-50); border-radius: var(--radius-sm);
  max-height: 60vh; overflow-y: auto;
}
.chant-side { display: flex; flex-direction: column; gap: 1rem; }
.card { background: white; padding: 1rem; border-radius: var(--radius); box-shadow: var(--shadow); }
.kv { display: grid; grid-template-columns: 100px 1fr; gap: 0.4rem; font-size: 0.88rem; }
.kv dt { color: var(--gray-600); }
.kv dd { color: var(--gray-900); }

/* ---- Annotations ---- */
.annotation { padding: 0.6rem 0; border-bottom: 1px solid var(--gray-100); }
.annotation:last-of-type { border-bottom: none; }
.annotation-meta { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; font-size: 0.85rem; margin-bottom: 0.25rem; }
.annotation p { font-size: 0.9rem; color: var(--gray-700); white-space: pre-wrap; }

/* ---- Playlists ---- */
.playlist-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0.85rem;
}
.playlist-card {
  background: white; padding: 1rem; border-radius: var(--radius);
  box-shadow: var(--shadow); text-decoration: none; color: var(--gray-900);
  border: 1px solid transparent; transition: border-color 0.1s;
}
.playlist-card:hover { border-color: var(--primary); }
.playlist-items { list-style: none; }
.playlist-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem; background: white; border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 0.5rem;
}
.item-pos {
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  background: var(--primary); color: white; border-radius: 50%; font-weight: 600; font-size: 0.85rem;
  flex-shrink: 0;
}
.item-body { flex: 1; min-width: 0; }
.item-title { display: flex; align-items: center; gap: 0.5rem; text-decoration: none; color: var(--gray-900); font-weight: 600; }
.item-meta { display: flex; gap: 0.3rem; flex-wrap: wrap; margin-top: 0.25rem; }
.item-actions { display: flex; gap: 0.25rem; }

.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-header-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---- Tables ---- */
.data-table { width: 100%; border-collapse: collapse; background: white; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.data-table th, .data-table td { padding: 0.6rem 0.85rem; text-align: left; border-bottom: 1px solid var(--gray-100); font-size: 0.9rem; }
.data-table thead { background: var(--gray-100); }
.data-table th { font-weight: 600; color: var(--gray-700); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; }
.data-table .actions { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.copy-target { display: inline-block; padding: 0.2rem 0.4rem; background: var(--gray-100); border-radius: 3px; font-size: 0.75rem; word-break: break-all; max-width: 360px; }

/* ---- Stats grid ---- */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.85rem; margin-bottom: 1.5rem;
}
.stat {
  background: white; padding: 1rem; border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center;
}
.stat .n { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat .l { color: var(--gray-600); font-size: 0.85rem; }
.stat.alert .n { color: var(--warning); }

/* ---- Revisions diff ---- */
.revision { background: white; padding: 1rem; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 0.85rem; }
.revision header { display: flex; gap: 0.75rem; margin-bottom: 0.5rem; }
.diff-table { width: 100%; border-collapse: collapse; margin-top: 0.5rem; }
.diff-table th, .diff-table td { padding: 0.4rem 0.6rem; border: 1px solid var(--gray-200); font-size: 0.85rem; vertical-align: top; }
.diff-table th { background: var(--gray-100); }
.diff-table del { background: #fee2e2; text-decoration: line-through; color: var(--danger); padding: 0 0.2rem; border-radius: 2px; }
.diff-table ins { background: #dcfce7; text-decoration: none; color: var(--success); padding: 0 0.2rem; border-radius: 2px; }

section { margin-bottom: 1.5rem; }
