/* =========================================================
   Dasrwet Audit Platform — styles
   ========================================================= */

:root {
  --navy: #0b3a86;
  --navy-deep: #04204f;
  --navy-light: #1f6fc4;
  --cyan: #1ec4b4;
  --cyan-dark: #0fa394;
  --cyan-soft: #7fdcd1;
  --ink: #15233f;
  --text: #3a4458;
  --muted: #6b7280;
  --line: #e1e8f3;
  --bg: #f4f7fc;
  --bg-white: #fff;
  --success: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --alert: #c2410c;
  --alert-bg: #fff7ed;

  --radius: 12px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 3px rgba(15,23,42,.06);
  --shadow-md: 0 4px 14px rgba(15,23,42,.08);
  --shadow-lg: 0 12px 40px rgba(15,23,42,.14);
  --transition: 200ms cubic-bezier(.4,0,.2,1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

/* Fix critique : le hidden attribute HTML doit écraser tous les display */
[hidden] { display: none !important; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  font-size: 14px;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

.view { min-height: 100vh; }

/* ============ LOGIN ============ */
.login-view {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(140deg, var(--navy-deep), var(--navy) 50%, var(--cyan-dark));
  padding: 40px 20px;
}
.login-card {
  background: #fff; border-radius: 18px;
  padding: 44px 40px;
  max-width: 440px; width: 100%;
  box-shadow: var(--shadow-lg);
}
.brand-header { text-align: center; margin-bottom: 30px; }
.brand-mark {
  display: inline-block;
  font-weight: 800; font-size: 20px; color: var(--navy);
  letter-spacing: -.02em;
  background: linear-gradient(135deg, var(--navy), var(--cyan-dark));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.brand-line {
  width: 60px; height: 3px;
  background: linear-gradient(90deg, var(--cyan), var(--navy-light));
  border-radius: 2px; margin: 12px auto;
}
.brand-header h1 {
  font-size: 22px; color: var(--ink); font-weight: 700;
  margin-bottom: 8px;
}
.brand-sub { font-size: 13px; color: var(--muted); }
#login-form { display: flex; flex-direction: column; gap: 16px; }
#login-form label { display: flex; flex-direction: column; gap: 6px; }
#login-form label span {
  font-size: 12px; font-weight: 600; color: var(--navy);
  text-transform: uppercase; letter-spacing: .05em;
}
#login-form input {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff; color: var(--ink);
  transition: var(--transition);
}
#login-form input:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(30,196,180,.15);
}
.error-msg {
  background: #fef2f2; color: var(--danger);
  border: 1px solid #fca5a5;
  padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 13px;
}
.login-footer {
  margin-top: 26px; padding-top: 20px;
  border-top: 1px solid var(--line);
  text-align: center; font-size: 12px; color: var(--muted);
}
.login-footer p { margin: 4px 0; }
.login-footer a { color: var(--navy); text-decoration: none; font-weight: 500; }

/* ============ BUTTONS ============ */
.btn {
  padding: 10px 18px; border: 0; border-radius: 8px;
  font-weight: 600; font-size: 13px;
  transition: var(--transition);
  display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none;
}
.btn-primary {
  background: linear-gradient(135deg, var(--navy), var(--cyan-dark));
  color: #fff;
  box-shadow: 0 4px 14px rgba(11,58,134,.28);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(11,58,134,.4); }
.btn-ghost {
  background: transparent; color: var(--navy);
  border: 1px solid var(--line);
}
.btn-ghost:hover { background: var(--bg); border-color: var(--navy-light); }
.btn-danger { color: var(--danger); border-color: rgba(239,68,68,.3); }
.btn-danger:hover { background: #fef2f2; border-color: var(--danger); }
.btn-danger-outline {
  background: #fff; color: var(--danger); border: 1px solid var(--danger);
}
.btn-back {
  background: transparent; color: var(--navy);
  padding: 8px 12px; font-weight: 500;
}
.btn-back:hover { color: var(--cyan-dark); }

/* ============ APP HEADER ============ */
.app-view { display: flex; flex-direction: column; }
.app-header {
  background: #fff;
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 50;
}
.app-header-inner {
  max-width: 1200px; margin: 0 auto;
  padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px;
}
.brand-mini {
  font-weight: 800; font-size: 15px; color: var(--navy);
  letter-spacing: -.02em;
}
.brand-mini span { color: var(--cyan-dark); margin: 0 6px; }
.mission-info {
  flex: 1; text-align: center;
  color: var(--ink); font-size: 13px;
  font-weight: 500;
}
.mission-info .sep { color: var(--muted); margin: 0 8px; }
.mission-info .placeholder { color: var(--muted); font-style: italic; }
.app-actions { display: flex; gap: 8px; }

/* ============ MAIN ============ */
.app-main {
  max-width: 1200px; margin: 0 auto;
  padding: 30px 24px 60px;
  width: 100%;
}
.app-section { animation: fadeIn 300ms ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-head { margin-bottom: 22px; }
.section-head h2 {
  color: var(--navy); font-size: 22px; font-weight: 700;
  margin-bottom: 6px;
}
.section-lead { color: var(--muted); font-size: 14px; }

/* ============ DASHBOARD ============ */
.questionnaires-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 30px;
}
.q-card {
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  cursor: pointer;
  transition: var(--transition);
  position: relative; overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.q-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: linear-gradient(180deg, var(--navy), var(--cyan));
  transform: scaleY(0); transform-origin: top;
  transition: var(--transition);
}
.q-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--cyan);
}
.q-card:hover::before { transform: scaleY(1); }
.q-card-id {
  font-size: 11px; font-weight: 700;
  color: var(--cyan-dark); letter-spacing: .1em;
  text-transform: uppercase; margin-bottom: 4px;
}
.q-card-title {
  font-size: 15px; color: var(--navy);
  font-weight: 600; margin-bottom: 6px;
  line-height: 1.3;
}
.q-card-cible { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.q-card-stats {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--muted);
  padding-top: 10px; border-top: 1px solid var(--line);
}
.q-card-stats strong { color: var(--ink); font-weight: 600; }
.mini-progress {
  height: 4px; background: var(--line);
  border-radius: 2px; margin-top: 10px; overflow: hidden;
}
.mini-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--navy), var(--cyan));
  width: 0%; transition: width var(--transition);
}
.q-card.completed { background: linear-gradient(135deg, #e6f7f5, #fff 60%); }
.q-card.completed .q-card-id::after {
  content: " ✓"; color: var(--success);
}

.dashboard-footer {
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 22px;
  box-shadow: var(--shadow-sm);
}
.progress-global {
  display: grid;
  grid-template-columns: 200px 1fr 60px;
  gap: 16px; align-items: center;
}
.progress-label {
  font-size: 12px; color: var(--navy); font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
}
.progress-bar-wrap {
  height: 10px; background: var(--line);
  border-radius: 5px; overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--navy), var(--cyan-dark), var(--cyan));
  width: 0%; transition: width 400ms ease;
}
.progress-pct {
  font-size: 15px; font-weight: 700; color: var(--navy);
  text-align: right;
}

/* ============ QUESTIONNAIRE VIEW ============ */
.questionnaire-header {
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 20px; align-items: center;
  box-shadow: var(--shadow-sm);
}
.questionnaire-title h2 {
  color: var(--navy); font-size: 20px; font-weight: 700;
  margin-bottom: 4px;
}
.q-meta { font-size: 12px; color: var(--muted); }
.questionnaire-progress {
  display: flex; align-items: center; gap: 12px;
}
.questionnaire-progress .mini-progress {
  width: 100px; margin-top: 0;
}
.questionnaire-progress span {
  font-size: 13px; font-weight: 700; color: var(--navy);
}

.q-sections { display: flex; flex-direction: column; gap: 20px; }
.q-section {
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px 26px;
  box-shadow: var(--shadow-sm);
}
.q-section h3 {
  color: var(--navy); font-size: 16px; font-weight: 700;
  margin-bottom: 16px; padding-bottom: 10px;
  border-bottom: 2px solid var(--line);
}
.question {
  padding: 16px 0; border-bottom: 1px solid var(--line);
}
.question:last-child { border-bottom: 0; padding-bottom: 0; }
.question-header {
  display: flex; gap: 12px; align-items: baseline;
  margin-bottom: 8px;
}
.question-id {
  font-size: 11px; font-weight: 700;
  color: var(--cyan-dark); letter-spacing: .06em;
  background: #e6f7f5;
  padding: 2px 8px; border-radius: 10px;
  flex-shrink: 0;
}
.question-libelle {
  font-size: 14px; font-weight: 600; color: var(--ink);
  flex: 1; line-height: 1.5;
}
.question-libelle .required { color: var(--danger); margin-left: 3px; }
.question-guidance {
  background: linear-gradient(135deg, #eff6ff, #ecfdfa);
  border-left: 3px solid var(--cyan);
  padding: 10px 14px; border-radius: 0 6px 6px 0;
  font-size: 12px; color: #3a4458;
  margin: 8px 0 12px;
  line-height: 1.55;
}
.question-guidance strong { color: var(--navy); }
.question-signal-alerte {
  background: var(--alert-bg); border-left: 3px solid var(--alert);
  padding: 8px 12px; border-radius: 0 6px 6px 0;
  font-size: 12px; color: var(--alert);
  margin: 8px 0 12px;
  font-weight: 500;
}
.question-signal-alerte::before { content: "⚠ Signal d'alerte : "; font-weight: 700; }
.question-input textarea,
.question-input input[type=text],
.question-input input[type=number],
.question-input select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  transition: var(--transition);
}
.question-input textarea {
  min-height: 80px; resize: vertical;
  font-family: inherit;
}
.question-input textarea:focus,
.question-input input:focus,
.question-input select:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(30,196,180,.15);
}
.question-input .options {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.question-input .option {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px; background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 20px;
  cursor: pointer;
  transition: var(--transition);
  font-size: 13px;
}
.question-input .option:hover { border-color: var(--cyan); }
.question-input .option input { margin: 0; }
.question-input .option.selected {
  background: linear-gradient(135deg, var(--navy), var(--cyan-dark));
  color: #fff; border-color: transparent;
}
.question-input .option.selected input { accent-color: #fff; }
.question-input .unite {
  font-size: 12px; color: var(--muted); font-style: italic;
  margin-left: 8px;
}
.photo-placeholder {
  padding: 12px 14px; background: var(--bg);
  border: 1px dashed var(--line); border-radius: var(--radius-sm);
  font-size: 12px; color: var(--muted);
}

.questionnaire-footer {
  margin-top: 24px;
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.autosave-indicator {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--muted);
}
.autosave-indicator .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ============ MODAL ============ */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(15,35,63,.5);
  backdrop-filter: blur(4px);
}
.modal-card {
  position: relative;
  background: #fff; border-radius: 16px;
  padding: 28px 32px; max-width: 480px; width: 100%;
  box-shadow: var(--shadow-lg);
}
.modal-card h3 {
  color: var(--navy); font-size: 18px; margin-bottom: 20px;
}
.modal-card label { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.modal-card label span {
  font-size: 12px; font-weight: 600; color: var(--navy);
  text-transform: uppercase; letter-spacing: .05em;
}
.modal-card input {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.modal-card input:focus {
  outline: none; border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(30,196,180,.15);
}
.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 24px; padding-top: 20px;
  border-top: 1px solid var(--line);
}
.modal-danger {
  margin-top: 20px; padding-top: 20px;
  border-top: 1px dashed #fca5a5;
}
.modal-danger .small {
  font-size: 11px; color: var(--muted); margin-top: 6px;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  .app-header-inner {
    flex-wrap: wrap; padding: 12px 16px;
  }
  .mission-info { order: 3; width: 100%; text-align: left; }
  .app-actions { flex-wrap: wrap; }
  .app-actions .btn { padding: 8px 12px; font-size: 12px; }
  .app-main { padding: 20px 16px; }
  .questionnaires-grid { grid-template-columns: 1fr; }
  .questionnaire-header { grid-template-columns: 1fr; }
  .questionnaire-progress { justify-content: flex-start; }
  .progress-global { grid-template-columns: 1fr; gap: 8px; }
  .progress-pct { text-align: left; }
}
