/* ============================
   Reset et bases
============================ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  color: #1a1a1a;
  background: #f5f6f8;
  line-height: 1.5;
  overflow-x: hidden;
}
img, video { max-width: 100%; display: block; height: auto; }
button, input, textarea, select { font: inherit; color: inherit; }
input, textarea, select { font-size: 16px; } /* évite zoom iOS */
button { cursor: pointer; }
a { color: #8b1538; }

:root {
  --red: #8b1538;
  --red-dark: #6b0f29;
  --red-soft: #fdecef;
  --green: #137546;
  --green-soft: #e4f5ec;
  --yellow: #b78200;
  --yellow-soft: #fef5de;
  --gray-900: #1a1a1a;
  --gray-700: #4a4a4a;
  --gray-500: #7a7a7a;
  --gray-300: #d9d9d9;
  --gray-200: #ececec;
  --gray-100: #f5f6f8;
  --tap: 44px;
}

/* ============================
   Login
============================ */
.login-page { background: linear-gradient(145deg, #8b1538, #4a0820); min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-wrap { width: 100%; max-width: 420px; }
.login-card { background: #fff; border-radius: 14px; padding: 28px 24px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card h1 { margin: 0 0 6px; color: var(--red); }
.login-card .muted { color: var(--gray-500); margin-top: 0; }
.login-card label { display: block; font-weight: 600; margin: 14px 0 6px; font-size: 14px; }
.login-card input { width: 100%; min-height: var(--tap); padding: 10px 12px; border: 1px solid var(--gray-300); border-radius: 10px; background: #fff; }
.login-card input:focus { outline: 2px solid var(--red); outline-offset: 1px; }
.login-card button { width: 100%; min-height: var(--tap); margin-top: 18px; background: var(--red); color: #fff; border: 0; border-radius: 10px; font-weight: 600; }
.login-card button:hover { background: var(--red-dark); }
.error { color: var(--red); margin: 10px 0 0; }

/* ============================
   App shell
============================ */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: #fff; border-bottom: 1px solid var(--gray-200);
  padding: 10px 14px; display: flex; align-items: center; gap: 10px;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.topbar h1 { margin: 0; font-size: 18px; color: var(--red); }
.topbar .spacer { flex: 1; }
.user-chip { background: var(--gray-100); border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 600; }
.logout-btn { background: transparent; border: 1px solid var(--gray-300); border-radius: 8px; min-height: 36px; padding: 0 10px; font-size: 14px; }

.main { flex: 1; padding: 12px; padding-bottom: calc(80px + env(safe-area-inset-bottom)); max-width: 1200px; width: 100%; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: #fff; border-top: 1px solid var(--gray-200);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  min-height: 56px; background: transparent; border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--gray-700); position: relative;
}
.tabbar button.active { color: var(--red); font-weight: 700; }
.tabbar .ico { font-size: 20px; line-height: 1; }
.tabbar .badge { position: absolute; top: 6px; right: calc(50% - 20px); background: var(--red); color: #fff; font-size: 10px; min-width: 16px; height: 16px; border-radius: 8px; display: grid; place-items: center; padding: 0 4px; font-weight: 700; }

/* ============================
   Views
============================ */
.view { display: none; }
.view.active { display: block; }
.view-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.view-header h2 { margin: 0; font-size: 20px; }

/* Bandeaux rouges objectifs entrepreneuriat */
.goals-banners { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 14px; }
.goals-banner {
  background: var(--red-soft); border: 2px solid var(--red); border-radius: 12px; padding: 12px;
}
.goals-banner h3 { margin: 0 0 8px; color: var(--red); font-size: 16px; }
.goals-banner .goal-item { display: flex; align-items: center; gap: 8px; padding: 8px 6px; border-top: 1px dashed rgba(139,21,56,.3); min-height: var(--tap); cursor: pointer; }
.goals-banner .goal-item:first-of-type { border-top: 0; }
.goals-banner .goal-item .goal-title { flex: 1; font-weight: 600; }
.goals-banner .goal-item .goal-due { font-size: 12px; color: var(--gray-700); }
.goals-banner .add-goal { background: var(--red); color: #fff; border: 0; border-radius: 8px; min-height: 36px; padding: 0 10px; font-size: 14px; margin-top: 6px; }
.goals-banner .add-goal:disabled { background: var(--gray-300); cursor: not-allowed; }

.status-chip { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 700; letter-spacing: .3px; }
.status-chip.a_faire { background: var(--yellow-soft); color: var(--yellow); }
.status-chip.valide { background: var(--green-soft); color: var(--green); }
.status-chip.non_valide { background: #ffd9d9; color: #a40b0b; }

.goals-history { margin-top: 10px; }
.goals-history summary { cursor: pointer; font-weight: 600; color: var(--gray-700); min-height: var(--tap); display: flex; align-items: center; }
.goal-done { color: var(--green); }
.goal-notvalid { color: var(--gray-500); text-decoration: line-through; }

/* ============================
   Fil chat
============================ */
.chat-wrap { display: flex; flex-direction: column; gap: 10px; min-height: 60vh; }
.chat-filter { display: flex; gap: 6px; flex-wrap: wrap; }
.chat-filter button { background: #fff; border: 1px solid var(--gray-300); border-radius: 999px; padding: 6px 12px; font-size: 13px; min-height: 36px; }
.chat-filter button.active { background: var(--red); color: #fff; border-color: var(--red); }
.chat-messages { display: flex; flex-direction: column; gap: 10px; }
.msg {
  background: #fff; border: 1px solid var(--gray-200); border-radius: 12px; padding: 10px 12px;
  max-width: 92%; word-break: break-word;
}
.msg.mine { background: #fef0f3; border-color: #f5c6cf; align-self: flex-end; }
.msg.other { align-self: flex-start; }
.msg .meta { font-size: 11px; color: var(--gray-500); margin-bottom: 4px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.msg .meta .author { font-weight: 700; color: var(--gray-900); }
.msg .text { white-space: pre-wrap; }
.msg img, .msg video { border-radius: 10px; margin-top: 4px; max-width: 100%; max-height: 70vh; }
.msg img { cursor: zoom-in; }
.msg .link-card { display: flex; gap: 8px; margin-top: 4px; border: 1px solid var(--gray-200); border-radius: 10px; overflow: hidden; text-decoration: none; color: inherit; background: #fafbfc; }
.msg .link-card img { max-width: 80px; max-height: 80px; object-fit: cover; margin: 0; border-radius: 0; }
.msg .link-card .link-body { padding: 6px 8px; flex: 1; }
.msg .link-card .link-title { font-weight: 700; margin-bottom: 2px; }
.msg .link-card .link-url { font-size: 12px; color: var(--gray-500); word-break: break-all; }
.msg .actions { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.msg .actions button { background: transparent; border: 1px solid var(--gray-300); border-radius: 6px; min-height: 32px; padding: 0 8px; font-size: 12px; }
.msg .pin { background: var(--yellow-soft); color: var(--yellow); font-size: 11px; padding: 1px 6px; border-radius: 4px; font-weight: 700; }

.composer {
  position: sticky; bottom: 60px; z-index: 10; background: #fff; border-top: 1px solid var(--gray-200);
  padding: 8px; display: flex; gap: 6px; align-items: flex-end;
  margin: 0 -12px -12px; padding-bottom: calc(8px + env(safe-area-inset-bottom));
}
.composer textarea { flex: 1; resize: none; min-height: 40px; max-height: 120px; border: 1px solid var(--gray-300); border-radius: 10px; padding: 8px 10px; }
.composer button { min-width: var(--tap); min-height: var(--tap); border: 0; border-radius: 10px; background: var(--red); color: #fff; font-weight: 700; }
.composer .icon-btn { background: var(--gray-100); color: var(--gray-900); border: 1px solid var(--gray-300); font-size: 18px; }
.composer label.icon-btn { display: inline-grid; place-items: center; }
.composer input[type="file"] { display: none; }
.composer .opts { display: flex; gap: 6px; margin-bottom: 4px; align-items: center; font-size: 12px; }

/* Image lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); display: grid; place-items: center; z-index: 100; }
.lightbox img { max-width: 100vw; max-height: 100vh; }
.lightbox button.close-lb { position: absolute; top: 10px; right: 10px; background: #fff; border: 0; width: 44px; height: 44px; border-radius: 22px; font-size: 20px; }

/* ============================
   Fenêtres modales (connexion)
============================ */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; z-index: 90; }
.modal {
  background: #fff; width: 100%; max-width: 560px; margin: auto; padding: 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3); overflow-y: auto; max-height: 100vh;
}
@media (min-width: 768px) {
  .modal { border-radius: 14px; max-height: 85vh; }
}
.modal header { position: sticky; top: 0; background: #fff; display: flex; align-items: center; gap: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--gray-200); }
.modal header h2 { margin: 0; flex: 1; font-size: 18px; }
.modal header .close-x { min-width: var(--tap); min-height: var(--tap); border: 1px solid var(--gray-300); background: #fff; border-radius: 8px; font-size: 18px; }
.modal .modal-body { padding: 12px 0; }
.modal .modal-foot { position: sticky; bottom: 0; background: #fff; padding-top: 10px; border-top: 1px solid var(--gray-200); display: flex; gap: 8px; justify-content: flex-end; }
.modal .btn-primary { background: var(--red); color: #fff; border: 0; border-radius: 10px; min-height: var(--tap); padding: 0 16px; font-weight: 700; }
.modal .btn-secondary { background: #fff; color: var(--gray-900); border: 1px solid var(--gray-300); border-radius: 10px; min-height: var(--tap); padding: 0 14px; }
.modal .btn-danger { background: #c62525; color: #fff; border: 0; border-radius: 10px; min-height: var(--tap); padding: 0 14px; font-weight: 700; }
.modal .form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.modal input[type="text"], .modal input[type="date"], .modal input[type="email"], .modal input[type="tel"], .modal input[type="url"], .modal textarea, .modal select {
  width: 100%; min-height: var(--tap); padding: 8px 10px; border: 1px solid var(--gray-300); border-radius: 8px; background: #fff;
}
.modal textarea { min-height: 100px; resize: vertical; }

/* Fenêtre objectifs du jour avec checkbox */
.daily-list { list-style: none; padding: 0; margin: 0; }
.daily-list li { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--gray-200); min-height: var(--tap); }
.daily-list input[type="checkbox"] { width: 22px; height: 22px; flex-shrink: 0; }
.daily-list .title { flex: 1; }
.daily-list .due { font-size: 12px; color: var(--gray-500); }
.yesterday-summary { margin-top: 12px; padding: 10px; background: var(--gray-100); border-radius: 10px; font-size: 14px; color: var(--gray-700); }

/* ============================
   Annuaire
============================ */
.annuaire-toolbar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.annuaire-toolbar input[type="search"] { flex: 1; min-width: 150px; min-height: var(--tap); padding: 8px 10px; border: 1px solid var(--gray-300); border-radius: 8px; }
.annuaire-toolbar select, .annuaire-toolbar button { min-height: var(--tap); border: 1px solid var(--gray-300); border-radius: 8px; padding: 0 10px; background: #fff; }
.annuaire-toolbar .btn-add { background: var(--red); color: #fff; border-color: var(--red); font-weight: 600; }
.fiche-list { display: grid; grid-template-columns: 1fr; gap: 10px; }
.fiche {
  background: #fff; border: 1px solid var(--gray-200); border-radius: 12px; padding: 12px; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px;
}
.fiche .fiche-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.fiche .fiche-societe { font-weight: 700; font-size: 16px; flex: 1; }
.fiche .fiche-row { font-size: 13px; color: var(--gray-700); }
.fiche .fiche-row a { color: var(--gray-900); }
.fiche .fiche-meta { font-size: 11px; color: var(--gray-500); margin-top: 4px; }
.annuaire-table { display: none; }

@media (min-width: 768px) {
  .fiche-list { display: none; }
  .annuaire-table { display: table; width: 100%; background: #fff; border-collapse: collapse; border-radius: 12px; overflow: hidden; border: 1px solid var(--gray-200); }
  .annuaire-table th, .annuaire-table td { padding: 10px; text-align: left; border-top: 1px solid var(--gray-200); font-size: 14px; }
  .annuaire-table th { background: var(--gray-100); font-weight: 700; }
  .annuaire-table tr { cursor: pointer; }
  .annuaire-table tr:hover { background: #fafbfc; }
}

/* ============================
   Progression
============================ */
.progression-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.progression-card { background: #fff; border: 1px solid var(--gray-200); border-radius: 12px; padding: 14px; }
.progression-card h3 { margin: 0 0 10px; color: var(--red); }
.progression-row { display: flex; justify-content: space-between; font-size: 14px; padding: 4px 0; border-top: 1px dashed var(--gray-200); }
.progression-row:first-of-type { border-top: 0; }
.streak { font-size: 24px; font-weight: 800; color: var(--red); }

/* ============================
   Activité
============================ */
.activity-list { list-style: none; padding: 0; margin: 0; }
.activity-list li { background: #fff; border: 1px solid var(--gray-200); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; font-size: 14px; }
.activity-list li .time { color: var(--gray-500); font-size: 12px; display: block; margin-top: 2px; }

/* ============================
   Objectifs du jour (dans onglets)
============================ */
.daily-section { background: #fff; border: 1px solid var(--gray-200); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.daily-section h3 { margin: 0 0 8px; }
.daily-user { font-weight: 700; margin-top: 10px; }
.daily-add { display: flex; gap: 6px; margin-top: 8px; }
.daily-add input { flex: 1; min-height: var(--tap); padding: 8px 10px; border: 1px solid var(--gray-300); border-radius: 8px; }
.daily-add button { background: var(--red); color: #fff; border: 0; border-radius: 8px; min-height: var(--tap); padding: 0 14px; font-weight: 600; }

/* ============================
   Responsive
============================ */
@media (min-width: 768px) {
  .main { padding: 16px 20px; }
  .goals-banners { grid-template-columns: 1fr 1fr; }
  .progression-grid { grid-template-columns: 1fr 1fr; }
  .fiche-list { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 1024px) {
  .topbar { padding-left: 24px; padding-right: 24px; }
  .main { padding: 20px 28px; padding-bottom: 20px; }
  .tabbar { position: static; grid-template-columns: repeat(5, auto); gap: 10px; padding: 10px 24px; border-top: 0; border-bottom: 1px solid var(--gray-200); justify-content: center; }
  .tabbar button { min-width: 100px; flex-direction: row; font-size: 14px; gap: 6px; }
  .tabbar .badge { position: static; margin-left: 4px; }
  .composer { position: static; margin: 0; padding: 8px 0; border-top: 0; }
  .msg { max-width: 70%; }
}

@media (min-width: 1280px) {
  .main { padding: 24px 40px; }
  body { font-size: 16px; }
}

/* ============================
   Urgent
============================ */
.badge-urgent {
  display: inline-block;
  background: #e60000;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .4px;
  padding: 3px 8px;
  border-radius: 999px;
  margin-right: 6px;
  box-shadow: 0 0 0 2px #fff, 0 0 0 3px #e60000;
  vertical-align: middle;
  text-transform: uppercase;
}
.is-urgent {
  outline: 2px solid #e60000;
  outline-offset: -2px;
  background: #fff5f5 !important;
  position: relative;
}
.goal-item.is-urgent {
  border-radius: 10px;
  padding-left: 10px;
}
.urgent-since { color: #e60000; font-weight: 600; }
.urgent-btn {
  min-width: 44px; min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--gray-300);
  background: #fff;
  font-size: 18px;
  cursor: pointer;
  opacity: .55;
  transition: opacity .15s, background .15s;
}
.urgent-btn:hover { opacity: 1; }
.urgent-btn.on {
  opacity: 1;
  background: #e60000;
  border-color: #e60000;
  color: #fff;
}
.urgent-toggle.on { background: #e60000 !important; color: #fff !important; border-color: #e60000 !important; }

/* ============================
   Horodatage & séparateurs
============================ */
time { font-variant-numeric: tabular-nums; cursor: help; }
.day-sep { display: flex; align-items: center; gap: 8px; margin: 10px 0 4px; }
.day-sep::before, .day-sep::after { content: ''; flex: 1; height: 1px; background: var(--gray-200); }
.day-sep span { font-size: 12px; font-weight: 700; color: var(--gray-500); text-transform: uppercase; letter-spacing: .5px; background: #fff; padding: 2px 10px; border: 1px solid var(--gray-200); border-radius: 999px; }
.msg .meta time { color: var(--gray-500); }
.msg .meta .edited { color: var(--gray-500); font-style: italic; }
.msg .views { margin-top: 4px; font-size: 11px; color: var(--gray-500); }
.msg .views time { color: inherit; }
.pin.pin-mute { background: #eee; color: #555; }
.muted.small, .small { font-size: 11px; }
.muted { color: var(--gray-500); }
.daily-cell { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.daily-cell .title { font-weight: 500; }
.daily-meta { font-size: 11px; color: var(--gray-500); }
.daily-meta time { color: inherit; }
.goal-item { flex-wrap: wrap; }
.goal-main { flex: 1; min-width: 0; }
.goal-sub { font-size: 11px; color: var(--gray-500); margin-top: 2px; }
.goal-sub time { color: inherit; }
.activity-list time { color: inherit; }

/* ============================
   Bandeau minimum / goals counter
============================ */
.min-banner {
  background: #fff8e1; border-bottom: 2px solid #e2b000;
  padding: 8px 12px; font-size: 13px; color: #8a5a00;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding-top: calc(8px + env(safe-area-inset-top));
}
.min-banner b { color: #a40b0b; }
.under-min { color: #a40b0b; font-weight: 700; }
.goals-counter {
  display: inline-block; font-size: 20px; font-weight: 800;
  padding: 6px 14px; border-radius: 10px; margin-bottom: 8px;
}
.goals-counter.warn { background: #ffe9ea; color: #a40b0b; }
.goals-counter.ok { background: var(--green-soft); color: var(--green); }
.small-btn { background:#fff; border:1px solid var(--gray-300); border-radius:8px; min-height:38px; padding:6px 10px; font-size:13px; }

/* ============================
   Historique
============================ */
.hist-wrap { display: flex; flex-direction: column; gap: 16px; }
.hist-section h3 { margin: 0 0 8px; }
.hist-filter { display: flex; gap: 10px; flex-wrap: wrap; }
.hist-filter label { background: var(--gray-100); border-radius: 999px; padding: 6px 12px; min-height: 36px; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.cal-dual { display: grid; grid-template-columns: 1fr; gap: 14px; }
.cal-col h4 { margin: 0 0 6px; color: var(--red); font-size: 14px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: 11px; color: var(--gray-500); font-weight: 700; }
.cal-cell { aspect-ratio: 1; min-height: 32px; border-radius: 6px; border: 1px solid var(--gray-200); background: #fff; font-size: 12px; display: flex; align-items: center; justify-content: center; position: relative; cursor: pointer; }
.cal-cell.empty { visibility: hidden; }
.cal-cell:hover { outline: 2px solid var(--red); }
.cal-green { background: #16a34a; color: #fff; border-color: #138539; }
.cal-orange { background: #f59e0b; color: #fff; border-color: #ca7c00; }
.cal-red { background: #dc2626; color: #fff; border-color: #a81f1f; }
.cal-gray { background: #e5e7eb; color: #555; border-color: #cbd5df; }
.cal-none { background: #fff; color: #ccc; }
.cal-urg { position: absolute; top: 1px; right: 2px; font-size: 9px; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 11px; color: var(--gray-500); margin-top: 6px; }
.cal-dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; margin-right: 3px; }
.cal-dot.cal-green { background: #16a34a; }
.cal-dot.cal-orange { background: #f59e0b; }
.cal-dot.cal-red { background: #dc2626; }
.cal-dot.cal-gray { background: #e5e7eb; }
.hist-list-filter { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.hist-list-filter input, .hist-list-filter select { min-height: 40px; padding: 6px 10px; border: 1px solid var(--gray-300); border-radius: 8px; background: #fff; font-size: 14px; }
.hist-list-filter input[type="search"] { flex: 1; min-width: 160px; }
.hist-row { display: grid; grid-template-columns: 90px 1fr; gap: 2px 10px; padding: 8px 6px; border-top: 1px solid var(--gray-200); font-size: 13px; }
.hist-row:first-of-type { border-top: 0; }
.hist-date { font-variant-numeric: tabular-nums; color: var(--gray-500); grid-row: span 3; }
.hist-user { font-weight: 700; }
.hist-onglet { color: var(--gray-500); font-size: 12px; }
.hist-titre { grid-column: 2; }
.hist-flags { grid-column: 2; display: flex; gap: 4px; flex-wrap: wrap; }
.hist-day-user { margin-bottom: 14px; }
@media (min-width: 768px) {
  .cal-dual { grid-template-columns: 1fr 1fr; }
  .hist-row { grid-template-columns: 110px 120px 90px 1fr auto; grid-template-rows: auto; }
  .hist-titre, .hist-flags { grid-column: auto; }
}

/* Utils */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
