:root {
  --bg: #f0f4ff;
  --surface: #ffffff;
  --surface2: #f5f7ff;
  --border: #dde3f5;
  --accent: #4f46e5;
  --accent-light: #ede9fe;
  --accent-hover: #4338ca;
  --text: #1e1b4b;
  --muted: #7c7fab;
  --rdv: #0ea5e9;
  --accepted: #16a34a;
  --abandoned: #dc2626;
  --rdv-bg: #e0f2fe;
  --accepted-bg: #dcfce7;
  --abandoned-bg: #fee2e2;
  --rdv-border: #7dd3fc;
  --accepted-border: #86efac;
  --abandoned-border: #fca5a5;
  --pending: #d97706;
  --pending-bg: #fef3c7;
  --pending-border: #fcd34d;
  --shadow: 0 1px 3px rgba(79,70,229,0.08), 0 4px 16px rgba(79,70,229,0.06);
  --shadow-lg: 0 8px 32px rgba(79,70,229,0.16);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Playfair Display', Georgia, serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

/* HEADER */
header {
  padding: 18px 32px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.logo {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.5px;
  color: var(--accent);
}
.logo span { 
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.header-badge {
  background: var(--accent-light);
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid #c4b5fd;
}
.header-actions { display: flex; gap: 12px; align-items: center; }

/* STATS BAR */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  padding: 20px 32px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.stat {
  background: var(--surface);
  padding: 18px 22px;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: transform 0.15s;
}
.stat:hover { transform: translateY(-2px); }
.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  font-weight: 500;
}
.stat-value {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
}
.stat.total { border-top: 3px solid var(--accent); }
.stat.stat-rdv { border-top: 3px solid var(--rdv); }
.stat.stat-accepted { border-top: 3px solid var(--accepted); }
.stat.stat-abandoned { border-top: 3px solid var(--abandoned); }
.stat.stat-pending   { border-top: 3px solid var(--pending); }
.stat-value.rdv { color: var(--rdv); }
.stat-value.accepted { color: var(--accepted); }
.stat-value.abandoned { color: var(--abandoned); }
.stat-value.pending { color: var(--pending); }
.stat-value.total { color: var(--accent); }

/* TOOLBAR */
.toolbar {
  padding: 14px 32px;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.month-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}
.btn-icon {
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--accent);
  border-radius: 8px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  transition: all 0.15s;
}
.btn-icon:hover { background: var(--accent-light); border-color: #c4b5fd; }

.filter-group { display: flex; gap: 6px; margin-left: auto; }
.filter-btn {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  cursor: pointer;
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s;
}
.filter-btn:hover { color: var(--text); border-color: var(--muted); background: white; }
.filter-btn.active { color: white; border-color: transparent; background: var(--accent); }
.filter-btn.rdv.active { background: var(--rdv); border-color: var(--rdv); }
.filter-btn.accepted.active { background: var(--accepted); border-color: var(--accepted); }
.filter-btn.pending.active { background: var(--pending); border-color: var(--pending); }

.btn-add {
  padding: 9px 20px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: white;
  border: none;
  border-radius: 10px;
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  letter-spacing: 0.3px;
  transition: all 0.15s;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(79,70,229,0.3);
}
.btn-add:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(79,70,229,0.4); }

.search-box {
  padding: 8px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 13px;
  width: 200px;
  outline: none;
  transition: all 0.15s;
}
.search-box:focus { border-color: var(--accent); background: white; box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
.search-box::placeholder { color: var(--muted); }

/* TABLE */
.table-container {
  padding: 24px 32px;
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}
th {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 14px 18px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  background: #f8f9ff;
  white-space: nowrap;
}
td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  background: white;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbff; }

.client-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}
.client-id {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  font-weight: 400;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge-rdv { background: var(--rdv-bg); color: var(--rdv); border-color: var(--rdv-border); }
.badge-accepted { background: var(--accepted-bg); color: var(--accepted); border-color: var(--accepted-border); }
.badge-abandoned { background: var(--abandoned-bg); color: var(--abandoned); border-color: var(--abandoned-border); }
.badge-pending   { background: var(--pending-bg);   color: var(--pending);   border-color: var(--pending-border); }

.device-tag {
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-light);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid #c4b5fd;
  font-weight: 500;
}

.date-cell { font-size: 13px; color: var(--muted); white-space: nowrap; font-weight: 500; }

.action-btns { display: flex; gap: 6px; justify-content: flex-end; }
.btn-edit, .btn-delete {
  width: 30px; height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  transition: all 0.15s;
  color: var(--muted);
}
.btn-edit:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.btn-delete:hover { border-color: var(--abandoned); color: var(--abandoned); background: var(--abandoned-bg); }

/* EMPTY STATE */
.empty-state {
  text-align: center;
  padding: 64px 32px;
  color: var(--muted);
  background: white;
  border-radius: 16px;
  border: 1px dashed var(--border);
  margin-top: 0;
}
.empty-icon { font-size: 44px; margin-bottom: 12px; }
.empty-text { font-family: 'Playfair Display', Georgia, serif; font-size: 18px; font-weight: 700; margin-bottom: 6px; color: var(--text); }

/* MODAL */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(30,27,75,0.4);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
}
.modal-overlay.open { display: flex; }
.modal {
  background: white;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px;
  width: 490px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 24px;
  color: var(--text);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 11px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
input, select {
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 14px;
  outline: none;
  transition: all 0.15s;
  width: 100%;
}
input:focus, select:focus { border-color: var(--accent); background: white; box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
textarea {
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 13px;
  outline: none;
  transition: all 0.15s;
  width: 100%;
  resize: vertical;
  min-height: 80px;
  line-height: 1.6;
}
textarea:focus { border-color: var(--accent); background: white; box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
textarea::placeholder { color: var(--muted); }
select option { background: white; color: var(--text); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}
.btn-cancel {
  padding: 10px 20px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-cancel:hover { background: var(--border); }
.btn-save {
  padding: 10px 24px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: white;
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 0 2px 8px rgba(79,70,229,0.3);
}
.btn-save:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(79,70,229,0.4); }

/* SORTABLE HEADERS */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--accent); }
th.sortable .sort-icon { margin-left: 4px; opacity: 0.3; }
th.sortable.asc .sort-icon::after { content: '↑'; opacity: 1; color: var(--accent); }
th.sortable.desc .sort-icon::after { content: '↓'; opacity: 1; color: var(--accent); }
th.sortable:not(.asc):not(.desc) .sort-icon::after { content: '↕'; }

/* ===================== LOGIN SCREEN ===================== */
#loginScreen {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #a855f7 100%);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#loginScreen.hidden { display: none; }

.login-bg-circles {
  position: absolute; inset: 0; overflow: hidden; pointer-events: none;
}
.login-bg-circles span {
  position: absolute; border-radius: 50%;
  background: rgba(255,255,255,0.06);
}
.login-bg-circles span:nth-child(1) { width:400px; height:400px; top:-100px; left:-100px; }
.login-bg-circles span:nth-child(2) { width:300px; height:300px; bottom:-80px; right:-60px; }
.login-bg-circles span:nth-child(3) { width:180px; height:180px; top:40%; left:60%; }

.login-card {
  background: white;
  border-radius: 24px;
  padding: 44px 40px 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 64px rgba(79,70,229,0.35);
  position: relative;
  animation: fadeInDown 0.4s ease;
}
.login-logo {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 800;
  font-size: 26px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 6px;
}
.login-subtitle {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 32px;
}
.login-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface2);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 28px;
  border: 1px solid var(--border);
}
.login-tab {
  padding: 9px;
  text-align: center;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  transition: all 0.2s;
  border: none;
  background: transparent;
  font-family: 'Playfair Display', Georgia, serif;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.login-tab.active {
  background: white;
  color: var(--accent);
  box-shadow: 0 1px 6px rgba(79,70,229,0.15);
}

.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-form label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 2px; }
.login-form .field { display: flex; flex-direction: column; gap: 5px; }
.login-form input {
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: 'Playfair Display', Georgia, serif;
  color: var(--text);
  background: var(--surface2);
  outline: none;
  transition: all 0.15s;
  width: 100%;
}
.login-form input:focus { border-color: var(--accent); background: white; box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
.login-error {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #dc2626;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  display: none;
}
.login-error.show { display: block; animation: fadeInDown 0.2s ease; }
.btn-login {
  padding: 13px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: white;
  border: none;
  border-radius: 12px;
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 16px rgba(79,70,229,0.35);
  margin-top: 4px;
}
.btn-login:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(79,70,229,0.45); }
.btn-login:active { transform: translateY(0); }

.visitor-info {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
}
.visitor-info strong { color: var(--text); }

/* ===================== ROLE BADGE ===================== */
.role-badge {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  border: 1.5px solid;
}
.role-badge.admin {
  background: #ede9fe; color: #4f46e5; border-color: #c4b5fd;
}
.role-badge.visitor {
  background: #f0fdf4; color: #16a34a; border-color: #86efac;
}
.role-badge .dot {
  width: 7px; height: 7px; border-radius: 50%; background: currentColor;
  animation: blink 2s infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.3} }

.btn-logout {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  display: flex; align-items: center; gap: 5px;
}
.btn-logout:hover { border-color: var(--abandoned); color: var(--abandoned); background: var(--abandoned-bg); }

/* ===================== VISITOR RESTRICTIONS ===================== */
.visitor-banner {
  background: linear-gradient(90deg, #f0fdf4, #dcfce7);
  border-bottom: 1px solid #86efac;
  padding: 10px 32px;
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: #15803d; font-weight: 500;
}
.visitor-banner.hidden { display: none; }

/* Disabled admin controls in visitor mode */
body.visitor-mode .admin-only { 
  opacity: 0.3; 
  pointer-events: none; 
  cursor: not-allowed;
  filter: grayscale(1);
}
body.visitor-mode .action-btns { opacity: 0.2; pointer-events: none; }

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeOutLeft {
  from { opacity: 1; transform: translateX(0); max-height: 80px; }
  to   { opacity: 0; transform: translateX(-20px); max-height: 0; padding: 0; }
}
@keyframes rowIn {
  from { opacity: 0; transform: translateX(-16px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes pulse-once {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(60px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(60px); }
}

tr.row-enter td { animation: rowIn 0.3s ease forwards; }
tr.row-exit { animation: fadeOutLeft 0.3s ease forwards; pointer-events: none; }

.stat-value { transition: color 0.3s; }
.stat-value.bump { animation: pulse-once 0.4s ease; }

/* TOAST */
#toast-container {
  position: fixed;
  bottom: 28px; right: 28px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toast-in 0.3s ease;
  min-width: 220px;
}
.toast.hide { animation: toast-out 0.3s ease forwards; }
.toast.success { border-left: 4px solid var(--accepted); }
.toast.info    { border-left: 4px solid var(--accent); }
.toast.error   { border-left: 4px solid var(--abandoned); }

/* EXPORT BUTTONS */
.export-group { display: flex; gap: 8px; }
.btn-export {
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-export:hover { background: white; box-shadow: var(--shadow); transform: translateY(-1px); }
.btn-export.excel:hover { border-color: #16a34a; color: #16a34a; }
.btn-export.pdf:hover   { border-color: #dc2626; color: #dc2626; }
.btn-export .icon { font-size: 14px; }

/* MODAL ANIMATION */
.modal-overlay.open .modal {
  animation: fadeInDown 0.25s ease;
}

@media (max-width: 700px) {
  .stats-bar { grid-template-columns: repeat(3, 1fr); padding: 12px 16px; }
  .toolbar { padding: 12px 16px; }
  .table-container { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  header { padding: 14px 16px; }
  .export-group { flex-wrap: wrap; }
}
