:root {
  --bg: #f1f5f9; --card: #fff; --text: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --primary: #1e3a8a; --primary-2: #2563eb; --primary-2-hover: #1d4ed8; --on-accent: #fff; --accent-text: #2563eb; --accent-soft: #dbeafe; --ok: #16a34a; --warn: #d97706; --danger: #dc2626;
  --radius: 12px; --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 "Open Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent-text); }
h1, h2, h3, .brand, .stat b, .cal-head .title { font-family: "Work Sans", "Open Sans", sans-serif; }
h1 { font-size: 22px; margin: 0 0 14px; }
h2 { font-size: 17px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 230px; background: var(--primary); color: #fff; padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.sidebar .brand { font-weight: 700; font-size: 17px; padding: 4px 4px 18px; }
.logo-box { background: #fff; border-radius: 12px; padding: 10px; text-align: center; box-shadow: 0 0 0 3px var(--primary-2); }
.logo-img { max-width: 100%; max-height: 90px; display: block; margin: 0 auto; }
.brand-sub { font-size: 12px; font-weight: 600; color: var(--primary-2); text-transform: uppercase; letter-spacing: .08em; text-align: center; margin-top: 10px; }
.login-logo { max-width: 180px; max-height: 128px; }
.sidebar a { display: flex; gap: 10px; align-items: center; color: rgba(255,255,255,.78); text-decoration: none; padding: 10px 12px; border-radius: 8px; margin-bottom: 2px; }
.sidebar a.active, .sidebar a:hover { background: rgba(255,255,255,.12); color: #fff; }
.sidebar a.active { box-shadow: inset 3px 0 0 var(--primary-2); font-weight: 600; }
.sidebar .badge { margin-left: auto; }
.sidebar .me { margin-top: auto; font-size: 13px; color: rgba(255,255,255,.7); padding: 10px; }
.main { flex: 1; padding: 22px; max-width: 1200px; width: 100%; margin: 0 auto; min-width: 0; }
.tabbar { display: none; }
.topbar { display: none; }

@media (max-width: 820px) {
  .sidebar { display: none; }
  .main { padding: 14px 12px calc(84px + var(--safe-b)); }
  .topbar { display: flex; align-items: center; justify-content: space-between; background: var(--primary); color: #fff; padding: 12px 14px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); position: sticky; top: 0; z-index: 20; }
  .topbar .t { font-weight: 600; }
  .topbar button, .topbar .topbar-btn { background: none; border: 0; color: #fff; font-size: 14px; text-decoration: none; }
  .topbar { box-shadow: inset 0 -3px 0 var(--primary-2); }
  .tabbar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--line); z-index: 30; padding-bottom: var(--safe-b); }
  .tabbar a { flex: 1; text-align: center; padding: 8px 2px 7px; font-size: 11px; color: var(--muted); text-decoration: none; position: relative; }
  .tabbar a .ico { display: block; font-size: 20px; line-height: 24px; }
  .tabbar a.active { color: var(--primary); font-weight: 700; box-shadow: inset 0 3px 0 var(--primary-2); }
  .tabbar .badge { position: absolute; top: 3px; left: 55%; }
  .layout { display: block; }
}

/* Composants */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stats { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 14px; }
.stat { background: #fff; border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); text-decoration: none; color: inherit; }
.stat b { font-size: 26px; display: block; }
.btn { appearance: none; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 10px 14px; border-radius: 10px; font: inherit; font-weight: 500; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; justify-content: center; text-decoration: none; min-height: 42px; }
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--primary-2); color: var(--on-accent); border-color: var(--primary-2); font-weight: 600; }
.btn.primary:hover { background: var(--primary-2-hover); }
.btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.block { width: 100%; }
.btn.lg { padding: 14px 18px; font-size: 16px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.sm { padding: 6px 10px; min-height: 32px; font-size: 13px; }
label { display: block; font-size: 13px; font-weight: 600; color: #334155; margin: 10px 0 4px; }
input, select, textarea { width: 100%; font: inherit; padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; color: var(--text); font-size: 16px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--primary-2); }
textarea { min-height: 96px; resize: vertical; }
input[type=color] { padding: 2px; height: 42px; }
.fields { display: grid; gap: 0 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: #e2e8f0; color: #334155; white-space: nowrap; }
.s-planifiee { background: var(--accent-soft); color: var(--primary); }
.s-en_cours { background: #fef3c7; color: #92400e; }
.s-terminee { background: #ffedd5; color: #c2410c; }
.s-validee { background: #dcfce7; color: #166534; }
.s-envoyee { background: #d1fae5; color: #065f46; }
.s-annulee { background: #f1f5f9; color: #64748b; text-decoration: line-through; }
.badge.red { background: var(--danger); color: #fff; }

.list-item { display: flex; gap: 12px; align-items: center; padding: 12px 14px; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 8px; text-decoration: none; color: inherit; border-left: 5px solid var(--c, #cbd5e1); }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .time { font-weight: 700; font-size: 14px; min-width: 48px; text-align: center; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); }
.table-wrap { overflow-x: auto; }

/* Calendrier */
.cal-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.cal-head .title { font-weight: 700; font-size: 18px; flex: 1; text-transform: capitalize; min-width: 150px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: none; padding: 8px 12px; font: inherit; cursor: pointer; }
.seg button.on { background: var(--primary-2); color: var(--on-accent); font-weight: 600; }
.month { display: grid; grid-template-columns: repeat(7, 1fr); background: var(--line); gap: 1px; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.month .dow { background: #f8fafc; text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); padding: 6px 0; }
.month .day { background: #fff; min-height: 104px; padding: 4px; cursor: pointer; min-width: 0; }
.month .day.other { background: #f8fafc; color: #94a3b8; }
.month .day.today .num { background: var(--primary-2); color: var(--on-accent); border-radius: 99px; }
.month .num { display: inline-block; font-size: 12px; font-weight: 600; min-width: 22px; text-align: center; padding: 1px 4px; }
.ev { display: block; font-size: 11.5px; padding: 2px 5px; border-radius: 5px; margin-top: 2px; color: #fff; background: var(--c, var(--primary-2)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: none; }
.ev.done { opacity: .65; }
.more { font-size: 11px; color: var(--muted); padding-left: 4px; }
@media (max-width: 820px) {
  .month .day { min-height: 58px; }
  .month .ev { font-size: 0; height: 6px; padding: 0; border-radius: 3px; }
  .month .more { display: none; }
}
.week { display: grid; grid-template-columns: repeat(7, minmax(120px, 1fr)); gap: 8px; overflow-x: auto; }
.week .col { background: #fff; border-radius: var(--radius); padding: 8px; box-shadow: var(--shadow); min-height: 200px; }
.week .col.today { outline: 2px solid var(--primary-2); }
.week .col h3 { margin: 0 0 6px; font-size: 13px; text-transform: capitalize; }
.week .ev { font-size: 12px; white-space: normal; padding: 5px 6px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; margin: 10px 0; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); margin-right: 5px; }

/* Rapport */
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 4px 10px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; white-space: pre-wrap; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.photos .ph { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #e2e8f0; }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photos .del { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.6); color: #fff; border: 0; border-radius: 99px; width: 26px; height: 26px; cursor: pointer; }
.photos .add { display: flex; align-items: center; justify-content: center; flex-direction: column; border: 2px dashed #cbd5e1; color: var(--muted); cursor: pointer; font-size: 13px; }
.sig-img { max-width: 100%; max-height: 160px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.sig-pad { width: 100%; height: 240px; border: 2px dashed #94a3b8; border-radius: 12px; background: #fff; touch-action: none; display: block; }
.steps { display: flex; gap: 6px; margin-bottom: 14px; }
.steps div { flex: 1; height: 5px; border-radius: 3px; background: #cbd5e1; }
.steps div.on { background: var(--ok); }
.sticky-actions { position: sticky; bottom: calc(68px + var(--safe-b)); background: linear-gradient(transparent, var(--bg) 30%); padding-top: 14px; display: flex; gap: 8px; }
@media (min-width: 821px) { .sticky-actions { bottom: 0; } }

/* Modal / toast */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 12px; }
.modal-box { background: #fff; border-radius: 16px; width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; padding: 18px; }
@media (max-width: 820px) { .modal { align-items: flex-end; padding: 0; } .modal-box { border-radius: 16px 16px 0 0; max-height: 94vh; padding-bottom: calc(18px + var(--safe-b)); } }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + var(--safe-b)); background: #0f172a; color: #fff; padding: 11px 18px; border-radius: 10px; z-index: 200; max-width: 92vw; box-shadow: 0 8px 20px rgba(0,0,0,.25); }
.toast.err { background: var(--danger); }
.login { max-width: 380px; margin: 12vh auto; padding: 0 16px; }
.login .logo { text-align: center; font-size: 44px; }
.alert { padding: 10px 12px; border-radius: 10px; background: #fef3c7; color: #92400e; font-size: 14px; margin-bottom: 12px; }
.alert.info { background: var(--accent-soft); color: var(--primary); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.hide-m { } @media (max-width: 820px) { .hide-m { display: none !important; } }

/* Recherche de client */
.picker { position: relative; flex: 1; min-width: 0; }
.picker input { width: 100%; }
.picker-list { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); max-height: 300px; overflow-y: auto; background: #fff; border: 1px solid #cbd5e1; border-radius: 10px; box-shadow: 0 10px 25px rgba(15, 23, 42, .15); }
.picker-item { padding: 10px 12px; cursor: pointer; border-bottom: 1px solid #f1f5f9; }
.picker-item:last-child { border-bottom: 0; }
.picker-item span { display: block; font-size: 12px; color: #64748b; margin-top: 2px; }
.picker-item:hover, .picker-item.on { background: var(--accent-soft, #eff6ff); }
.picker-empty { padding: 12px; color: #64748b; font-size: 14px; }
