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

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface2: #f0f2f5;
  --border: #e2e8f0;
  --text: #1a202c;
  --text-muted: #718096;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --radius: 10px;
  --radius-sm: 6px;
  --transition: .2s ease;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #252836;
  --border: #2d3748;
  --text: #f7fafc;
  --text-muted: #a0aec0;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --shadow-md: 0 4px 6px rgba(0,0,0,.3);
}

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  transition: background var(--transition), color var(--transition);
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ========== LOGIN ========== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.login-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-logo h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.5px;
}

.login-logo p { color: var(--text-muted); font-size: .9rem; margin-top: .25rem; }

/* ========== FORMS ========== */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: .35rem; font-size: .875rem; }

.form-control {
  width: 100%;
  padding: .6rem .875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: .875rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

select.form-control { cursor: pointer; }

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.1rem;
  border-radius: var(--radius-sm);
  border: none;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: var(--success); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-icon { padding: .5rem; border-radius: 50%; background: transparent; border: none; cursor: pointer; color: var(--text-muted); transition: all var(--transition); }
.btn-icon:hover { background: var(--surface2); color: var(--text); }
.btn-sm { padding: .35rem .75rem; font-size: .8rem; }
.btn-full { width: 100%; justify-content: center; padding: .75rem; }

/* ========== APP LAYOUT ========== */
.app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 1rem;
}

.topbar-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -.3px;
  white-space: nowrap;
}

.topbar-nav {
  display: flex;
  gap: .25rem;
  overflow-x: auto;
  flex: 1;
  justify-content: center;
}

.topbar-nav::-webkit-scrollbar { height: 0; }

.nav-tab {
  padding: .45rem .9rem;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.nav-tab:hover { background: var(--surface2); color: var(--text); }
.nav-tab.active { background: var(--primary); color: #fff; }

.topbar-actions { display: flex; align-items: center; gap: .5rem; }

.user-badge {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .35rem .75rem;
  border-radius: 99px;
  background: var(--surface2);
  font-size: .8rem;
  font-weight: 500;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
}

/* ========== MAIN CONTENT ========== */
.main-content { flex: 1; padding: 1.25rem; max-width: 1400px; margin: 0 auto; width: 100%; }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ========== CARDS ========== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.card-header h2 { font-size: 1rem; font-weight: 600; }
.card-body { padding: 1.25rem; }

/* ========== CALENDRIER ========== */
.calendar-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 900px) {
  .calendar-container { grid-template-columns: 340px 1fr; }
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.calendar-header h3 { font-size: 1rem; font-weight: 600; text-transform: capitalize; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
}

.cal-day-name {
  background: var(--surface2);
  text-align: center;
  padding: .5rem;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.cal-day {
  background: var(--surface);
  min-height: 56px;
  padding: .35rem .5rem;
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
}

.cal-day:hover { background: var(--surface2); }
.cal-day.other-month { opacity: .35; }
.cal-day.today { background: rgba(59,130,246,.08); }
.cal-day.selected { background: rgba(59,130,246,.15); outline: 2px solid var(--primary); outline-offset: -2px; }

.cal-day-num {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text);
}

.cal-day.today .cal-day-num {
  background: var(--primary);
  color: #fff;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cal-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-top: 3px;
}

.cal-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.dot-chantier { background: var(--primary); }
.dot-conge { background: var(--text-muted); }
.dot-eta { background: #a855f7; }
.dot-transport { background: var(--warning); }
.dot-note { background: var(--danger); }

/* ========== DETAIL PANEL ========== */
.detail-panel { display: flex; flex-direction: column; gap: .75rem; }

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .5rem;
}

.detail-date { font-size: 1rem; font-weight: 700; text-transform: capitalize; }

.chantier-card {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: .75rem 1rem;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.chantier-card:hover { border-color: var(--primary); transform: translateX(2px); }
.chantier-card h4 { font-size: .9rem; font-weight: 600; margin-bottom: .25rem; }
.chantier-card .meta { display: flex; gap: 1rem; font-size: .78rem; color: var(--text-muted); flex-wrap: wrap; }

.chantier-card .badge {
  position: absolute;
  top: .5rem;
  right: .5rem;
  padding: .15rem .5rem;
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 600;
}

.badge-blue { background: rgba(59,130,246,.15); color: var(--primary); }
.badge-purple { background: rgba(168,85,247,.15); color: #9333ea; }
.badge-yellow { background: rgba(245,158,11,.15); color: #d97706; }
.badge-green { background: rgba(34,197,94,.15); color: #16a34a; }
.badge-gray { background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); }

/* ========== SALARIES LIST ========== */
.salarie-chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .25rem .65rem;
  border-radius: 99px;
  font-size: .78rem;
  font-weight: 500;
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}

.salarie-chip.libre { border-color: var(--success); }
.salarie-chip.libre:hover { background: rgba(34,197,94,.1); }
.salarie-chip.occupe { border-color: var(--warning); background: rgba(245,158,11,.08); }
.salarie-chip.conge { border-color: var(--text-muted); background: var(--surface2); opacity: .6; cursor: not-allowed; }
.salarie-chip.selected { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ========== MODAL ========== */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(2px);
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px rgba(0,0,0,.25);
  animation: slideUp .2s ease;
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.modal-header h3 { font-size: 1.05rem; font-weight: 700; }
.modal-body { padding: 1.5rem; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; gap: .75rem; justify-content: flex-end; }

/* ========== CONTEXT MENU ========== */
.context-menu {
  display: none;
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 300;
  min-width: 160px;
  overflow: hidden;
}

.context-menu.open { display: block; }
.context-menu-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .6rem 1rem;
  cursor: pointer;
  font-size: .875rem;
  transition: background var(--transition);
}

.context-menu-item:hover { background: var(--surface2); }
.context-menu-item.danger { color: var(--danger); }

/* ========== TABLE ========== */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead tr { background: var(--surface2); }
th, td { padding: .65rem 1rem; text-align: left; font-size: .875rem; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--text-muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .4px; }
tbody tr:hover { background: var(--surface2); }

/* ========== SUIVI / SEARCH ========== */
.search-bar {
  display: flex;
  gap: .75rem;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.search-bar .form-control { max-width: 300px; }

/* ========== NOTIFICATION BELL ========== */
.notif-wrapper { position: relative; }
.notif-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--danger);
  color: #fff;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  font-size: .65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  display: none;
}

.notif-badge.visible { display: flex; }

/* ========== TOAST ========== */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  z-index: 9999;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .875rem 1.1rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  font-size: .875rem;
  min-width: 280px;
  max-width: 380px;
  animation: slideInRight .25s ease;
}

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

.toast-icon { font-size: 1.1rem; }
.toast-content { flex: 1; }
.toast-title { font-weight: 600; margin-bottom: .15rem; }
.toast-msg { color: var(--text-muted); font-size: .82rem; }

/* ========== TABS SECONDAIRES ========== */
.sub-tabs { display: flex; gap: .35rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--border); padding-bottom: .25rem; }
.sub-tab { padding: .5rem 1rem; border: none; background: transparent; cursor: pointer; font-size: .875rem; font-weight: 500; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; transition: all var(--transition); }
.sub-tab:hover { color: var(--text); }
.sub-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ========== NOTES ========== */
.note-item {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  border-left: 3px solid var(--primary);
  margin-bottom: .5rem;
}

.note-item.unread { border-left-color: var(--danger); }
.note-meta { display: flex; gap: .75rem; font-size: .75rem; color: var(--text-muted); margin-bottom: .35rem; }
.note-text { font-size: .875rem; }

/* ========== BOTTOM NAV (mobile) ========== */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(0,0,0,.08);
  z-index: 100;
  padding: 0 .25rem;
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-inner {
  display: flex;
  align-items: stretch;
  height: 100%;
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: .35rem .25rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  color: var(--text-muted);
  font-size: .65rem;
  font-weight: 500;
  min-width: 0;
}

.bottom-nav-item .bnav-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.bottom-nav-item .bnav-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.bottom-nav-item.active {
  color: var(--primary);
}

.bottom-nav-item.active .bnav-icon {
  transform: translateY(-1px);
}

/* ========== RESPONSIVE ========== */
@media (max-width: 640px) {
  .topbar { padding: 0 .75rem; }
  .topbar-brand { font-size: .95rem; }
  /* Masquer la nav horizontale — remplacée par la bottom nav */
  .topbar-nav { display: none; }
  /* Afficher la bottom nav */
  .bottom-nav { display: block; }
  /* Décaler le contenu pour ne pas être masqué par la bottom nav */
  .main-content { padding: .75rem .75rem calc(.75rem + 60px + env(safe-area-inset-bottom)); }
  /* Décaler les toasts au-dessus de la bottom nav */
  .toast-container { bottom: calc(70px + env(safe-area-inset-bottom)); right: .75rem; }
  .toast { min-width: 0; max-width: calc(100vw - 1.5rem); }
  /* Modals en bas de l'écran */
  .modal { max-width: 100%; border-radius: var(--radius) var(--radius) 0 0; }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  /* Grille calendrier compacte */
  .cal-day { min-height: 44px; padding: .25rem .3rem; }
  .cal-day-name { padding: .35rem; font-size: .7rem; }
}

/* ========== EMPTY STATE ========== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  gap: .5rem;
}

.empty-state svg { opacity: .4; }
.empty-state p { font-size: .9rem; }

/* ========== CHIP SELECTED SALARIES ========== */
.selected-chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; min-height: 32px; }
.selected-chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem .6rem;
  border-radius: 99px;
  background: var(--primary);
  color: #fff;
  font-size: .78rem;
  font-weight: 500;
}

.selected-chip .remove { cursor: pointer; opacity: .7; }
.selected-chip .remove:hover { opacity: 1; }

/* ========== COPY MODAL CALENDAR ========== */
.copy-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.copy-cal-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-size: .8rem;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: all var(--transition);
}

.copy-cal-day:hover { background: var(--surface2); }
.copy-cal-day.selected-copy { background: var(--primary); color: #fff; border-color: var(--primary); }
.copy-cal-day.empty { cursor: default; }

/* ========== LOADING ========== */
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  margin: 1rem auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ========== DAY NOTIFICATION DOT ========== */
.day-notif {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--danger);
}
