/* Pocket Bookmarks — feuille de style unique.
   Pas de framework CSS : la surface visuelle est petite, et une feuille lisible de
   quelques centaines de lignes coûte moins cher à maintenir qu'une dépendance.
   Les couleurs passent par des variables afin que les thèmes clair/sombre/sépia ne
   soient qu'un jeu de valeurs à substituer. */

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --border: #e2e0da;
  --text: #1c1b19;
  --text-muted: #6b6862;
  --accent: #d3505a;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --radius: 10px;
  --shadow: 0 1px 3px rgb(0 0 0 / 8%);
  --max-width: 1200px;
}

[data-theme="dark"] {
  --bg: #16171a;
  --surface: #1e2024;
  --border: #303338;
  --text: #e8e6e3;
  --text-muted: #9b978f;
  --accent: #e2646d;
  --shadow: 0 1px 3px rgb(0 0 0 / 40%);
}

[data-theme="sepia"] {
  --bg: #f4ecd8;
  --surface: #fbf6e9;
  --border: #ddd2b8;
  --text: #3b3227;
  --text-muted: #7a6a52;
}

@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    --bg: #16171a;
    --surface: #1e2024;
    --border: #303338;
    --text: #e8e6e3;
    --text-muted: #9b978f;
    --accent: #e2646d;
    --shadow: 0 1px 3px rgb(0 0 0 / 40%);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a { color: inherit; }
h1, h2, h3 { line-height: 1.25; }

/* --- Barre supérieure ---------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.add-form {
  display: flex;
  gap: 8px;
  flex: 1 1 420px;
}

.add-form input[type="url"] { flex: 2 1 auto; }
.add-form input[type="text"] { flex: 1 1 140px; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-left: auto;
}

.topbar-actions a { text-decoration: none; color: var(--text-muted); }
.topbar-actions a:hover { color: var(--text); }
.topbar-actions form { margin: 0; }

/* --- Contrôles ----------------------------------------------------------- */
input[type="text"], input[type="url"], input[type="email"],
input[type="password"], input[type="search"], select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  min-width: 0;
}

input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button, .button {
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

.button.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.button.large { padding: 11px 20px; font-size: 1.05rem; }
.button.full { width: 100%; margin-top: 14px; }

.link-button {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0;
  font-size: 0.85rem;
  text-decoration: underline;
  cursor: pointer;
  font-weight: 400;
}

.link-button:hover { color: var(--text); }
.danger, .link-button.danger { color: var(--danger); }
button.danger { background: var(--danger); color: #fff; }

.icon {
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 1.1rem;
  padding: 4px 8px;
  border-radius: var(--radius);
}

.icon:hover { background: var(--bg); color: var(--text); }
.icon.on { color: var(--accent); }
.icon.danger:hover { color: var(--danger); background: transparent; }

/* --- Structure ----------------------------------------------------------- */
main { flex: 1; width: 100%; }

main.with-sidebar {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 28px;
  max-width: var(--max-width);
  margin: 24px auto;
  padding: 0 20px;
}

main.centered {
  max-width: 680px;
  margin: 40px auto;
  padding: 0 20px;
}

main.centered.wide { max-width: 900px; }

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

.auth-card h1 { margin-top: 0; }
.card-footer { margin-bottom: 0; color: var(--text-muted); font-size: 0.92rem; }

.card label { display: block; margin: 14px 0 5px; font-weight: 600; font-size: 0.92rem; }
.card input:not([type="checkbox"]), .card select { width: 100%; }
.card label.checkbox { font-weight: 400; display: flex; gap: 8px; align-items: center; }
.card label.checkbox input { width: auto; }

.hint { color: var(--text-muted); font-size: 0.86rem; margin: 6px 0; }

.flash {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin: 12px auto;
  max-width: var(--max-width);
}

.flash-error { background: #fde8e6; color: #7d1a15; }
.flash-ok { background: #e4f4e6; color: #1c5225; }

/* --- Barre latérale ------------------------------------------------------ */
.side-nav { display: flex; flex-direction: column; gap: 2px; }

.side-link {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-muted);
}

.side-link:hover { background: var(--surface); color: var(--text); }
.side-link.active { background: var(--surface); color: var(--text); font-weight: 600; }
.badge { color: var(--text-muted); font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.side-title { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em;
              color: var(--text-muted); margin: 22px 0 8px; }
.side-more { font-size: 0.85rem; color: var(--text-muted); display: inline-block; margin-top: 10px; }

/* --- Barre d'outils ------------------------------------------------------ */
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar input[type="search"] { flex: 1 1 260px; }
.result-count { color: var(--text-muted); font-size: 0.86rem; margin-left: auto; }
.trash-bar { margin-bottom: 16px; }

/* --- Liste de sauvegardes ------------------------------------------------ */
.bookmark-list { list-style: none; padding: 0; margin: 0; display: flex;
                 flex-direction: column; gap: 12px; }

.bookmark {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.bookmark.has-image { grid-template-columns: 120px minmax(0, 1fr) auto; }

.thumb {
  width: 120px;
  height: 84px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg);
}

.bookmark-body { min-width: 0; }
.bookmark h3 { margin: 0 0 4px; font-size: 1.05rem; }
.bookmark h3 a { text-decoration: none; }
.bookmark h3 a:hover { text-decoration: underline; }

.meta { color: var(--text-muted); font-size: 0.84rem; margin: 0 0 6px;
        display: flex; gap: 5px; flex-wrap: wrap; }
.meta .domain { text-decoration: none; }
.meta .pending { font-style: italic; }

.excerpt {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0 0 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tag-form { display: flex; gap: 8px; align-items: center; }
.tag-form input { flex: 1 1 auto; font-size: 0.85rem; padding: 4px 8px; }

.actions { display: flex; flex-direction: column; gap: 2px; align-items: center; }
.actions form { margin: 0; }

.empty { color: var(--text-muted); padding: 30px 0; text-align: center; }

.pagination { display: flex; gap: 16px; justify-content: center; align-items: center;
              margin: 26px 0; color: var(--text-muted); }

/* --- Page d'accueil ------------------------------------------------------ */
.hero h1 { font-size: 2.2rem; margin-bottom: 10px; }
.lede { font-size: 1.1rem; color: var(--text-muted); }
.hero-actions { display: flex; gap: 12px; margin: 24px 0 40px; flex-wrap: wrap; }
.features { list-style: none; padding: 0; display: grid;
            grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; }
.features h3 { margin: 0 0 6px; font-size: 1rem; }
.features p { margin: 0; color: var(--text-muted); font-size: 0.92rem; }

/* --- Mode lecture -------------------------------------------------------- */
.reader-main { max-width: 760px; margin: 0 auto; padding: 24px 20px 80px; }
.reader-nav { display: flex; justify-content: space-between; align-items: center;
              gap: 12px; margin-bottom: 28px; flex-wrap: wrap; }
.reader-actions { display: flex; gap: 8px; align-items: center; }
.reader-actions form { margin: 0; }
.reader-header h1 { font-size: 2rem; margin-bottom: 8px; }

.reader-content {
  font-family: var(--reader-family, Georgia, serif);
  font-size: var(--reader-size, 18px);
  line-height: 1.7;
}

.reader-content img, .reader-content figure { max-width: 100%; height: auto; }
.reader-content pre { overflow-x: auto; background: var(--bg); padding: 12px;
                      border-radius: var(--radius); }
.reader-content blockquote { margin: 1em 0; padding-left: 16px;
                             border-left: 3px solid var(--border); color: var(--text-muted); }
.reader-content table { width: 100%; border-collapse: collapse; display: block;
                        overflow-x: auto; }
.reader-content th, .reader-content td { border: 1px solid var(--border); padding: 6px 10px; }

.tag-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--bg); border: 1px solid var(--border); border-radius: 999px;
        padding: 2px 10px; font-size: 0.8rem; text-decoration: none; }

.note { background: var(--surface); border-left: 3px solid var(--accent);
        padding: 12px 16px; margin-top: 32px; border-radius: 0 var(--radius) var(--radius) 0; }
.note h2 { font-size: 0.9rem; margin: 0 0 6px; text-transform: uppercase;
           letter-spacing: 0.05em; color: var(--text-muted); }

.progress-bar { position: fixed; bottom: 0; left: 0; right: 0; height: 3px;
                background: var(--border); }
.progress-fill { height: 100%; background: var(--accent); transition: width 0.2s; }

/* --- Tableaux ------------------------------------------------------------ */
.tag-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.tag-table th { text-align: left; font-size: 0.8rem; text-transform: uppercase;
                letter-spacing: 0.04em; color: var(--text-muted);
                border-bottom: 1px solid var(--border); padding: 6px 8px; }
.tag-table td { padding: 8px; border-bottom: 1px solid var(--border); }
.tag-table td.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { flex: 1 1 auto; }

/* --- Surlignages --------------------------------------------------------- */
.highlight-add { margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--border); }
.highlight-add h2, .highlight-list h2 { font-size: 1rem; }
.highlight-add textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  resize: vertical;
}

.highlight-add label { display: block; margin: 12px 0 4px; font-weight: 600; font-size: 0.88rem; }
.highlight-add input[type="text"] { width: 100%; }

.highlight-list { margin-top: 32px; }

.highlight {
  border-left: 3px solid var(--accent);
  padding: 4px 0 4px 14px;
  margin-bottom: 20px;
}

.highlight blockquote {
  margin: 0;
  font-family: var(--reader-family, Georgia, serif);
  /* Le fond jaune évoque le surligneur, y compris en thème sombre où la teinte
     est atténuée pour rester lisible. */
  background: color-mix(in srgb, #ffe066 35%, transparent);
  padding: 2px 4px;
  border-radius: 3px;
}

[data-theme="dark"] .highlight blockquote {
  background: color-mix(in srgb, #ffe066 14%, transparent);
}

.highlight-note { color: var(--text-muted); font-size: 0.9rem; margin: 8px 0 0; }
.highlight .meta { display: flex; gap: 10px; align-items: center; margin-top: 6px; }
.highlight .meta form { margin: 0; }

/* Bouton flottant affiché au-dessus d'une sélection de texte. */
.highlight-button {
  position: absolute;
  z-index: 20;
  padding: 6px 12px;
  font-size: 0.85rem;
  box-shadow: 0 2px 8px rgb(0 0 0 / 25%);
}

/* --- Rapport d'import ---------------------------------------------------- */
.report { list-style: none; padding: 0; margin: 16px 0; }
.report li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.report li.danger { color: var(--danger); }

.error-list {
  font-size: 0.85rem;
  color: var(--text-muted);
  max-height: 260px;
  overflow-y: auto;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 12px 12px 12px 30px;
}

.error-list li { margin-bottom: 4px; word-break: break-all; }

/* --- Pied de page -------------------------------------------------------- */
.footer { display: flex; gap: 16px; justify-content: center; padding: 24px;
          color: var(--text-muted); font-size: 0.85rem; border-top: 1px solid var(--border); }

/* --- Écrans étroits ------------------------------------------------------ */
@media (max-width: 800px) {
  main.with-sidebar { grid-template-columns: 1fr; }
  .sidebar { order: 2; }
  .bookmark, .bookmark.has-image { grid-template-columns: minmax(0, 1fr); }
  .thumb { width: 100%; height: 160px; }
  .actions { flex-direction: row; justify-content: flex-end; }
}
