:root {
  --bg: #0b1220;
  --card: #141d31;
  --card2: #1b2742;
  --line: #24304d;
  --text: #e6edf7;
  --muted: #8fa0bd;
  --accent: #22d3a7;
  --accent-dark: #0e9f7a;
  --danger: #f0616d;
  --warn: #eab308;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  height: 100%;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }

/* ---------- layout ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: rgba(11, 18, 32, .92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: .3px; }
.badge {
  background: var(--accent); color: #04281e; font-size: 12px; font-weight: 700;
  padding: 3px 9px; border-radius: 99px;
}

#view { padding: 16px 16px calc(84px + var(--safe-b)); max-width: 640px; margin: 0 auto; }

#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-around;
  padding: 6px 4px calc(6px + var(--safe-b));
  background: rgba(15, 23, 41, .96);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; color: var(--muted); font-size: 10.5px; font-weight: 600;
  padding: 6px 0; cursor: pointer;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--accent); }

/* ---------- composants ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
.card h2 { font-size: 15px; margin-bottom: 12px; color: var(--text); }
.card .hint { font-size: 12.5px; color: var(--muted); line-height: 1.5; }

.btn {
  display: block; width: 100%; text-align: center;
  background: var(--accent); color: #04281e;
  border: none; border-radius: 12px;
  padding: 15px; font-size: 16px; font-weight: 700; cursor: pointer;
  transition: transform .05s;
}
.btn:active { transform: scale(.98); }
.btn.secondary { background: var(--card2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn.small { padding: 10px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; }

.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
input[type="text"], input[type="tel"], input[type="email"], input[type="url"], input[type="password"], input[type="date"], textarea, select {
  width: 100%; background: var(--card2); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; color: var(--text); font-size: 16px;
  font-family: inherit;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 72px; resize: vertical; }

.checkline { display: flex; align-items: center; gap: 10px; padding: 10px 2px; font-size: 15px; cursor: pointer; }
.checkline input { width: 20px; height: 20px; accent-color: var(--accent); }

/* ---------- écran scan ---------- */
.scan-hero { text-align: center; padding: 30px 10px 10px; }
.scan-hero .pulse-ring {
  width: 130px; height: 130px; margin: 0 auto 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle, rgba(34,211,167,.16), transparent 70%);
  border: 2px solid var(--accent);
}
.scan-hero .pulse-ring svg { width: 56px; height: 56px; }
.scan-hero h1 { font-size: 21px; margin-bottom: 8px; }
.scan-hero p { color: var(--muted); font-size: 14px; margin-bottom: 26px; line-height: 1.5; }

.spinner {
  width: 42px; height: 42px; margin: 30px auto; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.photo-preview { width: 100%; border-radius: 12px; margin-bottom: 14px; max-height: 240px; object-fit: contain; background: #000; }

/* ---------- carnet ---------- */
.searchbar { display: flex; gap: 8px; margin-bottom: 12px; }
.searchbar input { flex: 1; }
.searchbar select { width: auto; max-width: 45%; }

.contact-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; cursor: pointer;
}
.contact-item .avatar {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
  background: var(--card2); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
}
.contact-item .info { flex: 1; min-width: 0; }
.contact-item .info .name { font-weight: 600; font-size: 15px; }
.contact-item .info .sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-item .meta { text-align: right; font-size: 11px; color: var(--muted); flex-shrink: 0; }
.contact-item .meta .tag { display: inline-block; background: var(--card2); border-radius: 6px; padding: 2px 7px; margin-top: 3px; }
.contact-item .meta .due { color: var(--warn); font-weight: 700; }

.empty { text-align: center; color: var(--muted); padding: 44px 20px; font-size: 14px; line-height: 1.6; }

/* ---------- détail / actions ---------- */
.action-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.action-grid .btn { padding: 12px 4px; font-size: 12.5px; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); flex-shrink: 0; }
.kv .v { text-align: right; word-break: break-word; }
.kv .v a { color: var(--accent); text-decoration: none; }

/* ---------- divers ---------- */
#toast {
  position: fixed; bottom: calc(96px + var(--safe-b)); left: 50%; transform: translateX(-50%);
  background: var(--card2); border: 1px solid var(--accent);
  color: var(--text); padding: 11px 20px; border-radius: 99px;
  font-size: 14px; font-weight: 600; z-index: 50; white-space: nowrap;
  max-width: 90vw; overflow: hidden; text-overflow: ellipsis;
}

.back { background: none; border: none; color: var(--accent); font-size: 15px; font-weight: 600; padding: 0 0 14px; cursor: pointer; }

.mic-btn {
  background: var(--card2); border: 1px solid var(--line); border-radius: 10px;
  color: var(--accent); padding: 0 14px; font-size: 18px; cursor: pointer;
}
.mic-btn.rec { border-color: var(--danger); color: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .4; } }

.note-row { display: flex; gap: 8px; }
.note-row textarea { flex: 1; }

.pill-row { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  background: var(--card2); border: 1px solid var(--line); color: var(--text);
  border-radius: 99px; padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.pill.on { background: var(--accent); color: #04281e; border-color: var(--accent); }

details.section { margin-bottom: 14px; }
details.section summary {
  cursor: pointer; font-weight: 600; font-size: 14px; padding: 10px 0; color: var(--text);
  list-style: none;
}
details.section summary::before { content: "▸ "; color: var(--accent); }
details.section[open] summary::before { content: "▾ "; }

.notice { font-size: 12px; color: var(--muted); line-height: 1.6; }
.notice strong { color: var(--text); }

/* ---------- vue Suivi (colonnes) ---------- */
.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; background: none; border: none; color: var(--muted); font-weight: 700; font-size: 13px; padding: 8px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--accent); color: #04281e; }
.kanban { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 12px; scroll-snap-type: x proximity; }
.kcol { min-width: 232px; max-width: 232px; scroll-snap-align: start; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; align-self: flex-start; }
.kcol h3 { font-size: 12.5px; margin-bottom: 8px; display: flex; justify-content: space-between; color: var(--text); }
.kcol h3 .n { color: var(--muted); font-weight: 600; }
.kcard { background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; margin-bottom: 7px; cursor: pointer; }
.kcard .kn { font-weight: 700; font-size: 13.5px; }
.kcard .ks { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kcard .kd { font-size: 10.5px; color: var(--warn); font-weight: 700; margin-top: 2px; }
.kempty { font-size: 11.5px; color: var(--muted); text-align: center; padding: 10px 0; }

/* ---------- journal (timeline) ---------- */
.timeline { border-left: 2px solid var(--line); margin: 4px 0 0 6px; padding-left: 14px; display: flex; flex-direction: column; gap: 10px; }
.tl-item { font-size: 13px; position: relative; line-height: 1.4; }
.tl-item::before { content: ""; position: absolute; left: -19px; top: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.tl-item.note::before { background: var(--accent); }
.tl-item .tl-date { color: var(--muted); font-size: 10.5px; display: block; }

/* ---------- panneau de sélection (envoi multi-cartes) ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(4, 8, 16, .72);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + var(--safe-b));
  width: 100%; max-width: 640px;
  animation: slideup .18s ease-out;
}
.sheet h2 { font-size: 16px; }
@keyframes slideup { from { transform: translateY(30px); opacity: .5; } to { transform: none; opacity: 1; } }

/* ---------- signature de marque : le pouls bat ---------- */
@media (prefers-reduced-motion: no-preference) {
  .pulse-ring { animation: pouls 2.4s ease-in-out infinite; }
  @keyframes pouls {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34, 211, 167, .28); }
    50% { box-shadow: 0 0 0 16px rgba(34, 211, 167, 0); }
  }
}
