/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue: #F07C21;
  --blue-dark: #d96710;
  --blue-light: #fff4e8;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #9ca3af;
  --gray-600: #4b5563;
  --gray-800: #1f2937;
  --red: #dc2626;
  --red-light: #fef2f2;
  --orange: #ea580c;
  --orange-light: #fff7ed;
  --yellow: #d97706;
  --yellow-light: #fffbeb;
  --green: #16a34a;
  --green-light: #f0fdf4;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  min-height: 100vh;
}

/* ===== HEADER ===== */
header {
  background: #F07C21;
  border-bottom: none;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.1rem;
  color: white;
  white-space: nowrap;
}
.logo strong { color: white; }

nav {
  display: flex;
  gap: 4px;
}

.nav-btn {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: .875rem;
  color: white;
  transition: background .15s, color .15s;
}
.nav-btn:hover { background: rgba(255,255,255,.25); color: white; }
.nav-btn.active { background: white; color: #F07C21; font-weight: 600; }

.header-user { display: flex; align-items: center; gap: 10px; margin-left: auto; white-space: nowrap; flex-shrink: 0; }
.header-username { font-size: .85rem; color: rgba(255,255,255,.9); font-weight: 500; }
.btn-logout { background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.35); color: white; border-radius: 6px; padding: 5px 12px; font-size: .82rem; cursor: pointer; transition: background .15s; white-space: nowrap; }
.btn-logout:hover { background: rgba(255,255,255,.3); }

/* ===== AVATARS UTILISATEURS ===== */
.user-avatar { border-radius: 50%; object-fit: cover; border: 2px solid var(--blue-light); flex-shrink: 0; }
.user-avatar-initials { border-radius: 50%; background: var(--blue); color: white; display: flex; align-items: center; justify-content: center; font-weight: 700; letter-spacing: .03em; flex-shrink: 0; }
/* Avatar dans l'en-tête */
#header-avatar .user-avatar, #header-avatar .user-avatar-initials { border: 2px solid rgba(255,255,255,.5); }
.tech-avatar-wrap { display: inline-flex; align-items: center; flex-shrink: 0; }
/* Pastille en ligne */
.avatar-online-wrap { position: relative; display: inline-flex; flex-shrink: 0; }
.online-dot {
  position: absolute;
  bottom: 0; right: 0;
  background: #22c55e;
  border: 2px solid white;
  border-radius: 50%;
  display: block;
  box-shadow: 0 0 0 0 rgba(34,197,94,.5);
  animation: pulse-online 2s ease-in-out infinite;
}
@keyframes pulse-online {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,.4); }
  50%       { box-shadow: 0 0 0 4px rgba(34,197,94,0); }
}
/* Zone upload avatar dans le modal */
.user-avatar-upload-preview { position: relative; width: 64px; height: 64px; flex-shrink: 0; }
.user-avatar-upload-preview .user-avatar { width: 64px; height: 64px; }
.user-avatar-upload-preview .user-avatar-initials { width: 64px; height: 64px; font-size: 22px; }
.btn-avatar-upload { display: inline-block; background: var(--blue-light); color: var(--blue-dark); border: 1.5px solid #f9c48a; border-radius: 6px; padding: 6px 12px; font-size: .82rem; font-weight: 600; cursor: pointer; transition: background .15s; }
.btn-avatar-upload:hover { background: #ffe8cc; }
.btn-avatar-clear { background: none; border: none; color: #9ca3af; font-size: .8rem; cursor: pointer; padding: 4px 0; display: block; margin-top: 4px; }
.btn-avatar-clear:hover { color: #dc2626; }

/* ===== MAIN ===== */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px;
}

.view { display: none; }
.view.active { display: block; }

.page-title { margin-bottom: 28px; }
.page-title h1 { font-size: 1.5rem; font-weight: 700; }
.page-title p { color: var(--gray-600); font-size: .9rem; margin-top: 4px; }

/* ===== STATS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
}
.stat-icon { font-size: 1.8rem; }
.stat-value { font-size: 1.8rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .8rem; color: var(--gray-600); margin-top: 2px; }
.stat-total .stat-value { color: var(--blue); }
.stat-open .stat-value { color: var(--red); }
.stat-progress .stat-value { color: var(--yellow); }
.stat-closed .stat-value { color: var(--green); }
#stat-closed-card:hover { box-shadow: var(--shadow-md); border-color: var(--green); transform: translateY(-1px); transition: all .15s; }
.stat-chart:hover { box-shadow: var(--shadow-md); border-color: var(--blue); transform: translateY(-1px); transition: all .15s; }

/* ===== RÉPONSE EMAIL ===== */
.reply-section { background: #fffdf9; border: 1.5px solid #f9c48a; border-radius: 10px; padding: 16px; }
.reply-section h3 { color: #d96710; margin-bottom: 10px; }
.reply-to-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; background: white; border: 1px solid var(--gray-200); border-radius: 6px; padding: 7px 12px; }
.reply-to-label { font-size: .8rem; font-weight: 600; color: var(--gray-600); white-space: nowrap; }
.reply-to-email { font-size: .875rem; color: var(--blue); }
.reply-templates-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.reply-templates-label { font-size: .8rem; font-weight: 600; color: var(--gray-600); white-space: nowrap; }
.reply-template-select { flex: 1; border: 1.5px solid #f9c48a; border-radius: 6px; padding: 6px 10px; font-size: .82rem; font-family: inherit; background: white; color: var(--gray-700); cursor: pointer; outline: none; transition: border-color .15s; }
.reply-template-select:hover, .reply-template-select:focus { border-color: var(--blue); }
.btn-reply { background: var(--blue); color: white; border: none; border-radius: 6px; padding: 8px 16px; font-size: .875rem; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; transition: background .15s; }
.btn-reply:hover { background: var(--blue-dark); }
.btn-reply:disabled { opacity: .45; cursor: not-allowed; }
.close-on-send-label { display:inline-flex; align-items:center; gap:7px; font-size:.82rem; color:var(--gray-600); cursor:pointer; user-select:none; padding:6px 10px; border:1px solid var(--gray-200); border-radius:6px; background:white; transition:border-color .15s, background .15s; }
.close-on-send-label:hover { border-color:#f9c48a; background:#fffdf9; }
.close-on-send-label input[type="checkbox"] { accent-color: var(--blue); width:15px; height:15px; cursor:pointer; }

/* ===== HISTORIQUE NOTES ===== */
.note-internal { background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: 6px; padding: 10px 12px; margin-bottom: 8px; font-size: .875rem; }
.note-internal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.note-internal-header span:first-child { font-size: .75rem; font-weight: 600; color: var(--gray-600); }
.note-reply { background: #fffdf9; border: 1px solid #f9c48a; border-left: 3px solid var(--blue); border-radius: 6px; padding: 10px 12px; margin-bottom: 8px; font-size: .875rem; }
.note-reply-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.note-reply-header span:first-child { font-size: .75rem; font-weight: 600; color: #d96710; }
.note-date { font-size: .72rem; color: var(--gray-400); white-space: nowrap; }
.note-client-reply { background: #f0fdf4; border: 1px solid #bbf7d0; border-left: 3px solid var(--green); border-radius: 6px; padding: 10px 12px; margin-bottom: 8px; font-size: .875rem; }
.note-client-reply-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; flex-wrap: wrap; gap: 4px; }
.note-client-reply-header span:first-child { font-size: .75rem; font-weight: 600; color: var(--green); }

/* ===== RESOLVED MODAL LIST ===== */
.resolved-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--gray-200);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background .12s;
}
.resolved-row:hover { background: var(--gray-50); border-color: var(--green); }
.resolved-row-main { display: flex; align-items: baseline; gap: 8px; }
.resolved-id { font-size: .75rem; font-family: monospace; color: var(--gray-400); white-space: nowrap; }
.resolved-company { font-weight: 600; color: var(--gray-800); }
.resolved-title { font-size: .875rem; font-weight: 500; color: var(--gray-800); }
.resolved-row-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.resolved-time { font-size: .78rem; color: #d96710; background: #fff4e8; border: 1px solid #f9c48a; border-radius: 20px; padding: 1px 8px; }
.resolved-tech { font-size: .78rem; color: var(--gray-600); }
.resolved-date { font-size: .78rem; color: var(--gray-400); margin-left: auto; white-space: nowrap; }

/* ===== DASHBOARD GRID ===== */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

@media (max-width: 768px) {
  .dashboard-grid { grid-template-columns: 1fr; }
}

.card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
}
.card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 16px; color: var(--gray-800); }

/* ===== TICKET LIST SMALL (dashboard) ===== */

.ticket-small {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  cursor: pointer;
  transition: background .15s;
  gap: 12px;
}
.ticket-small:hover { background: var(--blue-light); border-color: var(--blue); }
.ticket-small-title { font-size: .875rem; font-weight: 500; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticket-small-meta { font-size: .75rem; color: var(--gray-600); white-space: nowrap; }
.ticket-small-client { font-size: .78rem; color: var(--gray-600); white-space: nowrap; }

.ticket-list-small { display: flex; flex-direction: column; gap: 6px; }

.ticket-small-wrap {
  display: flex;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  background: var(--gray-50);
  overflow: hidden;
  transition: border-color .15s;
}
.ticket-small-wrap:hover { border-color: var(--blue); }

/* ── Carré contrat à gauche ────────────────────────── */
.contrat-flag {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  width: 44px;
  flex-shrink: 0;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  cursor: default;
}
.flag-contrat     { background: #dcfce7; color: #15803d; }
.flag-hors-contrat { background: #f1f5f9; color: #64748b; }

/* ── Alertes tickets ───────────────────────────────── */
.ticket-alert {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: .72rem; font-weight: 700; border-radius: 20px;
  padding: 2px 8px; white-space: nowrap;
}
.alert-new {
  background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa;
  animation: pulse-new 2s ease-in-out infinite;
}
.alert-reply {
  background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe;
  animation: pulse-reply 2s ease-in-out infinite;
}
@keyframes pulse-new {
  0%, 100% { box-shadow: 0 0 0 0 rgba(194,65,12,0); }
  50%       { box-shadow: 0 0 0 3px rgba(194,65,12,.15); }
}
@keyframes pulse-reply {
  0%, 100% { box-shadow: 0 0 0 0 rgba(29,78,216,0); }
  50%       { box-shadow: 0 0 0 3px rgba(29,78,216,.15); }
}
/* Mise en évidence des lignes dans la table */
tr.row-non-traite  { border-left: 3px solid #f97316; }
tr.row-reply-recu  { border-left: 3px solid #3b82f6; }
tr.row-non-traite td:first-child  { border-left: 4px solid #f97316; }
tr.row-reply-recu td:first-child  { border-left: 4px solid #3b82f6; }


.ticket-small-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.ticket-small-wrap .ticket-small {
  flex: 1;
  min-width: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  border-bottom: 1px solid var(--gray-200);
}
.ticket-small-wrap .ticket-small:hover { background: var(--blue-light); }

.ticket-note-input {
  width: 100%;
  border: none;
  background: white;
  padding: 6px 12px;
  font-size: .8rem;
  color: var(--gray-600);
  font-family: inherit;
  outline: none;
  transition: background .15s;
}
.ticket-note-input:focus { background: #fffbeb; color: var(--gray-800); }
.ticket-note-input::placeholder { color: var(--gray-400); font-style: italic; }

.tech-select {
  border: 1.5px solid var(--gray-200);
  border-radius: 99px;
  padding: 2px 8px;
  font-size: .75rem;
  font-weight: 500;
  color: var(--gray-800);
  background: white;
  cursor: pointer;
  transition: border-color .15s;
  white-space: nowrap;
  max-width: 120px;
}
.tech-select:hover { border-color: var(--blue); color: var(--blue); }
.tech-select:focus { outline: none; border-color: var(--blue); }

/* ===== TIMER ===== */
.timer-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #fff8f0;
  border: 1px solid #f9c48a;
  border-radius: 20px;
  padding: 2px 8px;
  white-space: nowrap;
}
.timer-display {
  font-family: 'Courier New', monospace;
  font-size: .8rem;
  font-weight: 700;
  color: #d96710;
  letter-spacing: .05em;
}
.timer-toggle-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: .75rem;
  padding: 0 2px;
  line-height: 1;
  opacity: .8;
  transition: opacity .15s;
}
.timer-toggle-btn:hover { opacity: 1; }

/* Timer dans la modale */
.modal-timer-section h3 { color: #d96710; }
.modal-timer-box {
  display: flex;
  align-items: center;
  gap: 16px;
  background: #fff8f0;
  border: 1px solid #f9c48a;
  border-radius: 10px;
  padding: 14px 20px;
  margin-top: 8px;
}
.modal-timer-clock {
  font-family: 'Courier New', monospace;
  font-size: 2rem !important;
  font-weight: 700;
  color: #d96710;
  letter-spacing: .1em;
}
.btn-timer-pause {
  background: #fff3e0;
  color: #d96710;
  border: 1px solid #f9c48a;
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: .875rem;
  font-weight: 600;
  transition: background .15s;
}
.btn-timer-pause:hover { background: #ffe0b2; }
.btn-timer-start {
  background: #F07C21;
  color: white;
  border: 1px solid #d96710;
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: .875rem;
  font-weight: 600;
  transition: background .15s;
}
.btn-timer-start:hover { background: #d96710; }

/* ===== PRIORITY BARS ===== */
.priority-bars { display: flex; flex-direction: column; gap: 12px; }

.priority-bar-item { display: flex; flex-direction: column; gap: 4px; }
.priority-bar-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: .8rem; flex-wrap: nowrap; }
.priority-bar-header span:first-child { white-space: nowrap; min-width: 55px; }
.priority-bar-header span:last-child  { white-space: nowrap; text-align: right; flex-shrink: 0; }
.priority-bar-track { background: var(--gray-100); border-radius: 99px; height: 8px; overflow: hidden; }
.priority-bar-fill { height: 100%; border-radius: 99px; transition: width .5s ease; }

/* ===== FORM ===== */
.form-container {
  background: white;
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  max-width: 800px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { margin-bottom: 20px; }

label { font-size: .875rem; font-weight: 500; color: var(--gray-800); }
.required { color: var(--red); }

input, select, textarea {
  border: 1.5px solid var(--gray-200);
  border-radius: 6px;
  padding: 9px 12px;
  font-size: .9rem;
  color: var(--gray-800);
  background: white;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(240, 124, 33, .18);
}
textarea { resize: vertical; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 8px;
}

/* ===== BUTTONS ===== */
.btn {
  padding: 9px 20px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: .875rem;
  font-weight: 500;
  transition: background .15s, transform .1s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary { background: var(--gray-100); color: var(--gray-800); border: 1px solid var(--gray-200); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-danger { background: var(--red-light); color: var(--red); border: 1px solid #fecaca; }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 5px 12px; font-size: .8rem; }
.btn-icon { background: none; border: none; cursor: pointer; padding: 4px 8px; border-radius: 4px; transition: background .15s; font-size: .85rem; }
.btn-icon:hover { background: var(--gray-100); }

/* ===== TOOLBAR ===== */
.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.toolbar input { flex: 1; min-width: 200px; }
.toolbar select { min-width: 160px; }

/* ===== TABLE ===== */
#tickets-table-container { overflow-x: auto; }

#tickets-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  font-size: .875rem;
}

#tickets-table thead th {
  background: var(--gray-50);
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--gray-600);
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}

#tickets-table tbody tr {
  border-bottom: 1px solid var(--gray-100);
  transition: background .1s;
}
#tickets-table tbody tr:last-child { border-bottom: none; }
#tickets-table tbody tr:hover { background: var(--gray-50); }

#tickets-table td {
  padding: 12px 14px;
  vertical-align: middle;
}

.ticket-id { color: var(--gray-400); font-size: .8rem; font-family: monospace; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-critique { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.badge-haute    { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }
.badge-normale  { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.badge-faible   { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

.badge-contrat      { background: #fff4e8; color: #d96710; border: 1px solid #f9c48a; }
.badge-hors-contrat { background: var(--gray-100); color: var(--gray-600); border: 1px solid var(--gray-200); }

.badge-ouvert   { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.badge-en-cours { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.badge-standby  { background: #f5f3ff; color: #6d28d9; border: 1px solid #ddd6fe; }
.badge-résolu   { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.badge-fermé    { background: var(--gray-100); color: var(--gray-600); border: 1px solid var(--gray-200); }

/* ===== STATUS PILLS (modal) ===== */
.modal-status-bar { display: flex; gap: 6px; margin-top: 14px; flex-wrap: wrap; }
.status-pill { border: 2px solid; border-radius: 20px; padding: 5px 16px; font-size: .82rem; font-weight: 600; cursor: pointer; background: white; transition: all .15s; }
.status-pill:hover { opacity: .8; }
.status-pill-ouvert   { border-color: #3b82f6; color: #3b82f6; }
.status-pill-ouvert.active   { background: #3b82f6; color: white; }
.status-pill-en-cours { border-color: #d97706; color: #d97706; }
.status-pill-en-cours.active { background: #d97706; color: white; }
.status-pill-standby  { border-color: #6d28d9; color: #6d28d9; }
.status-pill-standby.active  { background: #6d28d9; color: white; }
.status-pill-résolu   { border-color: #16a34a; color: #16a34a; }
.status-pill-résolu.active   { background: #16a34a; color: white; }

/* ===== CONFETTI ===== */
@keyframes confetti-fall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  80%  { opacity: 1; }
  100% { transform: translateY(105vh) rotate(var(--rot)); opacity: 0; }
}
@keyframes confetti-pop {
  0%   { transform: translate(-50%,-50%) scale(0); opacity: 0; }
  60%  { transform: translate(-50%,-50%) scale(1.1); opacity: 1; }
  80%  { transform: translate(-50%,-50%) scale(.95); }
  100% { transform: translate(-50%,-50%) scale(1); opacity: 1; }
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-400);
  font-size: .9rem;
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn .15s;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: white;
  border-radius: var(--radius);
  padding: 28px;
  max-width: 680px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  animation: slideUp .2s;
}

@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--gray-100);
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: .85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-600);
}
.modal-close:hover { background: var(--gray-200); }

.modal-header {
  margin-bottom: 20px;
  padding-right: 32px;
}
.modal-header h2 { font-size: 1.15rem; font-weight: 700; }
.modal-header .ticket-date { font-size: .8rem; color: var(--gray-400); margin-top: 4px; }

.modal-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 20px;
}
.meta-item { display: flex; flex-direction: column; gap: 2px; }
.meta-item .meta-label { font-size: .75rem; color: var(--gray-400); text-transform: uppercase; letter-spacing: .05em; }
.meta-item .meta-value { font-size: .875rem; font-weight: 500; }

.modal-section { margin-bottom: 20px; }
.modal-section h3 { font-size: .85rem; font-weight: 600; color: var(--gray-600); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .04em; }
.modal-section p { font-size: .9rem; line-height: 1.6; color: var(--gray-800); }

/* ===== TICKET INITIAL ===== */
.modal-ticket-initial { background: #fafafa; border: 1.5px solid var(--gray-200); border-radius: 10px; padding: 16px; }
.modal-ticket-initial h3 { color: var(--gray-700); }
.ticket-initial-label { display: block; font-size: .75rem; font-weight: 700; color: var(--gray-500); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.ticket-initial-attachment { margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--gray-200); }
.ticket-initial-file { display: inline-flex; align-items: center; gap: 6px; font-size: .875rem; color: var(--blue); text-decoration: none; background: var(--blue-light); border: 1px solid #f9c48a; padding: 6px 12px; border-radius: 6px; }
.ticket-initial-file:hover { background: #ffe8cc; }
.ticket-initial-desc-block {  }
.ticket-initial-desc { font-size: .9rem; line-height: 1.6; color: var(--gray-800); white-space: pre-wrap; }

/* ===== ONGLET TEMPS PASSÉ ===== */
.temps-societe-header { display: flex; align-items: center; justify-content: space-between; background: white; border: 1.5px solid var(--gray-200); border-radius: 10px; padding: 14px 20px; margin-bottom: 20px; }
.temps-societe-name { font-size: 1.1rem; font-weight: 700; color: var(--gray-800); }
.temps-total-badge { background: var(--blue); color: white; font-size: .95rem; font-weight: 700; padding: 6px 18px; border-radius: 20px; }

.modal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  border-top: 1px solid var(--gray-200);
  padding-top: 16px;
  margin-top: 16px;
}

.status-select {
  border: 1.5px solid var(--gray-200);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: .8rem;
  background: white;
  cursor: pointer;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: #1f2937;
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: .875rem;
  box-shadow: var(--shadow-md);
  z-index: 999;
  animation: slideInRight .25s;
}
@keyframes slideInRight {
  from { transform: translateX(60px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }

/* ===== STATISTIQUES ===== */
.stats-kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: white;
  border-radius: 12px;
  border: 1px solid var(--gray-200);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.kpi-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
}

.kpi-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.kpi-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-800);
  line-height: 1;
}

.kpi-label {
  font-size: .72rem;
  color: var(--gray-500);
  font-weight: 500;
}

.stats-charts-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 20px;
}

.stats-charts-row-2col {
  grid-template-columns: repeat(2, 1fr);
}

.stats-chart-card {
  background: white;
  border-radius: 12px;
  border: 1px solid var(--gray-200);
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.stats-chart-title {
  font-size: .85rem;
  font-weight: 600;
  color: var(--gray-700);
  margin: 0 0 16px 0;
}

.stats-chart-wrap {
  position: relative;
  max-width: 220px;
  margin: 0 auto;
}

.stats-chart-wrap-tall {
  position: relative;
  height: 240px;
}

.stats-chart-wrap-line {
  position: relative;
  height: 220px;
}

@media (max-width: 900px) {
  .stats-charts-row       { grid-template-columns: 1fr; }
  .stats-charts-row-2col  { grid-template-columns: 1fr; }
}

/* ===== DROITS D'ACCÈS — PERMISSION TOGGLES ===== */
.perm-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px 4px 6px;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: background .2s, color .2s;
  border: 1.5px solid transparent;
  white-space: nowrap;
}

.perm-toggle.perm-on {
  background: #f0fdf4;
  color: #16a34a;
  border-color: #bbf7d0;
}

.perm-toggle.perm-off {
  background: #fef2f2;
  color: #dc2626;
  border-color: #fecaca;
}

.perm-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.perm-toggle.perm-on  .perm-dot { background: #16a34a; }
.perm-toggle.perm-off .perm-dot { background: #dc2626; }

.perm-toggle:hover {
  filter: brightness(.95);
}

/* ===================================================
   RESPONSIVE MOBILE  (≤ 768px)
   =================================================== */

/* -- Login page ------------------------------------ */
@media (max-width: 480px) {
  .login-card { padding: 32px 20px; border-radius: 12px; }
}

/* -- Header ---------------------------------------- */
@media (max-width: 768px) {
  .header-inner {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 14px 0;
    gap: 6px;
    align-items: center;
  }

  /* Logo : réduit */
  .logo { font-size: .95rem; }
  .logo img { width: 28px; height: 28px; }

  /* Nav : barre horizontale scrollable sur toute la largeur */
  nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    display: flex;
    gap: 4px;
    padding: 8px 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  nav::-webkit-scrollbar { display: none; }
  .nav-btn { font-size: .76rem; padding: 5px 10px; white-space: nowrap; flex-shrink: 0; }

  /* User : masque le nom, garde avatar + déconnexion */
  .header-username { display: none; }
  .btn-logout { font-size: .76rem; padding: 4px 9px; }
}

/* -- Main layout ----------------------------------- */
@media (max-width: 768px) {
  main { padding: 16px 12px; }
  .page-title { margin-bottom: 18px; }
  .page-title h1 { font-size: 1.2rem; }
}

/* -- Stat cards dashboard -------------------------- */
@media (max-width: 600px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px 12px; gap: 10px; }
  .stat-value { font-size: 1.4rem; }
  .stat-icon { font-size: 1.4rem; }
}

/* -- Toolbar --------------------------------------- */
@media (max-width: 768px) {
  .toolbar { gap: 8px; }
  .toolbar input, .toolbar select { font-size: .85rem; }
  #temps-societe-select { max-width: 100% !important; }
}

/* -- Tableau tickets : masque colonnes secondaires -- */
@media (max-width: 900px) {
  #tickets-table th:nth-child(5),
  #tickets-table td:nth-child(5),
  #tickets-table th:nth-child(6),
  #tickets-table td:nth-child(6) { display: none; }
}

/* -- Tableau → cartes compactes sur mobile ---------- */
@media (max-width: 640px) {
  #tickets-table-container { overflow-x: visible; }
  #tickets-table, #tickets-table tbody,
  #tickets-table tr, #tickets-table td { display: block; width: 100%; }
  #tickets-table thead { display: none; }

  #tickets-table tr {
    margin-bottom: 8px;
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    padding: 10px 12px;
    background: white;
    box-shadow: var(--shadow);
    cursor: pointer;
    position: relative;
  }
  #tickets-table tr.row-non-traite { border-left: 3px solid #f97316; }
  #tickets-table tr.row-reply-recu { border-left: 3px solid #3b82f6; }
  #tickets-table tr:hover { background: var(--gray-50); }

  /* Masquer tous les TDs par défaut */
  #tickets-table td { display: none; padding: 0; border: none; }

  /* Ligne 1 : Titre (col 2) */
  #tickets-table td:nth-child(2) {
    display: block;
    font-size: .88rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 5px;
    padding-right: 60px; /* espace pour actions */
  }

  /* Ligne 2 : Société (col 4) + Statut (col 8) côte à côte */
  #tickets-table td:nth-child(4) {
    display: inline-block;
    font-size: .76rem;
    color: var(--gray-600);
    margin-right: 8px;
  }
  #tickets-table td:nth-child(8) {
    display: inline-block;
    font-size: .76rem;
  }

  /* Actions (col 10) : coin haut droit */
  #tickets-table td:nth-child(10) {
    display: block;
    position: absolute;
    top: 8px;
    right: 8px;
    width: auto;
    padding: 0;
  }
  #tickets-table td:nth-child(10) .btn-icon { padding: 4px 6px; font-size: .9rem; }
}

/* -- Modal ----------------------------------------- */
@media (max-width: 640px) {
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    border-radius: 18px 18px 0 0;
    max-height: 92vh;
    padding: 20px 16px;
    max-width: 100%;
  }
  .modal-meta { grid-template-columns: 1fr; }
  .modal-actions { flex-direction: column; }
  .modal-actions .btn { width: 100%; text-align: center; }
  .modal-status-bar { gap: 6px; }
  .status-pill { padding: 6px 12px; font-size: .8rem; }
}

/* -- KPI Stats ------------------------------------- */
@media (max-width: 600px) {
  .stats-kpi-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi-card { padding: 12px 12px; gap: 10px; }
  .kpi-value { font-size: 1.2rem; }
  .kpi-icon { font-size: 1.3rem; }
}

/* -- Formulaire nouveau ticket --------------------- */
@media (max-width: 600px) {
  .form-container { padding: 20px 14px; }
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; text-align: center; }
}

/* -- Toast ----------------------------------------- */
@media (max-width: 480px) {
  .toast { bottom: 16px; right: 12px; left: 12px; text-align: center; }
}

/* -- Dashboard : tickets ouverts compacts ---------- */
@media (max-width: 640px) {
  /* Masque flag contrat (bande verticale gauche) */
  .contrat-flag { display: none; }

  /* Ticket = flex colonne compacte */
  .ticket-small {
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px 10px;
    align-items: flex-start;
  }

  /* Titre + société : pleine largeur */
  .ticket-small-title {
    width: 100%;
    font-size: .82rem;
    white-space: normal;
    line-height: 1.3;
  }

  /* Masque avatar technicien, select, timer, note, date */
  .tech-avatar-wrap,
  .tech-select,
  .timer-badge,
  .ticket-small-meta,
  .ticket-note-input { display: none !important; }

  /* Status badge reste visible */
  .ticket-small .badge { font-size: .72rem; padding: 2px 8px; }

  /* Alerte reste visible */
  .ticket-alert { font-size: .7rem; }
}

/* -- Temps passé header ---------------------------- */
@media (max-width: 640px) {
  .temps-societe-header { flex-direction: column; align-items: flex-start; gap: 8px; }
}

/* -- Boutons touch-friendly (cibles min 44px) ------- */
@media (max-width: 768px) {
  .btn { min-height: 42px; }
  .btn-sm { min-height: 36px; }
  input, select, textarea { font-size: 16px !important; } /* évite le zoom iOS */
}
