/* ==========================================================================
   Le Fil — PWA d'information
   Design sobre, mobile-first, inspiré Le Monde / Bloomberg.
   ========================================================================== */

/* ---------- Reset + base ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
               "Noto Sans", Roboto, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; height: auto; display: block; }

/* ---------- Variables de thème ---------- */
:root {
  --bg:            #ffffff;
  --bg-elev:       #f5f5f3;
  --fg:            #111111;
  --fg-muted:      #5a5a5a;
  --border:        #e4e4e0;
  --accent:        #c8102e;          /* rouge sobre façon Le Monde */
  --shadow:        0 1px 2px rgba(0,0,0,.04), 0 4px 12px rgba(0,0,0,.05);
  --radius:        6px;

  --cat-actualite: #c8102e;
  --cat-sciences:  #2563eb;
  --cat-economie:  #047857;
}

html[data-theme="dark"],
@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0d0d0d;
    --bg-elev:   #1a1a1a;
    --fg:        #f4f4f2;
    --fg-muted:  #a2a2a2;
    --border:    #2a2a2a;
    --accent:    #ff4d64;
    --shadow:    0 1px 2px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.4);
  }
}

/* Quand l'utilisateur force explicitement le thème via le toggle : */
html[data-theme="dark"] {
  --bg:        #0d0d0d;
  --bg-elev:   #1a1a1a;
  --fg:        #f4f4f2;
  --fg-muted:  #a2a2a2;
  --border:    #2a2a2a;
  --accent:    #ff4d64;
  --shadow:    0 1px 2px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.4);
}
html[data-theme="light"] {
  --bg:        #ffffff;
  --bg-elev:   #f5f5f3;
  --fg:        #111111;
  --fg-muted:  #5a5a5a;
  --border:    #e4e4e0;
  --accent:    #c8102e;
  --shadow:    0 1px 2px rgba(0,0,0,.04), 0 4px 12px rgba(0,0,0,.05);
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  padding-top: env(safe-area-inset-top);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  max-width: 820px;
  margin: 0 auto;
}

.brand {
  font-family: "Georgia", "Times New Roman", serif;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

.header-actions { display: flex; gap: 6px; }

.icon-btn {
  background: transparent;
  border: 0;
  color: var(--fg);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s ease;
}
.icon-btn:hover,
.icon-btn:focus-visible {
  background: var(--bg-elev);
  outline: none;
}
.icon-btn.small { width: 32px; height: 32px; }

/* ---------- Tabs de catégories ---------- */
.category-tabs {
  display: flex;
  gap: 4px;
  padding: 0 12px 8px;
  max-width: 820px;
  margin: 0 auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.category-tabs::-webkit-scrollbar { display: none; }

.tab {
  flex-shrink: 0;
  background: transparent;
  border: 0;
  color: var(--fg-muted);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s, color .15s;
  letter-spacing: -0.01em;
}
.tab:hover { background: var(--bg-elev); }
.tab.active {
  background: var(--fg);
  color: var(--bg);
}

/* ---------- Barre de date ---------- */
.date-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px 16px 10px;
  border-top: 1px solid var(--border);
  max-width: 820px;
  margin: 0 auto;
}
.current-date {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--fg-muted);
  min-width: 140px;
  text-align: center;
  text-transform: capitalize;
}

/* ---------- Feed ---------- */
.feed {
  max-width: 820px;
  margin: 0 auto;
  padding: 8px 0 40px;
}

.article-card {
  display: flex;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s;
}
.article-card:hover { background: var(--bg-elev); }
.article-card:active { background: var(--bg-elev); }

.article-main { flex: 1; min-width: 0; }

.article-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--fg-muted);
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.source-name { font-weight: 600; color: var(--fg); }
.category-badge {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.category-badge.actualite { background: var(--cat-actualite); }
.category-badge.sciences  { background: var(--cat-sciences); }
.category-badge.economie  { background: var(--cat-economie); }

.article-title {
  font-family: "Georgia", "Times New Roman", serif;
  font-size: 1.12rem;
  font-weight: 700;
  line-height: 1.3;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}

.article-summary {
  color: var(--fg-muted);
  font-size: 0.92rem;
  line-height: 1.45;
  margin: 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.article-thumb {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: var(--radius);
  flex-shrink: 0;
  background: var(--bg-elev);
}

/* ---------- Empty / loading / error ---------- */
.loading, .empty, .error {
  padding: 60px 20px;
  text-align: center;
  color: var(--fg-muted);
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error button {
  margin-top: 12px;
  background: var(--fg);
  color: var(--bg);
  border: 0;
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
}

/* ---------- Footer ---------- */
.app-footer {
  text-align: center;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  font-size: 0.78rem;
  color: var(--fg-muted);
  border-top: 1px solid var(--border);
}
.app-footer p { margin: 0; }

/* ---------- Modal article ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
}
.modal[aria-hidden="false"] { display: block; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  backdrop-filter: blur(2px);
}

.modal-body {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
@media (min-width: 720px) {
  .modal-body {
    top: 5vh; bottom: 5vh;
    left: 50%;
    transform: translateX(-50%);
    width: min(760px, 92vw);
    border-radius: 10px;
    box-shadow: var(--shadow);
  }
}

.modal-header {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: flex-end;
  padding: 10px 10px 0;
  background: var(--bg);
  padding-top: calc(10px + env(safe-area-inset-top));
}

.modal-content {
  padding: 0 22px 60px;
  max-width: 680px;
  margin: 0 auto;
}

.modal-content .meta {
  color: var(--fg-muted);
  font-size: 0.85rem;
  margin-bottom: 10px;
}
.modal-content h1 {
  font-family: "Georgia", "Times New Roman", serif;
  font-size: 1.7rem;
  line-height: 1.2;
  margin: 6px 0 14px;
  letter-spacing: -0.01em;
}
.modal-content .article-body {
  font-size: 1.02rem;
  line-height: 1.65;
}
.modal-content .article-body p { margin: 0 0 1.1em; }
.modal-content .article-body h2,
.modal-content .article-body h3 {
  font-family: "Georgia", "Times New Roman", serif;
  margin-top: 1.4em;
}
.modal-content .article-body img {
  border-radius: var(--radius);
  margin: 1em 0;
}
.modal-content .article-body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.modal-content .article-body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  margin-left: 0;
  color: var(--fg-muted);
  font-style: italic;
}

.read-more {
  display: inline-block;
  margin-top: 20px;
  padding: 10px 18px;
  background: var(--fg);
  color: var(--bg);
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.95rem;
}
.truncated-note {
  margin: 18px 0;
  padding: 12px 14px;
  background: var(--bg-elev);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.9rem;
  color: var(--fg-muted);
}

/* ---------- Responsive ajustements ---------- */
@media (max-width: 420px) {
  .article-thumb { width: 76px; height: 76px; }
  .article-title { font-size: 1.05rem; }
  .brand { font-size: 1.4rem; }
}
