:root {
  --bg: #f4f6fb;
  --sidebar: #0f2942;
  --sidebar-hover: #1b3a5a;
  --sidebar-active: #2563eb;
  --card: #ffffff;
  --border: #e3e8f0;
  --text: #1c2b3a;
  --muted: #6b7a8d;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --violet: #7c3aed;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16,42,67,.08), 0 1px 2px rgba(16,42,67,.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; }

#app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }

/* Sidebar */
.sidebar { background: var(--sidebar); color: #cdd8e6; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-logo { width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(135deg,#2563eb,#7c3aed); display: grid; place-items: center; font-weight: 800; color: #fff; letter-spacing: .5px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { color: #fff; font-size: 16px; }
.brand-text span { color: #8ba3bd; font-size: 11px; }
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 8px; color: #cdd8e6; text-decoration: none; font-size: 13.5px; transition: background .15s, color .15s; }
.nav-item .ico { width: 18px; text-align: center; opacity: .85; }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.sidebar-foot { padding: 14px 18px; font-size: 11px; color: #6f89a6; border-top: 1px solid rgba(255,255,255,.08); }

/* Main */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 24px; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-search { flex: 1; max-width: 520px; }
.topbar-search input { width: 100%; padding: 9px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 13.5px; background: #f7f9fc; }
.topbar-search input:focus { outline: none; border-color: var(--primary); background: #fff; }
.user-chip { background: #eef2ff; color: var(--primary-dark); padding: 6px 14px; border-radius: 20px; font-weight: 600; font-size: 13px; }
.view { padding: 24px; }

/* Page header */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; font-weight: 700; }
.page-head p { color: var(--muted); font-size: 13px; margin-top: 2px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border: 1px solid var(--border); background: #fff; color: var(--text); border-radius: 8px; font-size: 13.5px; font-weight: 500; cursor: pointer; transition: all .15s; text-decoration: none; }
.btn:hover { border-color: #c4cddb; background: #f7f9fc; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-danger { color: var(--red); border-color: #f3c7c7; background: #fff5f5; }
.btn-danger:hover { background: #fee2e2; }
.btn-ghost { border-color: transparent; background: transparent; }

/* Cards & grid */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 7px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.panel-head h2 { font-size: 15px; font-weight: 650; }
.panel-body { padding: 4px 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 980px) { .two-col { grid-template-columns: 1fr; } #app { grid-template-columns: 64px 1fr; } .brand-text, .nav-item span:not(.ico), .sidebar-foot { display: none; } }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { text-align: left; padding: 11px 18px; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; border-bottom: 1px solid var(--border); background: #fafbfe; white-space: nowrap; }
tbody td { padding: 12px 18px; border-bottom: 1px solid #eef1f6; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: #f7f9fc; }
.t-strong { font-weight: 600; }
.t-muted { color: var(--muted); }
.t-right { text-align: right; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-amber { background: #fef3c7; color: #b45309; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-gray { background: #eef1f6; color: #64748b; }
.badge-violet { background: #ede9fe; color: #6d28d9; }

/* Filters */
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.filters input, .filters select { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; background: #fff; }
.filters input:focus, .filters select:focus { outline: none; border-color: var(--primary); }

/* Forms / modal */
#modal-root:empty { display: none; }
.modal-overlay { position: fixed; inset: 0; background: rgba(15,41,66,.45); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 640px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.lg { max-width: 820px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: #fff; }
.modal-head h3 { font-size: 17px; }
.modal-close { border: none; background: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-body { padding: 20px 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; position: sticky; bottom: 0; background: #fff; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12.5px; font-weight: 600; color: #40546a; }
.field input, .field select, .field textarea { padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13.5px; font-family: inherit; background: #fff; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.field textarea { resize: vertical; min-height: 70px; }
.section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: 8px 0 2px; grid-column: 1/-1; }

/* Detail */
.detail-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px){ .detail-grid { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; font-size: 13.5px; padding: 4px 0; }
.kv dt { color: var(--muted); }
.kv dd { font-weight: 500; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }

/* Tarif result */
.tarif-result { background: linear-gradient(135deg,#eff6ff,#f5f3ff); border: 1px solid #dbe4f5; border-radius: 12px; padding: 18px; text-align: center; }
.tarif-result .big { font-size: 34px; font-weight: 800; color: var(--primary-dark); }
.tarif-result .lbl { color: var(--muted); font-size: 13px; }

/* Bars (reporting) */
.bar-row { display: grid; grid-template-columns: 140px 1fr 90px; gap: 12px; align-items: center; padding: 8px 18px; font-size: 13px; }
.bar-track { background: #eef1f6; border-radius: 6px; height: 12px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg,#2563eb,#7c3aed); border-radius: 6px; }

/* Toast */
#toast-root { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { background: #0f2942; color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: 13.5px; animation: slidein .2s ease; }
.toast.ok { background: #16a34a; } .toast.err { background: #dc2626; }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.loading { padding: 40px; text-align: center; color: var(--muted); }

/* Auth screens */
#auth-screen:empty { display: none; }
.auth-wrap { position: fixed; inset: 0; display: grid; place-items: center; background: linear-gradient(135deg,#0f2942,#1b3a5a); padding: 20px; overflow-y: auto; }
.auth-card { background: #fff; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.35); width: 100%; max-width: 440px; padding: 32px; }
.auth-card.wide { max-width: 560px; }
.auth-logo { width: 54px; height: 54px; border-radius: 13px; background: linear-gradient(135deg,#2563eb,#7c3aed); display: grid; place-items: center; font-weight: 800; color: #fff; font-size: 20px; margin: 0 auto 16px; }
.auth-card h1 { text-align: center; font-size: 22px; margin-bottom: 4px; }
.auth-card .sub { text-align: center; color: var(--muted); font-size: 13.5px; margin-bottom: 22px; }
.auth-card .field { margin-bottom: 14px; }
.auth-card .btn-primary { width: 100%; justify-content: center; padding: 12px; font-size: 15px; margin-top: 6px; }
.auth-err { background: #fee2e2; color: #b91c1c; padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; display: none; }
.auth-foot { text-align: center; margin-top: 16px; font-size: 12px; color: var(--muted); }
.pw-row { display: flex; gap: 8px; }
.pw-row input { flex: 1; }
.pw-meter { height: 6px; border-radius: 4px; background: #eef1f6; overflow: hidden; margin-top: 6px; }
.pw-meter > div { height: 100%; width: 0; transition: width .2s, background .2s; }
.pw-rules { font-size: 11.5px; color: var(--muted); margin-top: 6px; line-height: 1.6; }
.pw-rules .ok { color: var(--green); }
.pw-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Media editor */
.editor { display: grid; grid-template-columns: 1fr 300px; gap: 18px; align-items: start; }
@media (max-width: 900px){ .editor { grid-template-columns: 1fr; } }
.editor-canvas { background: #1e2a38; border-radius: 12px; padding: 16px; display: grid; place-items: center; min-height: 380px; position: relative; overflow: hidden; }
.editor-canvas img { max-width: 100%; max-height: 62vh; user-select: none; }
.crop-layer { position: absolute; inset: 0; cursor: crosshair; }
.crop-box { position: absolute; border: 2px dashed #fff; background: rgba(37,99,235,.15); box-shadow: 0 0 0 9999px rgba(0,0,0,.45); }
.editor-controls .ctl { margin-bottom: 14px; }
.editor-controls label { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 600; color: #40546a; margin-bottom: 4px; }
.editor-controls input[type=range] { width: 100%; }
.chips-toggle { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-btn { padding: 6px 11px; border: 1px solid var(--border); border-radius: 20px; background: #fff; cursor: pointer; font-size: 12.5px; }
.chip-btn.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.size-info { font-size: 12.5px; color: var(--muted); background: #f7f9fc; border-radius: 8px; padding: 8px 12px; }

/* Téléphonie — bandeaux d'appels entrants (empilables) */
#call-banners { position: fixed; top: 18px; right: 18px; z-index: 300; display: flex; flex-direction: column; gap: 10px; }
.call-banner { background: #0f2942; color: #fff; border-radius: 14px; padding: 16px 20px; width: 320px; box-shadow: 0 16px 48px rgba(0,0,0,.4); animation: slidein .25s ease; }
.call-banner-head { display: flex; align-items: center; gap: 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: #8ba3bd; margin-bottom: 8px; }
.call-banner-nom { font-size: 18px; font-weight: 700; }
.call-banner-num { font-size: 13px; color: #cdd8e6; margin: 2px 0 12px; }
.call-banner-actions { display: flex; gap: 8px; }
.call-dot { width: 11px; height: 11px; border-radius: 50%; background: #22c55e; animation: pulse 1.1s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.6); } 70% { box-shadow: 0 0 0 9px rgba(34,197,94,0); } 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); } }
.btn-call { color: var(--green); border-color: #bbe7c9; }
.btn-call:hover { background: #dcfce7; }

/* ==========================================================================
   APPLICATION MOBILE (PWA) — barre d'onglets + adaptation tactile
   ========================================================================== */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 90;
  display: none; background: #ffffff; border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -2px 12px rgba(16,42,67,.06); }
.tabbar a, .tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px; font-size: 10.5px; font-weight: 600; color: var(--muted);
  text-decoration: none; background: none; border: none; font-family: inherit; cursor: pointer; }
.tabbar .tb-ico { font-size: 19px; line-height: 1; }
.tabbar a.active { color: var(--primary); }

.sheet-overlay { position: fixed; inset: 0; background: rgba(15,41,66,.45); z-index: 95; }
.sheet { position: absolute; bottom: 0; left: 0; right: 0; background: #fff;
  border-radius: 18px 18px 0 0; padding: 8px 16px calc(14px + env(safe-area-inset-bottom));
  animation: montee .22s ease; }
@keyframes montee { from { transform: translateY(40%); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-grip { width: 42px; height: 5px; border-radius: 3px; background: #d5dce6; margin: 6px auto 12px; }
.sheet-item { display: block; width: 100%; text-align: left; padding: 13px 10px; font-size: 15px;
  color: var(--text); text-decoration: none; border: none; background: none; font-family: inherit;
  border-bottom: 1px solid #f0f3f8; cursor: pointer; }
.sheet-item:last-child { border-bottom: none; }
.sheet-deconnexion { color: var(--red); }

@media (max-width: 760px) {
  /* structure : plus de barre latérale, barre d'onglets en bas */
  #app { grid-template-columns: 1fr !important; }
  .sidebar { display: none !important; }
  body.connecte .tabbar { display: flex; }
  .main { padding-bottom: 0; }
  .view { padding: 14px 12px calc(84px + env(safe-area-inset-bottom)); }

  /* barre du haut compacte */
  .topbar { padding: 10px 12px; gap: 8px; }
  .topbar-search input { padding: 8px 12px; font-size: 16px; }
  .user-chip { display: none; }

  /* titres & actions empilés, boutons pleine largeur tactile */
  .page-head { flex-direction: column; align-items: stretch; gap: 10px; margin-bottom: 14px; }
  .page-head h1 { font-size: 18px; }
  .page-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .page-actions .btn { justify-content: center; padding: 11px 10px; }

  /* cartes de stats sur 2 colonnes */
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
  .stat { padding: 12px 14px; }
  .stat .value { font-size: 21px; }

  /* colonnes uniques */
  .two-col, .detail-grid, .editor { grid-template-columns: 1fr !important; }

  /* tableaux : défilement horizontal fluide au doigt */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  thead th { padding: 9px 10px; font-size: 11px; }
  tbody td { padding: 10px 10px; font-size: 13px; }

  /* formulaires : une colonne, police 16px (empêche le zoom iOS) */
  .form-grid { grid-template-columns: 1fr; }
  .field input, .field select, .field textarea, .filters input, .filters select { font-size: 16px; }
  .filters { gap: 6px; }
  .filters input { min-width: 0 !important; flex: 1; }

  /* modales : plein écran (feuilles) */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { max-width: 100%; width: 100%; max-height: 96vh; border-radius: 18px 18px 0 0; }
  .modal-foot { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }

  /* divers */
  .kv { grid-template-columns: 110px 1fr; }
  .bar-row { grid-template-columns: 92px 1fr 74px; padding: 8px 12px; }
  #toast-root { bottom: calc(76px + env(safe-area-inset-bottom)); right: 12px; left: 12px; }
  .toast { text-align: center; }
  #call-banners { top: 10px; right: 10px; left: 10px; }
  .call-banner { width: auto; }
}
a.link { color: var(--primary); text-decoration: none; font-weight: 500; }
a.link:hover { text-decoration: underline; }
