* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --accent: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
  --shadow: 0 4px 12px rgba(15,23,42,.08);
}
body { font-family: -apple-system, 'Segoe UI', Roboto, sans-serif; background: #f1f5f9; color: var(--text); line-height: 1.5; }

/* ===== LOGIN ===== */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--bg) 0%, var(--primary-dark) 100%); padding: 20px; }
.login-card { background: var(--card); padding: 40px; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.3); width: 100%; max-width: 420px; }
.login-card h1 { font-size: 32px; margin-bottom: 8px; }
.login-card .accent { color: var(--primary); }
.brand-login { display: block; max-width: 260px; height: auto; margin: 0 auto 14px; }
.login-card .tagline { color: var(--muted); margin-bottom: 4px; }
.login-card .date { color: var(--muted); font-size: 13px; margin-bottom: 24px; text-transform: capitalize; }
.login-card form { display: flex; flex-direction: column; gap: 8px; }
.login-card label { font-weight: 600; font-size: 14px; margin-top: 8px; }
.login-card input, input, select, textarea { padding: 11px 14px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; font-family: inherit; width: 100%; background: #fff; }
.login-card input:focus, input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
button { padding: 11px 18px; background: var(--primary); color: #fff; border: none; border-radius: var(--radius); font-size: 14px; font-weight: 600; cursor: pointer; transition: background .2s; font-family: inherit; }
button:hover { background: var(--primary-dark); }
button.secondary { background: #e2e8f0; color: var(--text); }
button.secondary:hover { background: #cbd5e1; }
button.danger { background: var(--danger); }
button.danger:hover { background: #dc2626; }
button.success { background: var(--success); }
button.success:hover { background: #059669; }
button.warning { background: var(--warning); color: #fff; }
button.warning:hover { background: #d97706; }
button.small { padding: 6px 10px; font-size: 12px; }
button.icon-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
button svg, a svg { vertical-align: -3px; }
.sidebar nav a { display: inline-flex; align-items: center; gap: 10px; }
.sidebar nav a svg { flex-shrink: 0; }
.topbar h2 { display: inline-flex; align-items: center; gap: 10px; }
.card .icon-ico { width: 22px; height: 22px; color: var(--primary); margin-bottom: 6px; opacity: .8; }
.card.success .icon-ico { color: var(--success); }
.card.warning .icon-ico { color: var(--warning); }
.card.accent .icon-ico { color: var(--accent); }
.login-card button { margin-top: 20px; }
.login-card .error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }
.login-card .hint { font-size: 12px; color: var(--muted); margin-top: 20px; text-align: center; }
code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: 12px; }

/* ===== APP LAYOUT ===== */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--bg); color: #fff; padding: 22px 18px;
  position: sticky; top: 0;
  height: 100vh;
  overflow-y: auto;
  align-self: start;
  display: flex; flex-direction: column;
}
.sidebar nav { flex: 1; }
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }
.sidebar .brand { margin: 0 0 14px; padding: 4px 0 8px; text-align: center; }
.sidebar .brand-logo { max-width: 120px; height: auto; display: block; margin: 0 auto; filter: brightness(0) invert(1); opacity: .92; }
.sidebar .user-info { font-size: 13px; color: #94a3b8; margin-bottom: 20px; padding-bottom: 18px; border-bottom: 1px solid #334155; }
.sidebar .user-info strong { color: #fff; display:block; }
.sidebar nav a { display: block; padding: 10px 12px; color: #cbd5e1; border-radius: 8px; cursor: pointer; margin-bottom: 4px; text-decoration: none; font-size: 14px; transition: all .2s; }
.sidebar nav a:hover, .sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar .logout { margin-top: auto; width: 100%; }
.sidebar .date-display { font-size: 11px; color: #64748b; margin-top: 18px; text-transform: capitalize; }

.main { padding: 24px; overflow-x: hidden; }
.main h2 { margin-bottom: 20px; font-size: 24px; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }

/* ===== CARDS / STATS ===== */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.card { background: #fff; padding: 18px; border-radius: var(--radius); box-shadow: var(--shadow); border-left: 4px solid var(--primary); }
.card .label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.card .value { font-size: 28px; font-weight: 700; }
.card.success { border-left-color: var(--success); }
.card.warning { border-left-color: var(--warning); }
.card.accent { border-left-color: var(--accent); }

/* ===== TABLES ===== */
.panel { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 24px; }
.panel h3 { margin-bottom: 14px; font-size: 18px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { background: #f8fafc; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
tr:hover td { background: #f8fafc; }
td.actions { white-space: nowrap; }
td.actions button { margin-right: 4px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 12px; font-size: 11px; font-weight: 600; background: #e2e8f0; color: #475569; }
.badge.nouveau             { background: #dbeafe; color: #1e40af; }
.badge.ne_repond_pas       { background: #e2e8f0; color: #475569; }
.badge.a_rappeler          { background: #fef3c7; color: #92400e; }
.badge.en_traitement       { background: #dbeafe; color: #1e40af; }
.badge.attente_documents   { background: #fef3c7; color: #92400e; }
.badge.attente_photos      { background: #fed7aa; color: #9a3412; }
.badge.pre_visite          { background: #e0e7ff; color: #3730a3; }
.badge.probleme_toiture    { background: #fecaca; color: #991b1b; }
.badge.charpente_apparente { background: #fecaca; color: #991b1b; }
.badge.deja_isole          { background: #fee2e2; color: #991b1b; }
.badge.infaisable          { background: #fee2e2; color: #991b1b; }
.badge.pas_interesse       { background: #e5e7eb; color: #374151; }
.badge.devis_en_cours      { background: #cffafe; color: #155e75; }
.badge.devis_signe         { background: #bbf7d0; color: #14532d; }
.badge.client              { background: #d1fae5; color: #065f46; }
.badge.lead                { background: #fef9c3; color: #854d0e; }
.badge.visite_technique_programmee { background: #fce7f3; color: #9f1239; }
.badge.installation_programmee     { background: #e0e7ff; color: #3730a3; }
.badge.installe_et_paye            { background: #bbf7d0; color: #14532d; font-weight: 700; }
.badge.admin { background: #dc2626; color: #fff; }
.badge.telepro { background: var(--primary); color: #fff; }
.badge.technicien { background: var(--accent); color: #fff; }
.badge.planifie { background: #dbeafe; color: #1e40af; }
.badge.confirme { background: #d1fae5; color: #065f46; }
.badge.termine { background: #e2e8f0; color: #475569; }
.badge.annule { background: #fee2e2; color: #991b1b; }

/* ===== FORMS / FILTERS ===== */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.form-grid label { font-size: 12px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 4px; }
.form-grid .full { grid-column: 1 / -1; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filters input, .filters select { max-width: 220px; }

/* ===== MODAL ===== */
.modal-backdrop { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(15,23,42,.55); display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal-backdrop.open { display: flex; }
.modal { background: #fff; border-radius: 12px; max-width: 900px; width: 100%; max-height: 92vh; overflow-y: auto; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.small { max-width: 500px; }
.modal.large { max-width: 1100px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 20px; }
.modal-close { background: transparent; color: var(--muted); font-size: 24px; cursor: pointer; border: none; padding: 0 8px; }
.modal-close:hover { color: var(--text); background: transparent; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border); }

#map { width: 100%; height: 440px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
iframe.map-frame { width: 100%; height: 440px; border: 0; border-radius: 8px; }

/* ===== NOTIFICATIONS ===== */
.toast { position: fixed; bottom: 20px; right: 20px; padding: 12px 20px; border-radius: 8px; color: #fff; font-size: 14px; z-index: 200; box-shadow: var(--shadow); animation: slide 0.3s; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slide { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===== CALENDRIER (admin visites) ===== */
.cal-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.cal-nav     { display: flex; align-items: center; gap: 8px; }
.cal-nav strong { margin-left: 6px; font-size: 15px; }
.cal-views   { display: flex; gap: 4px; }
.cal-filters { display: grid; grid-template-columns: 1fr 220px 180px auto auto; gap: 8px; margin-bottom: 12px; }
.cal-filters input, .cal-filters select { padding: 8px 11px; font-size: 13px; }
.cal-legend  { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; min-height: 24px; }
.cal-chip    { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 14px; font-size: 12px; font-weight: 600; border: 1px solid transparent; }
.cal-dot     { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* Week view */
.cal-head { display: grid; grid-template-columns: 60px repeat(7, 1fr); border-bottom: 2px solid var(--border); margin-bottom: 0; }
.cal-hour-col { background: #f8fafc; }
.cal-day-head { text-align: center; padding: 8px 4px; font-size: 12px; color: var(--muted); background: #f8fafc; border-left: 1px solid var(--border); text-transform: uppercase; }
.cal-day-head.today { color: var(--primary); font-weight: 700; background: #eef2ff; }
.cal-daynum { font-size: 22px; font-weight: 700; color: var(--text); margin-top: 2px; }
.cal-day-head.today .cal-daynum { color: var(--primary); }
.cal-week { display: grid; grid-template-columns: 60px repeat(7, 1fr); grid-auto-rows: minmax(70px, auto); }
.cal-hour-label { background: #f8fafc; padding: 6px 8px; text-align: right; color: var(--muted); font-size: 11px; font-weight: 600; border-top: 1px solid var(--border); border-right: 1px solid var(--border); }
.cal-cell { background: #fff; border-top: 1px solid var(--border); border-right: 1px solid var(--border); padding: 2px; position: relative; min-height: 60px; }
.cal-cell.today { background: #f0f5ff; }
.cal-event { background: #eef2ff; color: #3730a3; border-left: 3px solid var(--primary); padding: 5px 8px; margin-bottom: 3px; border-radius: 4px; font-size: 11px; cursor: pointer; transition: all .15s; }
.cal-event:hover { transform: translateX(2px); box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.cal-event-time { display: flex; align-items: center; justify-content: space-between; font-weight: 700; margin-bottom: 2px; }
.cal-event-status .badge { padding: 1px 5px; font-size: 9px; }
.cal-event-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-event-sub   { color: currentColor; opacity: .75; font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-event-tech  { display: flex; align-items: center; gap: 4px; font-size: 10px; opacity: .8; margin-top: 2px; }

/* Month view */
.cal-month-head { display: grid; grid-template-columns: repeat(7, 1fr); border-bottom: 1px solid var(--border); }
.cal-month-head > div { text-align: center; padding: 8px; font-size: 11px; text-transform: uppercase; font-weight: 700; color: var(--muted); background: #f8fafc; }
.cal-month      { display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: minmax(110px, auto); }
.cal-month-cell { background: #fff; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 6px; position: relative; }
.cal-month-cell.outside { background: #f8fafc; color: var(--muted); }
.cal-month-cell.today   { background: #eef2ff; }
.cal-month-num  { font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.cal-month-cell.today .cal-month-num { color: var(--primary); }
.cal-month-event { padding: 3px 6px; margin-bottom: 2px; border-radius: 4px; font-size: 10px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-month-event:hover { filter: brightness(.95); }
.cal-month-more { font-size: 10px; color: var(--muted); font-weight: 600; }

/* Logs - affichage propre */
.log-action { background: #eef2ff; color: var(--primary-dark); padding: 3px 8px; border-radius: 4px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.log-target { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.log-target .icon-btn { padding: 3px 8px; font-size: 11px; }
.log-details { font-size: 12px; }
.log-kv { display: inline-block; margin-right: 4px; }
.log-kv strong { color: var(--muted); font-weight: 600; }

.cal-block-title { font-size: 15px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 2px solid var(--primary); }

/* Mini-agendas par technicien */
.mini-agenda { margin-bottom: 22px; background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.mini-agenda-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 14px; }
.mini-agenda-head strong { flex: 1; letter-spacing: .3px; }
.mini-count { font-size: 12px; font-weight: 600; background: rgba(255,255,255,.6); padding: 2px 10px; border-radius: 12px; }

@media (max-width: 900px) {
  .cal-filters { grid-template-columns: 1fr 1fr; }
  .cal-head, .cal-week { grid-template-columns: 40px repeat(7, 1fr); }
  .cal-event-sub, .cal-event-tech { display: none; }
  .tech-head, .tech-row { grid-template-columns: 120px repeat(7, 1fr); }
  .tech-event-sub { display: none; }
}

/* ===== PLANNING ===== */
.planning { display: grid; grid-template-columns: 80px repeat(7, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.planning .cell, .planning .header-cell, .planning .hour-cell { background: #fff; padding: 8px; min-height: 60px; font-size: 12px; }
.planning .header-cell { background: #f1f5f9; font-weight: 600; text-align: center; }
.planning .hour-cell { background: #f8fafc; color: var(--muted); text-align: center; font-weight: 600; }
.planning .event { background: var(--primary); color: #fff; padding: 4px 6px; border-radius: 4px; font-size: 11px; margin-bottom: 3px; cursor: pointer; }
.planning .event.confirme { background: var(--success); }
.planning .event.annule { background: var(--danger); opacity: .7; }

.section-title { margin: 22px 0 12px; font-size: 16px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }

/* ===== FICHE PROSPECT ===== */
.fiche-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 2px solid var(--primary); }
.fiche-head h4 { font-size: 20px; }
.fiche-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; margin-bottom: 18px; }
.fiche-section { background: #f8fafc; border-radius: 8px; padding: 14px 16px; }
.fiche-section.full { grid-column: 1 / -1; }
.fiche-section h5 { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.fiche-row { display: grid; grid-template-columns: 18px 100px 1fr; gap: 8px; align-items: center; padding: 5px 0; font-size: 13px; }
.fiche-ico { color: var(--muted); }
.fiche-label { color: var(--muted); font-size: 12px; }
.fiche-value { color: var(--text); font-weight: 500; word-break: break-word; }
.fiche-notes { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; font-size: 13px; white-space: pre-wrap; min-height: 40px; }
.fiche-note { background: #fff; border-left: 3px solid var(--primary); border-radius: 4px; padding: 8px 10px; margin-bottom: 6px; font-size: 13px; }
.fiche-note-meta { color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.fiche-status { display: flex; align-items: center; gap: 10px; }
.q-status { max-width: 220px; padding: 6px 10px; font-size: 13px; }

/* Section qualification éditable */
.q-section { background: #f8fafc; border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; }
.q-section h5 { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.q-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.q-field { display: flex; flex-direction: column; gap: 4px; }
.q-field label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.q-field input, .q-field select, .q-field textarea { padding: 9px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; font-family: inherit; background: #fff; }
.q-field input[readonly] { background: #f1f5f9; color: var(--muted); }

/* ===== DOCUMENTS ===== */
.docs-list { margin-bottom: 14px; }
.docs-table { width: 100%; font-size: 13px; }
.docs-table th { font-size: 11px; color: var(--muted); padding: 6px 8px; background: #fff; border-bottom: 1px solid var(--border); }
.docs-table td { padding: 8px; border-bottom: 1px solid var(--border); background: #fff; }
.docs-table tr:last-child td { border-bottom: 0; }
.docs-table a.icon-btn, .docs-table button.icon-btn { text-decoration: none; padding: 5px 9px; font-size: 12px; }

.docs-upload { border: 2px dashed var(--border); border-radius: 8px; padding: 20px; background: #fff; transition: all .2s; }
.docs-upload.drag-over { border-color: var(--primary); background: #eef2ff; }
.docs-drop-inner { display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; color: var(--muted); padding: 10px; }
.docs-drop-inner:hover { color: var(--primary); }
.docs-drop-inner strong { color: var(--text); }
.docs-uploading { margin-top: 10px; color: var(--primary); font-size: 13px; font-weight: 600; }

/* ===== Produits (checklist) ===== */
.products-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.product-chk { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: #fff; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 14px; transition: all .15s; }
.product-chk:hover { border-color: var(--primary); background: #f8fafc; }
.product-chk input { position: absolute; opacity: 0; width: 0; height: 0; }
.product-chk .product-box { width: 20px; height: 20px; border: 2px solid var(--border); border-radius: 4px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; transition: all .15s; }
.product-chk input:checked + .product-box { background: var(--primary); border-color: var(--primary); }
.product-chk input:checked + .product-box::after { content: ''; width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); margin-bottom: 2px; }
.product-chk input:checked ~ span:last-child { font-weight: 600; color: var(--primary); }

/* ===== Inline select assignation ===== */
.inline-assign { padding: 5px 8px; font-size: 12px; border-radius: 5px; border: 1px solid var(--border); background: #fff; max-width: 150px; }
.inline-assign:focus { border-color: var(--primary); outline: none; }

/* ===== PAGINATION ===== */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; flex-wrap: wrap; padding: 10px 0; border-top: 1px solid var(--border); }
.pg-info { color: var(--muted); font-size: 13px; }
.pg-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.pg-btn { padding: 6px 11px; background: #fff; color: var(--text); border: 1px solid var(--border); border-radius: 6px; font-size: 13px; cursor: pointer; font-weight: 500; transition: all .15s; }
.pg-btn:hover:not([disabled]) { background: #f1f5f9; border-color: var(--primary); }
.pg-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pg-btn[disabled] { opacity: .4; cursor: not-allowed; }
.pg-ellipsis { padding: 6px 4px; color: var(--muted); }
.pg-per { max-width: 110px; padding: 6px 10px; font-size: 13px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { padding: 16px; position: static; height: auto; }
  .sidebar .logout { margin-top: 16px; }
}
