:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #f3f8f8;
  --surface: #ffffff;
  --text: #23264f;
  --muted: #687680;
  --line: #d8e6e7;
  --primary: #232650;
  --primary-2: #30356a;
  --accent: #8fbe3f;
  --accent-2: #66c7d0;
  --accent-soft: #f1f7e9;
  --accent-2-soft: #eaf8fa;
  --success: #5c9d2d;
  --warning: #b87818;
  --danger: #b43b49;
  --radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% 0%, rgb(102 199 208 / 8%), transparent 34rem),
    linear-gradient(180deg, #f7fbfb 0%, var(--bg) 100%);
  color: var(--text);
}

body::before {
  content: '';
  position: fixed;
  left: 50%;
  top: 51%;
  width: min(54vw, 700px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  background: url('/asv-logo.jpg') center / contain no-repeat;
  opacity: .11;
  mix-blend-mode: multiply;
  filter: saturate(.95) contrast(.98);
  pointer-events: none;
  z-index: 0;
}

button, input, textarea, select { font: inherit; }
a { color: inherit; }

.topbar {
  min-height: 78px;
  padding: 12px clamp(16px, 4vw, 34px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: linear-gradient(105deg, #20234c 0%, var(--primary) 58%, #294d59 155%);
  color: white;
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 3px solid var(--accent-2);
  box-shadow: 0 8px 30px rgb(35 38 80 / 18%);
}

.topbar-brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-logo-wrap {
  width: 54px;
  height: 54px;
  flex: 0 0 54px;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 4px;
  border-radius: 13px;
  background: white;
  box-shadow:
    inset 0 0 0 1px rgb(35 38 80 / 8%),
    0 4px 14px rgb(0 0 0 / 16%);
}

.topbar-logo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.2rem, 4vw, 1.7rem);
  letter-spacing: -.015em;
}

.eyebrow {
  margin: 0 0 2px;
  color: #dff4f6;
  font-size: .72rem;
  font-weight: 850;
  letter-spacing: .18em;
  opacity: .82;
}

.topbar-link {
  font-size: .88rem;
  text-decoration: none;
  padding: 9px 12px;
  border: 1px solid rgb(102 199 208 / 48%);
  border-radius: 12px;
  background: rgb(255 255 255 / 5%);
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease;
}

.topbar-link:hover {
  border-color: var(--accent);
  background: rgb(255 255 255 / 10%);
}

.page {
  position: relative;
  z-index: 1;
  width: min(1100px, calc(100% - 24px));
  margin: 22px auto 50px;
}

.page-form { max-width: 760px; }

.card {
  background: rgb(255 255 255 / 89%);
  border: 1px solid rgb(216 230 231 / 92%);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgb(35 38 80 / 6%);
}

.intro-card { padding: 18px 20px; margin-bottom: 14px; }
.intro-card h2 { margin: 0 0 6px; font-size: 1rem; }
.intro-card p { margin: 0; color: var(--muted); line-height: 1.45; }

.form-card { padding: clamp(18px, 4vw, 30px); }
.section-title { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.section-title > span {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgb(102 199 208 / 36%);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-soft), var(--accent-2-soft));
  color: var(--primary);
  font-weight: 850;
}
.section-title h2 { margin: 0; color: var(--primary); font-size: 1.05rem; }
.section-title p { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }
.section-gap { margin-top: 28px; }

.field-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.field { display: grid; gap: 7px; position: relative; }
.field > span { font-size: .9rem; font-weight: 700; }
.field strong { color: var(--danger); }

input, textarea, select {
  width: 100%;
  min-height: 48px;
  border: 1px solid #cbdcdc;
  border-radius: 12px;
  padding: 11px 13px;
  background: rgb(255 255 255 / 96%);
  color: var(--text);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent-2);
  background: #fcffff;
  box-shadow: 0 0 0 3px rgb(102 199 208 / 18%);
}

.autocomplete-field { margin-top: 4px; }
.suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 15;
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 18px 40px rgb(35 38 80 / 16%);
}
.suggestion-button { width: 100%; border: 0; background: white; padding: 12px 13px; text-align: left; cursor: pointer; border-bottom: 1px solid #edf4f4; }
.suggestion-button:last-child { border-bottom: 0; }
.suggestion-button:hover { background: var(--accent-2-soft); }
.suggestion-name { display: block; font-weight: 750; }
.suggestion-meta { display: block; margin-top: 2px; color: var(--muted); font-size: .8rem; }

.placeholder-block {
  margin-top: 24px;
  border: 1px dashed #90bfc3;
  background: rgb(247 251 251 / 92%);
  padding: 16px;
  border-radius: 14px;
}
.placeholder-block strong { display: block; margin-bottom: 4px; }
.placeholder-block p { margin: 0; color: var(--muted); line-height: 1.45; }

.primary-button {
  width: 100%;
  min-height: 52px;
  margin-top: 22px;
  border: 0;
  border-radius: 13px;
  background: linear-gradient(105deg, var(--primary), var(--primary-2));
  color: white;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 7px 18px rgb(35 38 80 / 16%);
}
.primary-button:hover {
  background: linear-gradient(105deg, var(--primary-2), #386875);
  box-shadow: 0 9px 22px rgb(35 38 80 / 22%);
}
.primary-button:disabled { opacity: .55; cursor: wait; }

.message { margin-top: 18px; padding: 12px 14px; border-radius: 12px; font-weight: 650; }
.message.success { background: #edf7e7; color: #457b24; }
.message.error { background: #fae8eb; color: #94313d; }

.admin-layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 16px;
  min-height: calc(100vh - 126px);
}

.admin-panel { overflow: hidden; }
.admin-panel-header {
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgb(255 255 255 / 94%), rgb(251 254 254 / 88%));
}
.admin-panel-header h2 { margin: 0 0 10px; color: var(--primary); font-size: 1.05rem; }
.admin-search { display: flex; gap: 8px; }
.admin-search input { min-height: 42px; }

.intervention-list { max-height: calc(100vh - 230px); overflow: auto; }
.intervention-row {
  display: block;
  width: 100%;
  border: 0;
  border-left: 4px solid transparent;
  border-bottom: 1px solid #edf4f4;
  background: rgb(255 255 255 / 91%);
  padding: 14px 16px 14px 12px;
  text-align: left;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.intervention-row:hover { background: rgb(247 251 251 / 95%); }
.intervention-row.active {
  border-left-color: var(--accent);
  background: linear-gradient(90deg, rgb(241 247 233 / 94%), rgb(255 255 255 / 90%) 70%);
}
.row-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row-ref { color: var(--primary); font-weight: 850; }
.row-client { display: block; margin-top: 5px; font-weight: 700; }
.row-meta { display: block; margin-top: 3px; color: var(--muted); font-size: .82rem; }

.badge { display: inline-flex; align-items: center; padding: 4px 8px; border-radius: 999px; font-size: .72rem; font-weight: 850; }
.badge-new { background: var(--accent-2-soft); color: #2b7980; }
.badge-review { background: #fff3d8; color: #906115; }
.badge-valid { background: var(--accent-soft); color: #4b7f29; }
.badge-sent { background: #ececf4; color: #4a4c73; }

.detail-panel { padding: 22px; }
.detail-empty { display: grid; place-items: center; min-height: 300px; color: var(--muted); text-align: center; }
.detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.detail-header h2 { margin: 0 0 4px; color: var(--primary); }
.detail-header p { margin: 0; color: var(--muted); }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.detail-item {
  padding: 13px;
  border-radius: 12px;
  background: rgb(248 251 251 / 88%);
  border: 1px solid rgb(231 240 240 / 92%);
}
.detail-item span { display: block; color: var(--muted); font-size: .78rem; margin-bottom: 4px; }
.detail-item strong { display: block; overflow-wrap: anywhere; }

@media (min-width: 821px) {
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  }

  .topbar-brand {
    grid-column: 2;
    justify-self: center;
  }

  .topbar > .connection-state,
  .topbar > .topbar-link {
    grid-column: 3;
    justify-self: end;
  }
}

@media (min-width: 680px) {
  .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid .field:first-child { grid-column: 1 / -1; }
}

@media (max-width: 820px) {
  .admin-layout { grid-template-columns: 1fr; }
  .intervention-list { max-height: 360px; }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  body::before {
    width: min(82vw, 400px);
    opacity: .075;
  }

  .card {
    background: rgb(255 255 255 / 92%);
  }

  .topbar {
    padding: 10px 12px;
    gap: 10px;
  }

  .topbar-brand { gap: 9px; }

  .topbar-logo-wrap {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
    border-radius: 10px;
  }

  .topbar h1 { font-size: 1.1rem; }
  .eyebrow { font-size: .64rem; }
}

/* ========================= ASV DARK THEME ========================= */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1220;
  --surface: #171d2d;
  --text: #eef3f7;
  --muted: #9aa7b4;
  --line: #2a3546;
  --primary: #e8eef6;
  --primary-2: #cbd7e6;
  --accent: #9bcf4b;
  --accent-2: #58c8d1;
  --accent-soft: #1f2b20;
  --accent-2-soft: #172d31;
  --success: #8fd05d;
  --warning: #e2a74a;
  --danger: #e36c79;
}

html[data-theme="dark"] body {
  background:
    radial-gradient(circle at 50% 0%, rgb(88 200 209 / 8%), transparent 36rem),
    linear-gradient(180deg, #111827 0%, #0c1220 100%);
  color: var(--text);
}

html[data-theme="dark"] body::before {
  opacity: .035;
  mix-blend-mode: screen;
  filter: grayscale(.25) brightness(.7);
}

html[data-theme="dark"] .topbar {
  background: linear-gradient(105deg, #161a32 0%, #20264a 58%, #23434d 155%);
  border-bottom-color: var(--accent-2);
  box-shadow: 0 10px 34px rgb(0 0 0 / 34%);
}

html[data-theme="dark"] .card,
html[data-theme="dark"] .form-card,
html[data-theme="dark"] .intro-card {
  background: rgb(23 29 45 / 94%);
  border-color: rgb(53 67 86 / 94%);
  box-shadow: 0 12px 32px rgb(0 0 0 / 20%);
}

html[data-theme="dark"] input,
html[data-theme="dark"] textarea,
html[data-theme="dark"] select {
  background: #101725;
  color: var(--text);
  border-color: #344258;
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
  color: #7f8b98;
}

html[data-theme="dark"] input:focus,
html[data-theme="dark"] textarea:focus,
html[data-theme="dark"] select:focus {
  border-color: var(--accent-2);
  outline-color: rgb(88 200 209 / 28%);
}

html[data-theme="dark"] button:not(.topbar-button):not(.theme-toggle) {
  color: var(--text);
}

html[data-theme="dark"] table,
html[data-theme="dark"] .table-wrap {
  background: transparent;
}

html[data-theme="dark"] th {
  background: #151c2b;
  color: #9aa7b4;
  border-bottom-color: #2b3648;
}

html[data-theme="dark"] td {
  color: #e5ebf2;
  border-bottom-color: #273244;
}

html[data-theme="dark"] tr:hover td {
  background: rgb(88 200 209 / 4%);
}

html[data-theme="dark"] .section-title > span {
  background: linear-gradient(135deg, #1f2b20, #172d31);
  border-color: rgb(88 200 209 / 28%);
  color: #dff4f6;
}

html[data-theme="dark"] .section-title h2,
html[data-theme="dark"] .intro-card h2,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3 {
  color: #eef3f7;
}

html[data-theme="dark"] .topbar-link,
html[data-theme="dark"] .topbar-button {
  color: #fff;
}

html[data-theme="dark"] .nav-group-menu,
html[data-theme="dark"] .notification-center-menu,
html[data-theme="dark"] .presence-tooltip {
  background: #171d2d;
  color: #eef3f7;
  border-color: #354257;
  box-shadow: 0 14px 34px rgb(0 0 0 / 42%);
}

html[data-theme="dark"] .nav-group-menu a,
html[data-theme="dark"] .notification-center-item {
  color: #e6edf5;
}

html[data-theme="dark"] .nav-group-menu a:hover,
html[data-theme="dark"] .notification-center-item:hover {
  background: #20293a;
}

html[data-theme="dark"] .session-chip {
  background: rgb(255 255 255 / 5%);
  border-color: rgb(88 200 209 / 34%);
}

html[data-theme="dark"] .modal,
html[data-theme="dark"] .time-modal,
html[data-theme="dark"] .dialog-backdrop {
  background: rgb(4 8 18 / 68%);
}

html[data-theme="dark"] .modal-card,
html[data-theme="dark"] .time-modal-card,
html[data-theme="dark"] [role="dialog"] {
  background: #171d2d;
  border-color: #354257;
  color: #eef3f7;
}

html[data-theme="dark"] .badge,
html[data-theme="dark"] .chip,
html[data-theme="dark"] .status-chip {
  border-color: #354257;
}

html[data-theme="dark"] .hours-overtime,
html[data-theme="dark"] .hours-overtime-label {
  color: #ffad45 !important;
}

html[data-theme="dark"] .hours-night,
html[data-theme="dark"] .hours-night-label {
  color: #b39cff !important;
}

html[data-theme="dark"] ::selection {
  background: rgb(88 200 209 / 30%);
  color: #fff;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    color-scheme: dark;
  }
}


/* ===== Dark mode contrast / shared controls pass ===== */
html[data-theme="dark"] {
  --action: #343b78;
  --action-hover: #434d96;
  --text-strong: #f5f8fb;
  --text-soft: #b7c2cf;
  --field-bg: #111827;
  --field-border: #3a465a;
}

html[data-theme="dark"] label,
html[data-theme="dark"] .field > span,
html[data-theme="dark"] .field label,
html[data-theme="dark"] .form-card label,
html[data-theme="dark"] .form-card .field > span,
html[data-theme="dark"] .detail-item strong,
html[data-theme="dark"] .row-client {
  color: var(--text-strong);
}

html[data-theme="dark"] small,
html[data-theme="dark"] .help,
html[data-theme="dark"] .hint,
html[data-theme="dark"] .field-help,
html[data-theme="dark"] .form-help {
  color: var(--text-soft);
}

html[data-theme="dark"] input,
html[data-theme="dark"] textarea,
html[data-theme="dark"] select {
  background: var(--field-bg);
  color: var(--text-strong);
  border-color: var(--field-border);
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
  color: #8f9cab;
  opacity: 1;
}

html[data-theme="dark"] .primary-button,
html[data-theme="dark"] .planning-primary-button,
html[data-theme="dark"] .user-primary-button,
html[data-theme="dark"] .client-primary-button,
html[data-theme="dark"] .client-save-button,
html[data-theme="dark"] .admin-save-button,
html[data-theme="dark"] .admin-edit-button,
html[data-theme="dark"] .planning-gps-button {
  background: linear-gradient(105deg, var(--action), var(--action-hover)) !important;
  border-color: #5661ad !important;
  color: #fff !important;
}

html[data-theme="dark"] .primary-button:hover,
html[data-theme="dark"] .planning-primary-button:hover,
html[data-theme="dark"] .user-primary-button:hover,
html[data-theme="dark"] .client-primary-button:hover,
html[data-theme="dark"] .admin-save-button:hover,
html[data-theme="dark"] .admin-edit-button:hover {
  background: linear-gradient(105deg, var(--action-hover), #5060a8) !important;
}

html[data-theme="dark"] button:disabled,
html[data-theme="dark"] .primary-button:disabled {
  opacity: .52;
  color: #cbd5e1 !important;
}

html[data-theme="dark"] .admin-panel-header,
html[data-theme="dark"] .detail-item,
html[data-theme="dark"] .placeholder-block,
html[data-theme="dark"] .suggestions,
html[data-theme="dark"] .suggestion-button,
html[data-theme="dark"] .intervention-row {
  background: #151c2b;
  color: var(--text-strong);
  border-color: #344258;
}

html[data-theme="dark"] .intervention-row:hover,
html[data-theme="dark"] .suggestion-button:hover {
  background: #1d2737;
}

html[data-theme="dark"] .intervention-row.active {
  background: linear-gradient(90deg, #20311e, #151c2b 70%);
}

html[data-theme="dark"] .message.success {
  background: #1d3321;
  color: #a8dd86;
}
html[data-theme="dark"] .message.error {
  background: #351e24;
  color: #f39aa4;
}


/* Dark ASV logo */
html[data-theme="dark"] .topbar-logo-wrap {
  background: transparent;
  box-shadow: none;
  padding: 1px;
}
html[data-theme="dark"] .topbar-logo {
  content: url('/asv-logo-dark.webp');
  filter: drop-shadow(0 2px 6px rgb(0 0 0 / 28%));
}
html[data-theme="dark"] body::before {
  background-image: url('/asv-logo-dark.webp');
  opacity: .045;
  mix-blend-mode: screen;
  filter: none;
}

/* Theme-aware ASV logos */
.topbar-logo-wrap {
  background: transparent;
  box-shadow: none;
  padding: 1px;
}

/* Le header reste bleu marine dans les deux thèmes : on garde le logo sombre/éclairé ici. */
.topbar-logo {
  content: url('/asv-logo-dark.webp');
  filter: drop-shadow(0 2px 6px rgb(0 0 0 / 30%));
}

/* Grand logo accueil : source claire d'origine + version sombre détourée finale. */
.mobile-home-intro .home-logo {
  width:min(310px, 78vw);
  max-height:220px;
  margin:0 auto 18px;
  object-fit:contain;
  filter:none;
}
.mobile-home-intro .home-logo-light {
  display:block;
}
.mobile-home-intro .home-logo-dark {
  display:none;
}
html[data-theme="dark"] .mobile-home-intro .home-logo-light {
  display:none;
}
html[data-theme="dark"] .mobile-home-intro .home-logo-dark {
  display:block;
}

body::before {
  background-image:url('/asv-logo.jpg');
}

html[data-theme="dark"] body::before {
  background-image: url('/asv-logo-dark.webp');
  opacity: .045;
  mix-blend-mode: screen;
  filter: none;
}
