:root {
  --primary: #1a3a5c;
  --primary-light: #2563a8;
  --accent: #f97316;
  --bg: #f0f4f8;
  --surface: #ffffff;
  --surface-alt: #dbeafe;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #cbd5e1;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 12px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,0.10);
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── LOGIN SCREEN ── */
#screen-login {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: linear-gradient(135deg, #1a3a5c 0%, #2563a8 100%);
}

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

.login-logo h1 {
  font-size: 2rem;
  font-weight: 800;
  color: white;
  letter-spacing: -0.5px;
}

.login-logo p {
  color: rgba(255,255,255,0.7);
  margin-top: 0.4rem;
  font-size: 0.95rem;
}

.login-card {
  background: white;
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
}

.login-step-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.login-card h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 1.5rem;
}

.store-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.store-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 1.5rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  transition: all 0.18s;
  text-align: center;
}

.store-btn:hover, .store-btn.selected {
  border-color: var(--primary-light);
  background: #eff6ff;
}

.store-btn.selected {
  border-color: var(--primary);
  background: #dbeafe;
}

.store-btn .store-icon {
  font-size: 2rem;
}

.store-btn .store-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--primary);
}

.user-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.user-btn {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1.1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
  transition: all 0.18s;
  width: 100%;
  text-align: left;
}

.user-btn:hover {
  border-color: var(--primary-light);
  background: #eff6ff;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: white;
  flex-shrink: 0;
}

.role-admin .user-avatar { background: var(--primary); }
.role-manager .user-avatar { background: var(--primary-light); }
.role-vendeur .user-avatar { background: var(--text-muted); }

.user-info .user-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

.user-info .user-role {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.role-badge {
  margin-left: auto;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
}

.role-admin .role-badge { background: #dbeafe; color: var(--primary); }
.role-manager .role-badge { background: #dcfce7; color: var(--success); }
.role-vendeur .role-badge { background: #f1f5f9; color: var(--text-muted); }

.btn-back {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.88rem;
  cursor: pointer;
  padding: 0.5rem 0;
  margin-bottom: 1.25rem;
  transition: color 0.15s;
}

.btn-back:hover { color: var(--primary); }

/* ── APP SHELL ── */
#screen-app { display: none; }

.app-header {
  background: var(--primary);
  color: white;
  padding: 0 1.5rem;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-logo {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.header-store {
  font-size: 0.8rem;
  background: rgba(255,255,255,0.15);
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: rgba(255,255,255,0.85);
}

.header-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
}

.btn-logout {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: white;
  padding: 0.3rem 0.8rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-logout:hover { background: rgba(255,255,255,0.2); }

/* ── NAV TABS ── */
.app-nav {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  gap: 0.25rem;
}

.nav-tab {
  padding: 0.85rem 1.2rem;
  border: none;
  background: none;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.15s;
}

.nav-tab:hover { color: var(--primary); }

.nav-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.nav-tab.hidden { display: none; }

/* ── MAIN CONTENT ── */
.app-content {
  padding: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
}

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

/* ── CARDS ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ── DASHBOARD ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: white;
  border-radius: var(--radius);
  padding: 1.25rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  text-align: center;
}

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

.kpi-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
  font-weight: 500;
}

.kpi-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* ── TABLE ── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead th {
  background: var(--primary);
  color: white;
  padding: 0.7rem 0.8rem;
  text-align: center;
  font-weight: 600;
  font-size: 0.78rem;
  white-space: nowrap;
}

thead th:first-child { text-align: left; }

tbody tr:nth-child(even) { background: var(--surface-alt); }
tbody tr:nth-child(odd) { background: white; }

tbody td {
  padding: 0.65rem 0.8rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td:first-child { text-align: left; font-weight: 600; }

.badge-ok {
  background: #dcfce7;
  color: var(--success);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge-warn {
  background: #fef3c7;
  color: var(--warning);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge-danger {
  background: #fee2e2;
  color: var(--danger);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

/* ── SAISIE FORM ── */
.form-section {
  margin-bottom: 1.75rem;
}

.form-section-title {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-field input {
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  background: white;
  color: var(--text);
  transition: border-color 0.15s;
  width: 100%;
}

.form-field input:focus {
  outline: none;
  border-color: var(--primary-light);
}

.form-field input[readonly] {
  background: var(--bg);
  color: var(--text-muted);
  cursor: default;
}

.form-field.computed input {
  background: #eff6ff;
  color: var(--primary);
  font-weight: 700;
}

.form-actions {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.btn {
  padding: 0.65rem 1.4rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover { background: var(--primary-light); }

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1.5px solid var(--border);
}

.btn-secondary:hover { background: var(--border); }

.btn-danger {
  background: #fee2e2;
  color: var(--danger);
  border: 1.5px solid #fca5a5;
}

.btn-danger:hover { background: #fca5a5; }

/* ── MONTH SELECTOR ── */
.month-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.month-bar label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.month-bar input[type="month"] {
  padding: 0.45rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--text);
  background: white;
}

.month-bar input[type="month"]:focus {
  outline: none;
  border-color: var(--primary-light);
}

/* ── PROGRESS BARS ── */
.progress-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.progress-item {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
}

.progress-label { font-weight: 600; color: var(--text); }
.progress-pct { font-weight: 700; }

.progress-bar-bg {
  height: 10px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}

.fill-blue { background: var(--primary-light); }
.fill-green { background: var(--success); }
.fill-orange { background: var(--accent); }
.fill-yellow { background: var(--warning); }

/* ── SCORE BADGE ── */
.score-big {
  font-size: 3.5rem;
  font-weight: 900;
  line-height: 1;
}

.score-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

/* ── ADMIN PARAMS ── */
.params-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.param-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.param-field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.param-field input {
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  background: white;
  color: var(--text);
  transition: border-color 0.15s;
}

.param-field input:focus {
  outline: none;
  border-color: var(--primary-light);
}

/* ── VENDEUR VIEW ── */
.vendeur-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  border-radius: var(--radius);
  padding: 2rem;
  color: white;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 2rem;
  flex-wrap: wrap;
}

.vendeur-score-circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: 4px solid rgba(255,255,255,0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.vendeur-score-circle .pct {
  font-size: 1.6rem;
  font-weight: 900;
  line-height: 1;
}

.vendeur-score-circle .label {
  font-size: 0.65rem;
  opacity: 0.8;
  margin-top: 2px;
}

.vendeur-info h2 { font-size: 1.5rem; font-weight: 800; }
.vendeur-info p { opacity: 0.8; font-size: 0.9rem; margin-top: 0.3rem; }
.vendeur-prime {
  margin-left: auto;
  text-align: right;
}
.vendeur-prime .amount {
  font-size: 2.2rem;
  font-weight: 900;
  line-height: 1;
}
.vendeur-prime .label {
  font-size: 0.8rem;
  opacity: 0.75;
  margin-top: 0.2rem;
}

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}

.empty-state .icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state p { font-size: 0.95rem; }

/* ── ALERT ── */
.alert {
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.alert-success { background: #dcfce7; color: var(--success); border: 1px solid #86efac; }
.alert-danger { background: #fee2e2; color: var(--danger); border: 1px solid #fca5a5; }
.alert-info { background: #dbeafe; color: var(--primary); border: 1px solid #93c5fd; }

/* ── TOOLBAR ── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.toolbar-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.toolbar select,
.toolbar input[type="date"] {
  padding: 0.45rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--text);
  background: white;
  cursor: pointer;
}

.toolbar select:focus,
.toolbar input[type="date"]:focus {
  outline: none;
  border-color: var(--primary-light);
}

/* ── KPI OBJ ── */
.kpi-obj {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-muted);
}

/* ── OBJECTIFS VS REALISE ── */
.obj-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1.25rem;
}

.obj-item {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.obj-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.obj-values {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.obj-reel {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1;
}

.obj-sep {
  color: var(--border);
  font-size: 1.1rem;
}

.obj-target {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.obj-pct {
  font-size: 0.78rem;
  font-weight: 700;
  margin-top: 0.1rem;
}

/* ── PREVIEW BAR ── */
.preview-bar {
  display: flex;
  gap: 0;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin: 1.25rem 0;
  flex-wrap: wrap;
}

.preview-item {
  flex: 1;
  min-width: 100px;
  padding: 0.85rem 0.75rem;
  text-align: center;
  border-right: 1px solid var(--border);
}

.preview-item:last-child { border-right: none; }

.preview-val {
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1;
  color: var(--primary);
}

.preview-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  font-weight: 500;
}

/* ── ROLE BADGE INLINE ── */
.role-badge-inline {
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.role-admin .role-badge-inline,
.role-badge-inline.role-admin   { background: #dbeafe; color: var(--primary); }
.role-manager .role-badge-inline,
.role-badge-inline.role-manager { background: #dcfce7; color: var(--success); }
.role-vendeur .role-badge-inline,
.role-badge-inline.role-vendeur { background: #f1f5f9; color: var(--text-muted); }

/* ── BTN ICON ── */
.btn-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.btn-icon:hover { background: var(--border); }

.btn-icon-danger {
  border-color: #fca5a5;
  background: #fee2e2;
}

.btn-icon-danger:hover { background: #fca5a5; }

/* ── BTN DANGER SMALL ── */
.btn-danger-sm {
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  background: #fee2e2;
  color: var(--danger);
  border: 1.5px solid #fca5a5;
  transition: all 0.15s;
}

.btn-danger-sm:hover { background: #fca5a5; }

/* ── MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-box {
  background: white;
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow);
}

.modal-box h3 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--danger);
  margin-bottom: 0.75rem;
}

.modal-box p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

/* ── PARAMS GRID ── */
.params-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.param-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.param-field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.param-field input {
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  background: white;
  color: var(--text);
  transition: border-color 0.15s;
}

.param-field input:focus {
  outline: none;
  border-color: var(--primary-light);
}

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .store-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .vendeur-header { flex-direction: column; text-align: center; }
  .vendeur-prime { margin-left: 0; text-align: center; }
  .app-content { padding: 1rem; }
  #page-saisie > div > div:first-child { grid-template-columns: 1fr !important; }
  #page-mon-bilan > div > div:last-child { grid-template-columns: 1fr !important; }
}
