:root {
  --gps-green: #308A26;
  --gps-green-dark: #1F5C19;
  --gps-orange: #FF7C10;
  --gps-orange-dark: #C95F0A;
  --bg: #F4F6F3;
  --surface: #FFFFFF;
  --border: #E1E5DE;
  --text: #1C231B;
  --text-muted: #6B756A;
  --danger: #C0392B;
  --danger-bg: #FBEAE8;
  --warning: #B8860B;
  --warning-bg: #FCF3D9;
  --success: #2E7D32;
  --success-bg: #E8F5E9;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, -apple-system, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--gps-green-dark); }

.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #ffffff 0%, var(--bg) 100%);
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.login-card img { width: 84px; margin-bottom: 12px; }
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card p.subtitle { color: var(--text-muted); font-size: 13px; margin: 0 0 24px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.login-card label { font-size: 13px; font-weight: 600; color: var(--text-muted); }

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gps-green);
  box-shadow: 0 0 0 3px rgba(48,138,38,0.12);
}

button {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  background: var(--gps-green);
  color: #fff;
  transition: background 0.15s ease;
}
button:hover { background: var(--gps-green-dark); }
button.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
button.secondary:hover { background: #f0f0ee; }
button.orange { background: var(--gps-orange); }
button.orange:hover { background: var(--gps-orange-dark); }
button.danger { background: var(--danger); }
button.danger:hover { background: #9c2d21; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.error-msg { color: var(--danger); font-size: 13px; min-height: 16px; }
.info-msg { color: var(--gps-green-dark); font-size: 13px; }

/* ---------- App shell ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, var(--gps-green-dark) 0%, var(--gps-green) 100%);
  border-bottom: 3px solid var(--gps-orange);
  padding: 10px 20px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
.app-header .brand { display: flex; align-items: center; gap: 10px; }
.app-header .brand img { height: 34px; border-radius: 6px; background: #fff; padding: 2px; }
.app-header .brand span { font-weight: 700; font-size: 15px; color: #fff; letter-spacing: .02em; }
.app-header .user-info { display: flex; align-items: center; gap: 12px; font-size: 13px; color: rgba(255,255,255,0.9); }
.app-header .user-info #user-name { font-weight: 600; color: #fff; }
.app-header .user-info button.secondary { background: rgba(255,255,255,0.15); color: #fff; border-color: rgba(255,255,255,0.35); }
.app-header .user-info button.secondary:hover { background: rgba(255,255,255,0.28); }
.role-badge {
  background: rgba(255,255,255,0.18); color: #fff;
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px; text-transform: uppercase;
  border: 1px solid rgba(255,255,255,0.35);
}

.tabs {
  display: flex; gap: 4px; padding: 8px 20px 0; background: var(--surface);
  border-bottom: 1px solid var(--border); overflow-x: auto;
}
.tab-btn {
  background: transparent; color: var(--text-muted); border: none; border-radius: 8px 8px 0 0;
  padding: 10px 16px; font-weight: 600; font-size: 13px; white-space: nowrap;
}
.tab-btn:hover { background: var(--bg); color: var(--text); }
.tab-btn.active { color: var(--gps-green-dark); border-bottom: 3px solid var(--gps-green); background: var(--bg); }
.tab-badge {
  display: inline-block; min-width: 16px; padding: 1px 5px; margin-left: 6px; border-radius: 10px;
  background: var(--danger, #c0392b); color: #fff; font-size: 10px; font-weight: 700; vertical-align: middle;
}

main { max-width: 1100px; margin: 0 auto; padding: 20px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px;
}
.card h2 { font-size: 15px; margin: 0 0 14px; }
.card h3 { font-size: 13px; color: var(--text-muted); margin: 0 0 10px; text-transform: uppercase; letter-spacing: .03em; }

.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.metric { background: var(--bg); border-radius: 8px; padding: 14px 16px; }
.metric .label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.metric .value { font-size: 22px; font-weight: 700; }
.metric .value.danger { color: var(--danger); }
.metric .value.warning { color: var(--warning); }

#comptes-table, #stock-table, #bons-sortie-table, #reservations-table, #td-table, #rh-table,
#revue-ventes-table, #portefeuille-client-table, #documents-liste, #journal-liste,
#comptes-alertes {
  overflow-x: auto;
  max-width: 100%;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tr:hover td { background: var(--bg); }
td.num, th.num { text-align: right; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge.ok { background: var(--success-bg); color: var(--success); }
.badge.warn { background: var(--warning-bg); color: var(--warning); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.muted { background: var(--bg); color: var(--text-muted); }

.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.form-field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 140px; }
.form-field label { font-size: 12px; font-weight: 600; color: var(--text-muted); }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; flex-wrap: wrap; }

.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--text); color: #fff;
  padding: 12px 18px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); z-index: 100;
}
.toast.error { background: var(--danger); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center;
  justify-content: center; z-index: 50; padding: 20px;
}
.modal-box {
  background: #fff; border-radius: var(--radius); padding: 24px; max-width: 420px; width: 100%;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.progress-bar { height: 7px; border-radius: 4px; background: var(--bg); overflow: hidden; }
.progress-bar > div { height: 100%; }

.cart-line { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.cart-total { display: flex; justify-content: space-between; font-weight: 700; padding-top: 10px; font-size: 15px; }

.empty-state { text-align: center; color: var(--text-muted); padding: 30px 10px; font-size: 13px; }

/* ---------- Reçu de caisse ---------- */
.recu { font-size: 13px; }
.recu-header { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.recu-header img { height: 40px; border-radius: 6px; }
.recu-sous { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.recu-ligne { display: flex; justify-content: space-between; padding: 3px 0; }
.recu-table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 12px; }
.recu-table th, .recu-table td { padding: 4px 2px; border-bottom: 1px dashed var(--border); text-align: left; }
.recu-table th.num, .recu-table td.num { text-align: right; }
.recu-total { font-weight: 700; font-size: 16px; color: var(--gps-green-dark); }
.recu-merci { text-align: center; color: var(--text-muted); font-size: 11px; margin-top: 14px; }

/* ---------- Décoration subtile ---------- */
.card { position: relative; overflow: hidden; }
.card::before {
  content: ''; position: absolute; top: 0; left: 0; width: 4px; height: 100%;
  background: linear-gradient(180deg, var(--gps-green) 0%, var(--gps-orange) 100%);
  opacity: 0.5;
}
.card h2 { padding-left: 2px; }

main {
  background-image: radial-gradient(circle at top right, rgba(48,138,38,0.05), transparent 45%),
                     radial-gradient(circle at bottom left, rgba(255,124,16,0.05), transparent 45%);
}

@media print {
  .app-header, .tabs, .no-print { display: none !important; }
  main { max-width: none; padding: 0; background: none; }
}

body.impression-recu > *:not(.modal-overlay) { display: none !important; }
body.impression-recu .modal-overlay { position: static; background: none; padding: 0; display: block; }
body.impression-recu .modal-box { box-shadow: none; max-width: none; }
body.impression-recu .no-print { display: none !important; }

/* ---------- Avatar / photo de profil ---------- */
.avatar-badge {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  background-color: var(--gps-orange); background-size: cover; background-position: center;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 13px; cursor: pointer;
  border: 2px solid rgba(255,255,255,0.5);
}

/* ---------- Messagerie : mail + chat ---------- */
.messagerie-split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .messagerie-split { grid-template-columns: 1fr; } }

.checklist-comptes { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 8px; }
.checklist-comptes label { display: flex; align-items: center; gap: 8px; padding: 5px 4px; font-weight: 400; cursor: pointer; }
.checklist-comptes label:hover { background: var(--bg); border-radius: 6px; }
.checklist-comptes input[type="checkbox"] { width: auto; }
.chip-liste { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; min-height: 22px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--bg); border: 1px solid var(--border); border-radius: 20px; padding: 3px 6px 3px 10px; font-size: 12px; }
.chip button { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 0 4px; font-size: 13px; }
.chip button:hover { color: var(--danger); background: none; }

.conv-item { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: var(--success-bg); border-color: var(--gps-green); }
.conv-item .conv-info { flex: 1; min-width: 0; }
.conv-item .conv-nom { font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .conv-apercu { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-bulle { max-width: 78%; padding: 8px 12px; border-radius: 12px; margin-bottom: 8px; font-size: 13px; }
.chat-bulle.moi { background: var(--gps-green); color: #fff; margin-left: auto; border-bottom-right-radius: 2px; }
.chat-bulle.autre { background: var(--bg); border: 1px solid var(--border); margin-right: auto; border-bottom-left-radius: 2px; }
.chat-bulle .chat-auteur { font-size: 11px; font-weight: 700; margin-bottom: 2px; opacity: 0.8; }
.chat-bulle .chat-heure { font-size: 10px; opacity: 0.7; margin-top: 4px; text-align: right; }
.lien-supprimer-chat {
  background: none; border: none; padding: 0; margin: 0; font-size: 10px; font-weight: 700;
  text-decoration: underline; cursor: pointer; color: inherit; opacity: 0.9;
}

/* ---------- Kanban Gestion de Projet ---------- */
.kanban-board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 10px; overflow-x: auto; }
@media (max-width: 900px) { .kanban-board { grid-template-columns: 1fr; } }
.kanban-colonne { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px; min-width: 200px; }
.kanban-colonne h4 { margin: 0 0 8px 0; font-size: 13px; }
.kanban-cartes { display: flex; flex-direction: column; gap: 8px; min-height: 40px; }
.kanban-carte { background: var(--card-bg, #fff); border: 1px solid var(--border); border-radius: 6px; padding: 8px; font-size: 12px; }

/* ---------- Gantt Gestion de Projet ---------- */
.gantt-chart { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.gantt-row { display: grid; grid-template-columns: 160px 1fr; align-items: center; gap: 8px; font-size: 12px; }
.gantt-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gantt-track { position: relative; height: 16px; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; }
.gantt-bar { position: absolute; top: 1px; bottom: 1px; border-radius: 3px; background: var(--gps-orange); }
.gantt-bar.gantt-termine { background: var(--gps-green); }
.gantt-bar.gantt-en_cours { background: var(--gps-orange); }
.gantt-bar.gantt-en_revue { background: #b98a2e; }
.gantt-bar.gantt-a_faire { background: var(--text-muted); }

/* ---------- Organigramme RH ---------- */
.org-arbre { display: flex; flex-wrap: wrap; gap: 24px; padding: 8px 0; overflow-x: auto; }
.org-noeud { display: flex; flex-direction: column; align-items: center; }
.org-carte { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 14px; text-align: center; white-space: nowrap; }
.org-enfants { display: flex; gap: 18px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); position: relative; }
.org-enfants .org-noeud { position: relative; }
