/* ============================================================
   SFM CRM — Design System "Swiss Premium"
   Clair, net, typographie soignee, un seul accent.
   ============================================================ */
:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --ink: #101216;
  --ink-2: #4b5058;
  --ink-3: #9aa0a8;
  --line: #e6e6e2;
  --accent: #e30613;          /* rouge suisse */
  --accent-dark: #b00510;
  --ok: #0d7a3f;
  --warn: #b26a00;
  --danger: #c0392b;
  --sidebar: #101216;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,18,22,.05), 0 4px 16px rgba(16,18,22,.06);
  --font: "Helvetica Neue", Helvetica, "Segoe UI", Inter, 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(--ink); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--sidebar); }
.login-card { background: var(--surface); padding: 44px 40px; border-radius: 16px; width: 380px; max-width: calc(100vw - 32px); box-shadow: 0 24px 64px rgba(0,0,0,.4); }
.login-card .brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.brand-mark { width: 40px; height: 40px; border-radius: 10px; background: var(--ink); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 20px; position: relative; }
.brand-mark::after { content: ""; position: absolute; right: -4px; bottom: -4px; width: 14px; height: 14px; background: var(--accent); border-radius: 4px; }
.brand-name { font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
.brand-name small { display: block; font-size: 11px; font-weight: 500; color: var(--ink-3); letter-spacing: .12em; text-transform: uppercase; }
.login-card h1 { font-size: 22px; letter-spacing: -.02em; margin-bottom: 6px; }
.login-card p.sub { color: var(--ink-2); margin-bottom: 24px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fbfbf9; transition: border .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(16,18,22,.08); background: #fff; }
.field textarea { min-height: 90px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: 8px; border: 1px solid transparent; font-weight: 600; font-size: 14px; transition: all .15s; }
.btn-primary { background: var(--ink); color: #fff; width: 100%; }
.btn-primary:hover { background: #000; transform: translateY(-1px); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-dark); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { border-color: var(--ink-3); color: var(--ink); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-danger { background: transparent; border-color: #f0c4c0; color: var(--danger); }
.btn-danger:hover { background: #fdf0ef; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.error-box { background: #fdf0ef; border: 1px solid #f0c4c0; color: var(--danger); padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }
.error-box ul { margin-left: 18px; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: #cfd3d9; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 22px 20px 18px; border-bottom: 1px solid rgba(255,255,255,.07); }
.sidebar .brand-mark { width: 34px; height: 34px; font-size: 17px; background: #fff; color: var(--ink); }
.sidebar .brand-name { color: #fff; font-size: 15px; }
.sidebar .brand-name small { color: #7d838c; }
.nav { padding: 14px 10px; flex: 1; overflow-y: auto; }
.nav-section { font-size: 10px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: #6b7178; padding: 14px 12px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px; color: #cfd3d9; font-weight: 500; font-size: 13.5px; transition: all .12s; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: rgba(255,255,255,.1); color: #fff; }
.nav a .ico { width: 18px; text-align: center; opacity: .8; }
.sidebar .user-box { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.07); display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.user-box .who { flex: 1; min-width: 0; }
.user-box .who b { display: block; color: #fff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-box .who span { font-size: 11px; color: #7d838c; text-transform: capitalize; }
.icon-btn { background: transparent; border: none; color: #7d838c; padding: 6px; border-radius: 6px; }
.icon-btn:hover { color: #fff; background: rgba(255,255,255,.08); }

.main { padding: 28px 32px 60px; max-width: 1440px; width: 100%; }
.topbar { display: flex; align-items: center; gap: 16px; margin-bottom: 26px; }
.topbar h1 { font-size: 24px; letter-spacing: -.02em; font-weight: 700; }
.topbar .spacer { flex: 1; }
.search-global { position: relative; width: 340px; max-width: 40vw; }
.search-global input { width: 100%; padding: 9px 14px 9px 36px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface); }
.search-global input:focus { outline: none; border-color: var(--ink-3); }
.search-global .s-ico { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); max-height: 60vh; overflow-y: auto; z-index: 50; }
.search-results .sr-group { padding: 8px 14px 2px; font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.search-results a { display: block; padding: 7px 14px; font-size: 13.5px; }
.search-results a:hover { background: var(--bg); }
.search-results a small { color: var(--ink-3); margin-left: 8px; }

/* ---------- Cards / KPI ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 26px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.kpi .k-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin-bottom: 8px; }
.kpi .k-value { font-size: 30px; font-weight: 800; letter-spacing: -.03em; }
.kpi .k-sub { font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.kpi.accent { border-top: 3px solid var(--accent); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.panel-body { padding: 16px 18px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 11px 14px; border-bottom: 1px solid #f0f0ed; vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background .1s; }
table.data tbody tr:hover { background: #fafaf8; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge-grey { background: #eef0f2; color: var(--ink-2); }
.badge-blue { background: #e7f0fd; color: #1a56c4; }
.badge-green { background: #e5f6ec; color: var(--ok); }
.badge-red { background: #fdeceb; color: var(--danger); }
.badge-orange { background: #fdf3e3; color: var(--warn); }
.badge-dark { background: var(--ink); color: #fff; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input, .toolbar select { padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.toolbar input:focus, .toolbar select:focus { outline: none; border-color: var(--ink-3); }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- Pipeline kanban ---------- */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; }
.kanban-col { min-width: 230px; width: 230px; flex-shrink: 0; }
.kanban-col-inner { background: #f0f0ec; border-radius: var(--radius); padding: 10px; min-height: 200px; }
.kanban-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 10px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); }
.kanban-head .count { background: #fff; border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; font-size: 11px; }
.kanban-card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; cursor: grab; box-shadow: 0 1px 2px rgba(0,0,0,.04); transition: box-shadow .15s, transform .15s; }
.kanban-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.kanban-card .c-name { font-weight: 650; font-size: 13.5px; margin-bottom: 2px; }
.kanban-card .c-meta { font-size: 12px; color: var(--ink-3); display: flex; justify-content: space-between; margin-top: 6px; }
.kanban-col.dragover .kanban-col-inner { outline: 2px dashed var(--ink-3); outline-offset: -2px; }
.score-dot { display: inline-block; min-width: 26px; text-align: center; border-radius: 6px; font-size: 11px; font-weight: 700; padding: 1px 5px; }
.score-high { background: #e5f6ec; color: var(--ok); }
.score-mid { background: #fdf3e3; color: var(--warn); }
.score-low { background: #fdeceb; color: var(--danger); }

/* ---------- Detail / timeline ---------- */
.detail-header { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.detail-header h1 { font-size: 26px; letter-spacing: -.02em; }
.detail-header .meta { color: var(--ink-2); font-size: 13.5px; margin-top: 4px; }
.detail-header .actions { margin-left: auto; display: flex; gap: 8px; }
.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.timeline-item { position: relative; padding-bottom: 18px; }
.timeline-item::before { content: ""; position: absolute; left: -21px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 2.5px solid var(--ink-3); }
.timeline-item.t-status_change::before { border-color: var(--accent); }
.timeline-item.t-audit::before { border-color: var(--warn); }
.timeline-item.t-meeting::before { border-color: #1a56c4; }
.timeline-item .t-subject { font-weight: 600; font-size: 13.5px; }
.timeline-item .t-body { color: var(--ink-2); font-size: 13px; margin-top: 2px; white-space: pre-wrap; }
.timeline-item .t-when { font-size: 11.5px; color: var(--ink-3); margin-top: 3px; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16,18,22,.45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 100; backdrop-filter: blur(2px); }
.modal { background: var(--surface); border-radius: 14px; width: 620px; max-width: 100%; max-height: 86vh; overflow-y: auto; box-shadow: 0 24px 64px rgba(0,0,0,.3); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 20px 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--surface); }

.empty { text-align: center; color: var(--ink-3); padding: 40px 20px; }

/* ---------- Widget chat (phase 5) ---------- */
.chat-widget { position: fixed; right: 20px; bottom: 20px; z-index: 150; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.chat-fab { width: 52px; height: 52px; border-radius: 50%; border: none; background: var(--ink); color: #fff; font-size: 22px; cursor: pointer; box-shadow: var(--shadow); transition: transform .15s; }
.chat-fab:hover { transform: scale(1.06); background: #000; }
.chat-panel { width: 340px; max-width: calc(100vw - 24px); height: 440px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 24px 64px rgba(0,0,0,.25); flex-direction: column; overflow: hidden; }
.chat-head { display: flex; align-items: baseline; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.chat-log { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { max-width: 88%; padding: 9px 13px; border-radius: 12px; font-size: 13.5px; line-height: 1.45; white-space: pre-wrap; }
.chat-msg.user { align-self: flex-end; background: var(--ink); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.bot { align-self: flex-start; background: var(--bg); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.chat-msg.pending { color: var(--ink-3); }
.chat-foot { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.chat-input { flex: 1; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fbfbf9; }
.chat-input:focus { outline: none; border-color: var(--ink-3); }
@media (max-width: 600px) {
  .chat-widget { right: 12px; bottom: 12px; left: 12px; align-items: stretch; }
  .chat-fab { align-self: flex-end; }
  .chat-panel { width: 100%; height: 60vh; }
}
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow); z-index: 200; font-size: 13.5px; animation: slideup .2s ease; }
@keyframes slideup { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.score-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.score-box { background: #fbfbf9; border: 1px solid var(--line); border-radius: 8px; padding: 12px; text-align: center; }
.score-box .s-val { font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.score-box .s-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }

/* ---------- Responsive ---------- */
/* Tablette paysage / petit desktop : respiration reduite mais layout identique */
@media (min-width: 901px) and (max-width: 1200px) {
  .main { padding: 22px 24px 50px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .search-global { width: 260px; }
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 90; width: 232px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .main { padding: 18px 16px 60px; }
  .grid-2 { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 20px; }
  .menu-toggle { display: inline-flex !important; }
  .form-row { grid-template-columns: 1fr; }
}

/* Mobile : une colonne, pleine largeur, zones tactiles confortables */
@media (max-width: 600px) {
  body { font-size: 13.5px; }
  .main { padding: 14px 12px 80px; }
  .topbar { flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
  .topbar .spacer { display: none; }
  .search-global { order: 3; width: 100%; max-width: none; }
  .cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi { padding: 14px; }
  .kpi .k-value { font-size: 24px; }
  .panel-head { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }
  .panel-body { padding: 12px 14px; }
  table.data th, table.data td { padding: 9px 10px; }
  .btn { padding: 11px 16px; }                 /* cible tactile >= 44px */
  .btn-sm { padding: 8px 12px; }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0; }
  .modal-head, .modal-body, .modal-foot { padding-left: 16px; padding-right: 16px; }
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; }
  .kanban-col { min-width: 200px; width: 200px; }
  .toast { left: 12px; right: 12px; bottom: 16px; text-align: center; }
  .detail-header .actions { margin-left: 0; width: 100%; }
  .detail-header .actions .btn { flex: 1; }
  .login-card { padding: 32px 24px; }
  .sidebar { width: 260px; }                    /* nav plus lisible au doigt */
  .nav a { padding: 11px 12px; font-size: 14px; }
}

/* Petits mobiles */
@media (max-width: 380px) {
  .cards { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 18px; }
}

/* Garde-fou anti-debordement horizontal */
html, body { overflow-x: clip; }
img, table { max-width: 100%; }
.menu-toggle { display: none; }

@media print {
  .sidebar, .toolbar, .topbar .actions, .btn { display: none !important; }
  .layout { grid-template-columns: 1fr; }
  .main { padding: 0; }
}
