/* ============================================================================
   Tokens — palette officielle T&S (extraite du livrable V1_19)
   ============================================================================ */

:root {
  --navy:        #14395A;
  --navy-dark:   #0d2840;
  --navy-light:  #1e4f7a;
  --yellow:      #F7B131;
  --yellow-light:#fdc95a;
  --yellow-bg:   #FEF6E0;

  --bg:     #f4f6f8;
  --card:   #ffffff;
  --text:   #1a2332;
  --text2:  #4a5568;
  --muted:  #8899aa;
  --border: #dde3ea;

  --ok:   #2d7a3a;
  --warn: #c98400;
  --err:  #c0392b;

  /* alias historiques */
  --accent: var(--yellow);
  --accent-dark: #d99a25;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================================
   Layout app (index, result)
   ============================================================================ */

.container {
  max-width: 780px;
  margin: 0 auto;
  padding: 48px 24px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 32px;
}

.app-header h1 {
  margin: 0 0 4px;
  font-size: 26px;
  font-weight: 700;
  color: var(--navy);
}

.app-header .subtitle {
  margin: 0;
  color: var(--text2);
  font-size: 14px;
}

.app-header .logout-form button {
  background: transparent;
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text2);
  cursor: pointer;
  font-weight: 500;
}

.app-header .logout-form button:hover {
  background: var(--card);
  color: var(--navy);
  border-color: var(--navy);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  margin-bottom: 24px;
  box-shadow: 0 1px 3px rgba(13, 40, 64, 0.04);
}

.field { margin-bottom: 22px; }

label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 14px;
  color: var(--text);
}

input[type="file"] {
  width: 100%;
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: 14px;
}

.hint, .footnote {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.req { color: var(--err); }
.opt { color: var(--muted); font-weight: 400; }

button[type="submit"], .btn.primary {
  display: inline-block;
  background: var(--yellow);
  color: var(--navy);
  border: none;
  padding: 12px 22px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}

button[type="submit"]:hover, .btn.primary:hover {
  background: var(--yellow-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(247, 177, 49, 0.3);
}

.btn {
  display: inline-block;
  padding: 12px 22px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: white;
  text-decoration: none;
  color: var(--text);
  font-weight: 500;
  font-size: 15px;
  margin-right: 8px;
}

.btn:hover { border-color: var(--navy); color: var(--navy); }

/* Variante destructive (suppression). Spécificité (0,2,0) > .inline-form button (0,1,1). */
.btn.danger,
.inline-form button.danger {
  background: white;
  color: var(--err);
  border: 1px solid #f5c6c6;
}
.btn.danger:hover,
.inline-form button.danger:hover {
  background: #fdecec;
  color: var(--err);
  border-color: var(--err);
}

.actions {
  margin: 16px 0 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.actions .btn,
.actions .inline-form,
.actions .inline-form button { margin-right: 0; }

.status {
  padding: 12px 16px;
  border-radius: 8px;
  font-weight: 600;
  margin-bottom: 16px;
}
.status.ok   { background: #e6f4ea; color: var(--ok); }
.status.warn { background: var(--yellow-bg); color: var(--warn); }

pre.report {
  white-space: pre-wrap;
  word-wrap: break-word;
  background: var(--bg);
  padding: 16px;
  border-radius: 8px;
  font-size: 13px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  border: 1px solid var(--border);
  max-height: 600px;
  overflow-y: auto;
}

ul.warnings { margin: 0; padding-left: 20px; font-size: 14px; }
ul.warnings li { margin-bottom: 4px; }

code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

h2 { margin: 0 0 16px; font-size: 18px; font-weight: 600; color: var(--navy); }

/* ============================================================================
   Page de login (split-screen brand)
   ============================================================================ */

.login-body {
  margin: 0;
  background: var(--bg);
  min-height: 100vh;
}

.login-shell {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 100vh;
}

/* ---- Panneau gauche : brand ---- */
.login-brand {
  position: relative;
  background: linear-gradient(135deg, var(--navy-dark) 0%, var(--navy) 60%, var(--navy-light) 100%);
  color: white;
  padding: 56px 56px 40px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}

.brand-deco {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.brand-deco .circle {
  position: absolute;
  border-radius: 50%;
  border: 2px solid rgba(247, 177, 49, 0.18);
}

.brand-deco .c1 {
  width: 480px; height: 480px;
  top: -120px; right: -180px;
  border-color: rgba(247, 177, 49, 0.12);
}
.brand-deco .c2 {
  width: 320px; height: 320px;
  top: -40px; right: -100px;
  border-color: rgba(247, 177, 49, 0.20);
  background: radial-gradient(circle, rgba(247, 177, 49, 0.08) 0%, transparent 70%);
}
.brand-deco .c3 {
  width: 220px; height: 220px;
  bottom: -70px; left: -70px;
  border-color: rgba(255, 255, 255, 0.08);
}
.brand-deco .c4 {
  width: 16px; height: 16px;
  background: var(--yellow);
  border: none;
  top: 30%; right: 18%;
  box-shadow: 0 0 30px rgba(247, 177, 49, 0.6);
}

.brand-content {
  position: relative;
  z-index: 2;
  max-width: 440px;
}

.brand-logo {
  height: 120px;
  width: auto;
  max-width: 140px;
  margin-bottom: 28px;
  object-fit: contain;
  display: block;
}

.brand-title {
  margin: 0 0 4px;
  font-size: 38px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: white;
}

.brand-tagline {
  margin: 0 0 32px;
  font-size: 16px;
  font-weight: 500;
  color: var(--yellow);
  letter-spacing: 0.02em;
}

.brand-baseline {
  margin: 0 0 36px;
  font-size: 16px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.78);
  max-width: 380px;
}

.brand-features {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.feature {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14.5px;
  color: rgba(255, 255, 255, 0.92);
}

.feature-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: rgba(247, 177, 49, 0.10);
  border: 1px solid rgba(247, 177, 49, 0.28);
  border-radius: 10px;
  flex-shrink: 0;
  color: var(--yellow);
}

.feature-icon svg {
  width: 18px;
  height: 18px;
  display: block;
}

.brand-footer {
  position: relative;
  z-index: 2;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.45);
  letter-spacing: 0.04em;
}

/* ---- Panneau droit : form ---- */
.login-pane {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: white;
  border-radius: 16px;
  border: 1px solid var(--border);
  padding: 40px 36px;
  box-shadow: 0 4px 24px rgba(13, 40, 64, 0.06);
}

.login-header h2 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 700;
  color: var(--navy);
}

.login-header p {
  margin: 0 0 28px;
  color: var(--text2);
  font-size: 14px;
}

.login-error {
  background: #fdecec;
  color: var(--err);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 20px;
  border: 1px solid #f5c6c6;
}

.login-form .field { margin-bottom: 18px; }

.login-form input[type="text"],
.login-form input[type="password"],
.login-form input[type="email"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  transition: all 0.15s;
  font-family: inherit;
}

.login-form input:focus {
  outline: none;
  background: white;
  border-color: var(--yellow);
  box-shadow: 0 0 0 3px rgba(247, 177, 49, 0.18);
}

.btn-login {
  width: 100%;
  padding: 14px;
  background: var(--navy);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}

.btn-login:hover {
  background: var(--navy-dark);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(13, 40, 64, 0.25);
}

.btn-login:hover .arrow { transform: translateX(3px); }

.btn-login .arrow {
  transition: transform 0.15s;
  font-weight: 400;
}

.login-foot {
  margin: 24px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* ---- Responsive : stack vertical sur mobile/tablette ---- */
@media (max-width: 920px) {
  .login-shell { grid-template-columns: 1fr; }

  .login-brand {
    padding: 40px 28px 32px;
    min-height: 280px;
  }

  .brand-logo { height: 64px; width: auto; max-width: 80px; margin-bottom: 16px; }
  .brand-title { font-size: 30px; }
  .brand-baseline { margin-bottom: 24px; font-size: 14px; }
  .brand-features { display: none; } /* gain de place */
  .brand-footer { display: none; }

  .login-pane { padding: 28px 20px; }
  .login-card { padding: 32px 24px; }
}

/* ============================================================================
   Pages "Études" & détail
   ============================================================================ */

.container-wide { max-width: 1100px; }

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-header-actions .btn {
  padding: 8px 14px;
  font-size: 13px;
  margin: 0;
}

.breadcrumb {
  margin: 0 0 6px;
  font-size: 13px;
}
.breadcrumb a {
  color: var(--text2);
  text-decoration: none;
}
.breadcrumb a:hover { color: var(--navy); }

/* ---- Tableau des études ---- */
.card.no-pad {
  padding: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.studies-table {
  width: 100%;
  min-width: 640px; /* force scroll horizontal sur mobile plutôt que cassage */
  border-collapse: collapse;
  font-size: 14px;
}

.studies-table thead th {
  text-align: left;
  padding: 14px 18px;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text2);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.studies-table tbody td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.studies-table tbody tr:last-child td { border-bottom: none; }
.studies-table tbody tr:hover { background: rgba(247, 177, 49, 0.04); }

.studies-table .muted { color: var(--muted); font-size: 13px; }

.studies-table .row-actions a {
  color: var(--navy);
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
}
.studies-table .row-actions a:hover { text-decoration: underline; }

/* ---- Code pill / badge ---- */
.code-pill {
  display: inline-block;
  background: var(--navy);
  color: white;
  padding: 4px 10px;
  border-radius: 6px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  letter-spacing: 0.15em;
  font-weight: 600;
}

.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-right: 4px;
}
.pill.ok   { background: #e6f4ea; color: var(--ok); }
.pill.warn { background: var(--yellow-bg); color: var(--warn); }
.pill.acc  { background: #e7eef7; color: var(--navy); }

.muted { color: var(--muted); font-weight: 400; }

.empty-state {
  text-align: center;
  padding: 48px 24px;
}
.empty-state p { color: var(--muted); margin-bottom: 16px; }

/* ---- Access card (code + email + actions inline) ---- */
.access-card { border-color: var(--yellow); border-width: 2px; }
.access-card h2 { margin-bottom: 6px; }

.access-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin: 22px 0 18px;
}

.access-field {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.access-field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text2);
  margin: 0;
}

.code-display {
  background: var(--navy);
  color: white;
  padding: 14px 18px;
  border-radius: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 22px;
  letter-spacing: 0.28em;
  font-weight: 700;
  text-align: center;
  user-select: all;
}

/* Formulaire de modification d'email — input + bouton sur la même ligne */
.email-edit-form {
  display: flex;
  gap: 8px;
  margin: 0;
  min-width: 0;
}
.email-edit-form input[type="email"] {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  background: var(--bg);
  color: var(--navy);
  font-family: inherit;
  font-weight: 600;
}
.email-edit-form input[type="email"]:focus {
  outline: none;
  background: white;
  border-color: var(--yellow);
  box-shadow: 0 0 0 3px rgba(247, 177, 49, 0.18);
}

.access-field-action {
  margin: 0;
  display: flex;
}

/* Boutons "secondaires" dans la card d'accès : outline navy sur fond blanc.
   Spécificité (0,2,1) > button[type="submit"] (0,1,1) → on bat le style primary jaune. */
.access-card button.btn-secondary {
  background: white;
  color: var(--navy);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.access-card button.btn-secondary:hover {
  background: var(--bg);
  border-color: var(--navy);
  transform: none;
  box-shadow: none;
}

.access-link {
  margin-top: 4px;
}
.access-link label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text2);
  margin-bottom: 6px;
}

.link-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--text2);
  background: var(--bg);
}
.link-input:focus { outline: none; border-color: var(--yellow); background: white; }

@media (max-width: 600px) {
  .access-grid { grid-template-columns: 1fr; gap: 18px; }
  .email-edit-form { flex-direction: column; }
  .access-card button.btn-secondary { width: 100%; }
}

/* ---- Audit log (tentatives d'accès) ---- */
.audit-wrap {
  margin-top: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.audit-list {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 13px;
}
.audit-list th, .audit-list td {
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  text-align: left;
}
.audit-list th {
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text2);
  font-weight: 600;
}
.audit-list tr:last-child td { border-bottom: none; }
.audit-list code {
  background: transparent;
  padding: 0;
  font-size: 12px;
}

/* ---- Inline form (regenerate) ---- */
.inline-form { display: inline-block; margin: 0; }
.inline-form button {
  background: white;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 22px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 15px;
  cursor: pointer;
  margin-right: 8px;
  font-family: inherit;
}
.inline-form button:hover {
  border-color: var(--navy);
  color: var(--navy);
  transform: none;
  box-shadow: none;
  background: white;
}

/* ============================================================================
   Overlay de chargement (génération de livrable)
   ============================================================================ */

.gen-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13, 40, 64, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadein 0.2s ease;
}
/* L'attribut HTML `hidden` doit l'emporter sur display: flex.
   Sans ça (selector specificity), l'overlay reste visible au chargement. */
.gen-overlay[hidden] { display: none; }

@keyframes fadein {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.gen-spinner-card {
  background: white;
  padding: 40px 36px;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  text-align: center;
  max-width: 420px;
  width: calc(100% - 40px);
}

.gen-spinner-card h3 {
  margin: 16px 0 8px;
  color: var(--navy);
  font-size: 18px;
  font-weight: 700;
}

.gen-spinner-card p {
  margin: 6px 0;
  color: var(--text2);
  font-size: 14px;
}

.gen-spinner-card .hint {
  margin-top: 14px;
  font-size: 12px;
  color: var(--muted);
}

.gen-spinner {
  width: 56px;
  height: 56px;
  margin: 0 auto;
  border: 4px solid var(--bg);
  border-top-color: var(--yellow);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

button[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-foot-secondary {
  margin-top: 6px;
  font-size: 11px;
  opacity: 0.7;
}
.login-foot-secondary a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px dotted var(--muted);
}
.login-foot-secondary a:hover {
  color: var(--navy);
  border-bottom-color: var(--navy);
}

/* ============================================================================
   Responsive — pages app (index, studies, study_detail, result)
   Le login/v_form ont déjà leur propre breakpoint à 920px.
   ============================================================================ */

/* Tablette */
@media (max-width: 720px) {
  .container { padding: 32px 18px; }

  .app-header { margin-bottom: 24px; }
  .app-header h1 { font-size: 22px; }

  .card { padding: 22px 18px; }

  .access-grid { gap: 12px; }
  .code-display {
    font-size: 22px;
    letter-spacing: 0.24em;
    padding: 14px 16px;
  }
  .name-display {
    font-size: 16px;
    padding: 14px 16px;
  }
}

/* Mobile */
@media (max-width: 480px) {
  .container { padding: 24px 14px; }

  .app-header h1 { font-size: 20px; }
  .app-header .subtitle { font-size: 13px; }

  .card { padding: 18px 14px; border-radius: 12px; }

  .actions .btn,
  .actions .btn.primary,
  .actions .inline-form,
  .actions .inline-form button {
    width: 100%;
    text-align: center;
    justify-content: center;
  }

  .code-display {
    font-size: 20px;
    letter-spacing: 0.18em;
    padding: 12px 14px;
  }

  .studies-table thead th,
  .studies-table tbody td { padding: 12px 14px; }

  pre.report { font-size: 12px; padding: 12px; }

  .gen-spinner-card { padding: 28px 22px; }
}
