:root {
  --blue: #2178B4;
  --blue-dark: #155C8A;
  --blue-light: #E8F4FD;
  --orange: #E05530;
  --orange-dark: #C03E1F;
  --dark: #1E1E1E;
  --navy: #16233A;
  --navy-light: #1F304D;
  --gray: #5A5A5A;
  --gray-light: #F4F6F8;
  --border: #E3E7EC;
  --white: #FFFFFF;
  --success: #1E9E5A;
  --success-bg: #E4F7EC;
  --danger: #D94A3D;
  --danger-bg: #FCE9E7;
  --warning: #C98A1A;
  --warning-bg: #FBF1DD;
  --info: var(--blue);
  --info-bg: var(--blue-light);
  --muted: #6B7280;
  --muted-bg: #EEF0F3;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 50, 0.06), 0 8px 24px rgba(20, 30, 50, 0.05);
  --sidebar-bg: #E7E9EC;
  --sidebar-text: #23262B;
  --sidebar-text-muted: rgba(35, 38, 43, .6);
  --sidebar-active: var(--orange);
  --sidebar-width: 250px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--gray-light);
  color: var(--dark);
  font-size: 15px;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 .35em; }
p { margin: 0 0 .75em; }
ul { margin: 0; padding: 0; list-style: none; }
img { max-width: 100%; }

.flash { padding: .85rem 1.1rem; border-radius: 10px; margin-bottom: 1.25rem; font-weight: 500; }
.flash-success { background: var(--success-bg); color: var(--success); }
.flash-error { background: var(--danger-bg); color: var(--danger); }

/* ===== Buttons / forms ===== */
.btn {
  display: inline-flex; align-items: center; gap: .4em;
  padding: .55rem 1.1rem; border-radius: 10px; border: 1px solid transparent;
  font-weight: 600; font-size: .92rem; cursor: pointer; background: var(--white);
  color: var(--dark); border-color: var(--border);
}
.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--orange); color: #fff; border-color: var(--orange); }
.btn-primary:hover { background: var(--orange-dark); }
.btn-secondary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-secondary:hover { background: var(--blue-dark); }
.btn-outline { background: transparent; border-color: var(--border); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.btn-sm { padding: .35rem .7rem; font-size: .82rem; border-radius: 8px; }
.btn-block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

label { display: block; font-size: .82rem; font-weight: 600; color: var(--gray); margin-bottom: .3rem; }
input, select, textarea {
  width: 100%; padding: .6rem .75rem; border: 1px solid var(--border); border-radius: 10px;
  font-size: .92rem; font-family: inherit; background: #fff; color: var(--dark);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-light); }
.field { margin-bottom: 1rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
@media (max-width: 720px) { .form-grid, .form-grid-3 { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: .6rem; margin-top: 1.2rem; }
fieldset { border: 1px solid var(--border); border-radius: 12px; padding: 1rem; margin: 0 0 1rem; }
legend { padding: 0 .4rem; font-weight: 700; color: var(--blue-dark); }

/* ===== Badges / status ===== */
.badge {
  display: inline-flex; align-items: center; gap: .35em; padding: .25rem .65rem;
  border-radius: 999px; font-size: .78rem; font-weight: 700;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.success { background: var(--success-bg); color: var(--success); }
.badge.info { background: var(--info-bg); color: var(--blue-dark); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.warning { background: var(--warning-bg); color: var(--warning); }
.badge.muted { background: var(--muted-bg); color: var(--muted); }

/* ===== Cards ===== */
.card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; margin-bottom: 1.25rem; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.card-header h2, .card-header h3 { margin: 0; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat-tile { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.3rem; display: flex; align-items: center; gap: .9rem; }
.stat-tile .num { font-size: 1.7rem; font-weight: 800; }
.stat-tile .lbl { color: var(--muted); font-size: .82rem; font-weight: 600; }
.stat-tile .icon { width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; }
.stat-tile.blue .icon { background: var(--blue-light); }
.stat-tile.orange .icon { background: #FCE7E0; }
.stat-tile.green .icon { background: var(--success-bg); }
.stat-tile.red .icon { background: var(--danger-bg); }

/* ===== Progress ===== */
.progress { height: 8px; background: var(--muted-bg); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--orange); border-radius: 999px; }

/* ===== Admin shell ===== */
/* Only .admin-content scrolls; the sidebar and topbar stay fixed in place. */
.admin-shell { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: var(--sidebar-width); flex: 0 0 var(--sidebar-width); height: 100vh; overflow-y: auto;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex; flex-direction: column; padding: 1.2rem 1rem;
  border-right: 1px solid rgba(35,38,43,.1);
}
.sidebar-brand { display: flex; flex-direction: column; align-items: center; text-align: center; gap: .45rem; padding: .4rem .4rem 1.2rem; border-bottom: 1px solid rgba(35,38,43,.1); margin-bottom: .8rem; }
.brand-badge { width: 38px; height: 38px; border-radius: 10px; background: var(--orange); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; flex: none; }
.brand-icon { width: 38px; height: 38px; flex: none; display: block; object-fit: contain; }
.brand-logo { height: 37px; width: auto; max-width: 100%; display: block; flex: none; }
.brand-title { font-weight: 800; font-size: 1rem; }
.brand-subtitle { font-size: .72rem; color: var(--sidebar-text-muted); }
.sidebar-nav { display: flex; flex-direction: column; gap: .15rem; flex: 1; overflow-y: auto; }
.sidebar-nav a { display: flex; align-items: center; gap: .7rem; padding: .65rem .7rem; border-radius: 10px; color: var(--sidebar-text); font-weight: 600; font-size: .88rem; }
.sidebar-nav a:hover { background: rgba(35,38,43,.07); }
.sidebar-nav a.active { background: var(--sidebar-active); color: #fff; }
.sidebar-nav .ic { width: 18px; text-align: center; }
.sidebar-sep { height: 1px; background: rgba(35,38,43,.12); margin: .6rem .2rem; }

.admin-main { flex: 1; min-width: 0; height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.topbar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.8rem; background: #fff; border-bottom: 1px solid var(--border); }
.topbar-left { display: flex; align-items: center; gap: .8rem; min-width: 0; }
.topbar-title { font-weight: 800; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 1rem; }
.topbar-clock { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.bell { font-size: 1.1rem; cursor: pointer; }
.topbar-user { display: flex; align-items: center; gap: .55rem; padding-left: .3rem; border-left: 1px solid var(--border); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--orange); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.avatar-sm { width: 30px; height: 30px; font-size: .85rem; }
.topbar-user-info { line-height: 1.25; }
.user-name { font-size: .82rem; font-weight: 700; }
.user-role { font-size: .7rem; color: var(--muted); }
.logout-btn { background: transparent; border: 1px solid var(--border); border-radius: 8px; width: 34px; height: 34px; color: var(--gray); font-size: 1rem; cursor: pointer; }
.logout-btn:hover { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.hamburger { display: none; flex-direction: column; justify-content: center; gap: 4px; width: 34px; height: 34px; background: transparent; border: none; cursor: pointer; padding: 0; flex: none; }
.hamburger span { display: block; height: 2px; width: 100%; background: var(--dark); border-radius: 2px; }
.sidebar-backdrop { display: none; }

.admin-content { padding: 1.8rem; flex: 1; overflow-y: auto; }

/* ===== Client shell ===== */
.client-shell { max-width: 560px; margin: 0 auto; min-height: 100vh; background: var(--gray-light); display: flex; flex-direction: column; }
.client-header { display: flex; align-items: center; gap: .7rem; padding: 1rem 1.2rem; background: var(--navy); color: #fff; }
.client-header .brand-title { color: #fff; }
.client-header .brand-subtitle { color: rgba(255,255,255,.65); }
.client-logout { margin-left: auto; }
.client-logout button { background: transparent; border: none; color: rgba(255,255,255,.7); font-size: 1.1rem; cursor: pointer; }
.client-content { flex: 1; padding: 1.1rem; padding-bottom: 5rem; }
.client-bottomnav { position: sticky; bottom: 0; display: flex; background: #fff; border-top: 1px solid var(--border); }
.client-bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .15rem; padding: .7rem 0; color: var(--muted); font-size: .72rem; font-weight: 700; }
.client-bottomnav a.active { color: var(--blue); }
.client-bottomnav .ic { font-size: 1.15rem; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: .7rem .6rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; font-weight: 700; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }

/* ===== Tabs (project detail) ===== */
.tabs { display: flex; gap: .4rem; overflow-x: auto; margin-bottom: 1.2rem; }
.tabs a { padding: .55rem 1rem; border-radius: 10px; font-weight: 700; font-size: .85rem; color: var(--gray); white-space: nowrap; background: #fff; border: 1px solid var(--border); }
.tabs a.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ===== Timeline (etapes) ===== */
.timeline { position: relative; }
.timeline-item { display: flex; gap: 1rem; padding-bottom: 1.4rem; position: relative; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before {
  content: ''; position: absolute; left: 15px; top: 34px; bottom: -6px; width: 2px; background: var(--border);
}
.timeline-item:last-child::before { display: none; }
.timeline-item.done::before { background: var(--success); }
.step-dot {
  width: 32px; height: 32px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .85rem; background: var(--muted-bg); color: var(--muted); border: 2px solid var(--border); z-index: 1;
}
.timeline-item.done .step-dot { background: var(--success-bg); color: var(--success); border-color: var(--success); }
.timeline-item.current .step-dot { background: var(--blue-light); color: var(--blue); border-color: var(--blue); }
.step-body { flex: 1; background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: .85rem 1rem; }
.step-body.done { opacity: .8; }
.step-title { font-weight: 700; }
.step-title.done { text-decoration: line-through; color: var(--muted); }
.step-desc { color: var(--muted); font-size: .85rem; margin-top: .2rem; }
.step-actions { display: flex; align-items: center; gap: .5rem; margin-top: .6rem; flex-wrap: wrap; }
.step-photos { display: flex; gap: .5rem; margin-top: .6rem; flex-wrap: wrap; }
.step-photos img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.file-chip { display: inline-flex; align-items: center; gap: .35em; height: 64px; padding: 0 .8rem; border-radius: 8px; border: 1px solid var(--border); background: var(--gray-light); font-size: .78rem; font-weight: 600; color: var(--blue-dark); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Photo capture ===== */
.photo-capture { border: 1.5px dashed var(--border); border-radius: 12px; padding: 1rem; text-align: center; }
.photo-capture video, .photo-capture canvas { width: 100%; border-radius: 10px; background: #000; }
.photo-capture-preview { max-width: 180px; border-radius: 10px; margin: .6rem auto; display: block; }
.capture-actions { display: flex; gap: .5rem; justify-content: center; margin-top: .6rem; flex-wrap: wrap; }

/* ===== Login ===== */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--navy) 0%, var(--blue-dark) 100%); padding: 1rem; }
.login-card { background: #fff; border-radius: 18px; padding: 2.4rem; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.25); text-align: center; }
.login-card .brand-badge { margin: 0 auto 1rem; width: 52px; height: 52px; font-size: 1.2rem; }
.login-logo { display: block; max-width: 240px; width: 80%; height: auto; margin: 0 auto 1.4rem; }
.login-card h1 { font-size: 1.3rem; margin-bottom: .2rem; }
.login-card .sub { color: var(--muted); font-size: .85rem; margin-bottom: 1.6rem; }
.login-error { background: var(--danger-bg); color: var(--danger); padding: .6rem .8rem; border-radius: 8px; font-size: .85rem; margin-bottom: 1rem; text-align: left; }
.login-hint { margin-top: 1.4rem; font-size: .76rem; color: var(--muted); text-align: left; background: var(--gray-light); border-radius: 10px; padding: .8rem; }
.login-hint b { color: var(--dark); }

/* ===== Misc ===== */
.muted-text { color: var(--muted); }
.project-cover { height: 90px; border-radius: 14px 14px 0 0; background: linear-gradient(120deg, var(--blue), var(--blue-dark)); display: flex; align-items: center; justify-content: center; font-size: 2rem; }
.project-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.project-card-body { padding: 1.1rem 1.2rem 1.3rem; }
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.2rem; }
.icon-pill { width: 20px; display: inline-block; text-align: center; }
.section-title { font-size: .82rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 1.4rem 0 .6rem; }
.chip-list { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip { background: var(--muted-bg); border-radius: 999px; padding: .3rem .7rem; font-size: .78rem; font-weight: 600; }
.perm-matrix td, .perm-matrix th { text-align: center; }
.perm-matrix td:first-child, .perm-matrix th:first-child { text-align: left; }
.inline-form { display: inline; }
.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 1.4rem; align-items: start; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ===== Zones collapsibles (roles & droits) ===== */
.role-zone { border: 1px solid var(--border); border-radius: 12px; margin-bottom: 1rem; overflow: hidden; }
.role-zone summary { list-style: none; cursor: pointer; padding: 1rem 1.1rem; display: flex; align-items: center; justify-content: space-between; gap: .8rem; background: var(--gray-light); }
.role-zone summary::-webkit-details-marker { display: none; }
.role-zone summary .chevron { transition: transform .18s ease; color: var(--muted); flex: none; }
.role-zone[open] summary .chevron { transform: rotate(90deg); }
.role-zone summary:hover { background: var(--muted-bg); }
.role-zone-body { padding: 1.1rem; }

/* ===== Responsive: mobile & tablette (menu laterale en tiroir) ===== */
@media (max-width: 900px) {
  .hamburger { display: flex; }
  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 70; width: 270px; flex: none;
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: 10px 0 32px rgba(0, 0, 0, .2);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 65; opacity: 0; pointer-events: none; transition: opacity .2s ease; }
  .sidebar-backdrop.show { opacity: 1; pointer-events: auto; }
  .admin-content { padding: 1.1rem; }
  .topbar { padding: .9rem 1rem; }
  .topbar-clock, .topbar-user-info { display: none; }
  .topbar-user { border-left: none; padding-left: 0; }
}
@media (max-width: 560px) {
  .topbar-title { font-size: 1rem; }
  .topbar-actions { gap: .5rem; }
  .btn-primary .btn-label { display: none; }
}
