:root {
  color-scheme: light;
  --navy: #212c54;
  --navy-deep: #18213f;
  --turquoise: #72c7d4;
  --turquoise-deep: #3aa7b8;
  --canvas: #f3f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --text: #202638;
  --muted-text: #687189;
  --line: #dfe5eb;
  --shadow: 0 12px 32px rgba(33, 44, 84, .08);
  --shadow-hover: 0 16px 40px rgba(33, 44, 84, .14);
  font-family: Figtree, "Avenir Next", Avenir, system-ui, -apple-system, sans-serif;
  background: var(--canvas);
  color: var(--text);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #11172b;
  --surface: #1b2440;
  --surface-soft: #222d4a;
  --text: #f5f7fb;
  --muted-text: #aab5cb;
  --line: #34415f;
  --shadow: 0 14px 34px rgba(0, 0, 0, .25);
  --shadow-hover: 0 18px 42px rgba(0, 0, 0, .35);
}

html { scroll-behavior: smooth; }
body { background: var(--canvas); color: var(--text); min-height: 100vh; }
a { color: #147a9a; text-underline-offset: 3px; }
:root[data-theme="dark"] a { color: var(--turquoise); }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  min-height: 92px;
  padding: .8rem clamp(1rem, 4vw, 4rem);
  background: rgba(33, 44, 84, .97);
  border-bottom: 3px solid var(--turquoise);
  box-shadow: 0 8px 28px rgba(11, 18, 43, .18);
  backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: center; gap: .85rem; color: #fff; text-decoration: none; flex: 0 0 auto; }
.brand img { width: 58px; height: 58px; object-fit: cover; border-radius: 14px; }
.brand span { display: grid; line-height: 1.05; }
.brand strong { color: #fff; font-family: Montserrat, Figtree, sans-serif; font-size: 1.1rem; letter-spacing: .01em; }
.uppercase-input { text-transform: uppercase; }
.brand small { margin-top: .28rem; color: #fff; font-size: .77rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.header-tools { display: flex; align-items: center; justify-content: flex-end; gap: 1.1rem; min-width: 0; }
.site-header nav { display: flex; align-items: center; gap: .25rem; }
.site-header nav a, .account-menu a {
  position: relative;
  padding: .62rem .78rem;
  border-radius: 9px;
  color: rgba(255,255,255,.82);
  font-size: .92rem;
  font-weight: 650;
  text-decoration: none;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}
.site-header nav a:hover, .site-header nav a.active, .account-menu a:hover, .account-menu a.active { background: rgba(114,199,212,.16); color: #fff; }
.site-header nav a.active::after { content: ""; position: absolute; left: .8rem; right: .8rem; bottom: .25rem; height: 2px; border-radius: 2px; background: var(--turquoise); }
.account-menu { display: flex; align-items: center; border-left: 1px solid rgba(255,255,255,.16); padding-left: .65rem; }
.account-menu .logout-link { color: rgba(255,255,255,.58); font-size: .82rem; }
.theme-toggle { width: 42px; height: 42px; padding: 0; border: 1px solid rgba(255,255,255,.2); border-radius: 50%; background: rgba(255,255,255,.08); color: #fff; font-size: 1.2rem; }
.theme-toggle:hover { background: var(--turquoise); color: var(--navy); transform: rotate(8deg); }

main { width: min(1440px, 100%); max-width: none; margin: 0 auto; padding: clamp(2rem, 4vw, 4rem) clamp(1rem, 4vw, 4rem) 5rem; }
.page-heading { position: relative; margin-bottom: 1.7rem; padding-left: 1.05rem; }
.page-heading::before { content: ""; position: absolute; left: 0; top: .2rem; bottom: .15rem; width: 4px; border-radius: 5px; background: var(--turquoise); }
.eyebrow { margin: 0 0 .25rem; color: var(--turquoise-deep); font-size: .73rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
h1, h2, h3 { font-family: Montserrat, Figtree, sans-serif; color: var(--text); letter-spacing: -.025em; }
h1 { margin: 0; font-size: clamp(2.2rem, 5vw, 4.2rem); line-height: 1; }
h2 { margin-top: 2rem; }

.card, form {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: clamp(1.1rem, 2.2vw, 1.8rem);
}
.filter-form { margin: 0 0 1.2rem; }
.form-title { display: flex; align-items: center; gap: .8rem; margin-bottom: 1.25rem; }
.form-title > span { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: rgba(114,199,212,.2); color: var(--turquoise-deep); font-size: 1.45rem; }
.form-title div { display: grid; gap: .15rem; }
.form-title strong { font-family: Montserrat, Figtree, sans-serif; }
.form-title small { color: var(--muted-text); }
.notice-card { margin: 1rem 0; padding: 1rem 1.2rem; border: 1px solid rgba(114,199,212,.45); border-radius: 16px; background: rgba(114,199,212,.12); }
.notice-card p { margin: .35rem 0 0; color: var(--muted-text); }
.manual-invoice { margin-top: 1.25rem; }
.manual-invoice summary { cursor: pointer; color: var(--turquoise-deep); font-weight: 700; }
.manual-invoice[open] summary { margin-bottom: 1rem; }
.job-documents { margin: 1.4rem 0 1rem; }
.job-documents h2 { margin: 0 0 .75rem; font-size: 1.15rem; }
.pdf-drop-zone { display: grid; place-items: center; gap: .35rem; min-height: 150px; margin: 0; padding: 1.4rem; border: 2px dashed var(--line); border-radius: 14px; background: var(--surface-soft); text-align: center; cursor: pointer; transition: border-color .18s ease, background .18s ease, box-shadow .18s ease; }
.pdf-drop-zone:hover, .pdf-drop-zone.is-dragging { border-color: var(--turquoise-deep); background: rgba(114,199,212,.12); box-shadow: 0 0 0 4px rgba(114,199,212,.14); }
.pdf-drop-zone input { position: absolute; width: 1px; height: 1px; min-height: 0; margin: 0; padding: 0; opacity: 0; overflow: hidden; }
.pdf-drop-zone strong { color: var(--text); font-family: Montserrat, Figtree, sans-serif; font-size: 1rem; }
.pdf-drop-zone span, .pdf-drop-zone small { color: var(--muted-text); font-weight: 500; }
.pdf-selection { margin: .65rem 0 0; color: var(--turquoise-deep); font-size: .85rem; overflow-wrap: anywhere; }
.job-document-list { display: grid; gap: .55rem; margin: 1rem 0 0; padding: 0; list-style: none; }
.job-document-list li { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .8rem 1rem; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); }
.job-document-list li > span:first-child { display: grid; gap: .2rem; min-width: 0; }
.job-document-list strong { overflow-wrap: anywhere; }
.job-document-list small { color: var(--muted-text); }
.job-document-actions { display: flex; flex-wrap: wrap; gap: .8rem; flex: 0 0 auto; }
.job-document-actions a { color: var(--turquoise-deep); font-weight: 750; }
.grid { gap: 1rem 1.2rem; }
label { color: var(--text); font-size: .88rem; letter-spacing: .01em; }
input, select, textarea {
  min-height: 46px;
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .72rem .82rem;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--turquoise-deep); background: var(--surface); box-shadow: 0 0 0 4px rgba(114,199,212,.2); }
.actions, .form-actions { display: flex; flex-wrap: wrap; gap: .7rem; align-items: center; }
.actions { margin-bottom: 1.2rem; }
.actions .button:not(.button-ghost),
:root[data-theme="dark"] .actions .button:not(.button-ghost) { color: #fff; }
.actions .button:not(.button-ghost):hover,
:root[data-theme="dark"] .actions .button:not(.button-ghost):hover { color: #fff; }
.form-actions { margin-top: .35rem; }
button, .button {
  min-height: 44px;
  padding: .72rem 1.1rem;
  border-radius: 11px;
  background: var(--navy);
  color: #fff;
  font-weight: 750;
  box-shadow: 0 6px 16px rgba(33,44,84,.16);
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}
button:hover, .button:hover { transform: translateY(-1px); background: #2c3a6d; color: #fff; box-shadow: 0 10px 22px rgba(33,44,84,.22); }
button.has-unsaved-changes { background: #c62828; color: #fff; box-shadow: 0 6px 16px rgba(198,40,40,.28); }
button.has-unsaved-changes:hover { background: #a91f1f; color: #fff; box-shadow: 0 10px 22px rgba(198,40,40,.34); }
.button-secondary { background: var(--turquoise-deep); color: #fff; }
.button-secondary:hover { background: #2c91a2; }
.button-ghost { background: transparent; color: var(--navy); border: 1px solid var(--line); box-shadow: none; }
:root[data-theme="dark"] .button-ghost { color: var(--turquoise); }
.button-ghost:hover { background: var(--surface-soft); color: var(--text); box-shadow: none; }
.muted { color: var(--muted-text); }

.table-scroll { margin-top: .5rem; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.sort-link { color: inherit; text-decoration: none; white-space: nowrap; }
.sort-link:hover { color: var(--accent); text-decoration: underline; }
.sort-link.active { color: var(--accent); }
table { background: var(--surface); color: var(--text); }
th, td { padding: 1rem .9rem; border-bottom-color: var(--line); vertical-align: middle; }
th { background: var(--surface-soft); color: var(--navy); font-family: Montserrat, Figtree, sans-serif; font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; }
:root[data-theme="dark"] th { color: var(--turquoise); }
th a { color: inherit; text-decoration: none; }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: rgba(114,199,212,.09); }
tbody tr:last-child td { border-bottom: 0; }
.jobs-table { min-width: 1110px; }
.jobs-table td:first-child a { color: var(--navy); text-decoration: none; }
:root[data-theme="dark"] .jobs-table td:first-child a { color: var(--turquoise); }
.status-badge { display: inline-flex; align-items: center; min-height: 29px; max-width: 100%; padding: .35rem .65rem; border-radius: 999px; background: #e8eef7; color: #35476f; font-size: .78rem; font-weight: 750; white-space: nowrap; }
.status-badge[data-status="nouveau"] { background: #e2f5f7; color: #176c79; }
.status-badge[data-status="confirme"] { background: #e6f2ff; color: #215f9a; }
.status-badge[data-status="planification"] { background: #f1eaff; color: #67439d; }
.status-badge[data-status="a_facturer"], .status-badge[data-status="bon_commande_demande"] { background: #fff0d6; color: #8a5710; }
.status-badge[data-status="facture"], .status-badge[data-status="paye"] { background: #e5f5e9; color: #26723a; }
.status-badge[data-status="cloture"] { background: #e8ebf0; color: #515c6c; }
.status-badge[data-status="annule"] { background: #fde7e7; color: #a33636; }
.status-badge[data-status="unpaid"] { background: #fff0d6; color: #8a5710; }
.status-badge[data-status="overdue"] { background: #fde7e7; color: #a33636; }
.status-badge[data-status="paid"] { background: #e5f5e9; color: #26723a; }
:root[data-theme="dark"] .status-badge { filter: saturate(.8) brightness(.88); }
.section-heading { scroll-margin-top: 120px; margin: 3.5rem 0 1rem; }
.section-heading h2 { margin: 0; font-size: clamp(1.6rem, 3vw, 2.3rem); }
.section-heading > p:last-child { margin: .35rem 0 0; color: var(--muted-text); }
.error, .success { border-radius: 12px; }
fieldset { border-color: var(--line); border-radius: 12px; }
.clients-table { min-width: 900px; }
.clients-table td:first-child { color: var(--muted-text); font-weight: 750; }
.clients-table td:nth-child(2) a { color: var(--navy); font-weight: 750; text-decoration: none; }
:root[data-theme="dark"] .clients-table td:nth-child(2) a { color: var(--turquoise); }
.summary-card, .profile-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 1.15rem 1.35rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(135deg, var(--surface), var(--surface-soft));
  box-shadow: var(--shadow);
}
.summary-number, .profile-avatar { display: grid; place-items: center; flex: 0 0 auto; width: 54px; height: 54px; border-radius: 15px; background: var(--navy); color: var(--turquoise); font-family: Montserrat, Figtree, sans-serif; font-size: 1.35rem; font-weight: 800; }
.summary-card > span:last-child, .profile-card > span:last-child { display: grid; gap: .15rem; font-weight: 750; }
.summary-card small, .profile-card small { color: var(--muted-text); font-size: .78rem; font-weight: 500; }
.profile-avatar { border-radius: 50%; }
.inline-check, form > label:has(input[type="checkbox"]) { display: flex; align-items: center; gap: .4rem; }
.inline-check input, form > label:has(input[type="checkbox"]) input { display: inline; width: auto; min-height: 0; margin: 0; accent-color: var(--turquoise-deep); }
.client-checkboxes { background: var(--surface-soft); border-radius: 10px; }
.client-checkboxes label { padding: .28rem .35rem; border-radius: 7px; }
.client-checkboxes label:hover { background: rgba(114,199,212,.14); }

.login-shell { display: grid; grid-template-columns: minmax(280px, .9fr) minmax(340px, 1.1fr); align-items: stretch; max-width: 920px; margin: 0 auto; border-radius: 24px; overflow: hidden; box-shadow: var(--shadow-hover); }
.login-brand { display: flex; flex-direction: column; justify-content: space-between; min-height: 420px; padding: 2rem; background: var(--navy); color: #fff; }
.login-brand img { width: 150px; height: 150px; object-fit: cover; border-radius: 24px; }
.login-brand strong { font-family: Montserrat, Figtree, sans-serif; font-size: 1.45rem; }
.login-brand p { margin-bottom: 0; color: rgba(255,255,255,.7); line-height: 1.55; }
.login-form { display: flex; flex-direction: column; justify-content: center; min-height: 420px; margin: 0; border: 0; border-radius: 0; box-shadow: none; }
.login-form button { width: 100%; margin-top: .5rem; }

form h2:first-child { margin-top: 0; }
form + .table-scroll { margin-top: 1.4rem; }

.invoices-table { min-width: 1320px; }
.invoices-table th:nth-child(1), .invoices-table td:nth-child(1) { width: 170px; }
.invoices-table th:nth-child(2), .invoices-table td:nth-child(2) { min-width: 240px; }
.invoices-table th:nth-child(3), .invoices-table td:nth-child(3) { width: 170px; }
.invoices-table th:nth-child(4), .invoices-table td:nth-child(4),
.invoices-table th:nth-child(5), .invoices-table td:nth-child(5) { width: 130px; white-space: nowrap; }
.invoices-table th:nth-child(6), .invoices-table td:nth-child(6),
.invoices-table th:nth-child(7), .invoices-table td:nth-child(7),
.invoices-table th:nth-child(8), .invoices-table td:nth-child(8) { width: 135px; text-align: right; }
.invoices-table th:nth-child(9), .invoices-table td:nth-child(9) { width: 135px; }
.invoice-list-totals { display: grid; grid-template-columns: repeat(5, minmax(150px, 1fr)); gap: .8rem; margin-top: 1rem; }
.invoice-list-totals > div { display: grid; gap: .3rem; padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.invoice-list-totals span { color: var(--muted-text); font-size: .76rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.invoice-list-totals strong { color: var(--text); font-size: 1.15rem; white-space: nowrap; }
.invoice-list-totals .paid-total strong { color: #26723a; }
.invoice-list-totals .unpaid-total strong { color: #a33636; }
.invoice-layout { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(320px, .95fr); gap: 1.2rem; align-items: start; }
.invoice-layout > form { margin: 0; }
.invoice-summary h2 { margin-top: 0; }
.invoice-summary dl { margin: 0; }
.invoice-summary dl > div { display: grid; grid-template-columns: minmax(115px, .35fr) minmax(0, 1fr); gap: 1rem; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.invoice-summary dt { color: var(--muted-text); font-size: .82rem; font-weight: 750; }
.invoice-summary dd { margin: 0; overflow-wrap: anywhere; }
.invoice-totals { display: grid; gap: .55rem; margin-top: 1.2rem; padding: 1rem; border-radius: 13px; background: var(--surface-soft); }
.invoice-totals span { display: flex; justify-content: space-between; gap: 1rem; }
.invoice-totals .grand-total { padding-top: .65rem; border-top: 1px solid var(--line); color: var(--navy); font-size: 1.15rem; font-weight: 800; }
:root[data-theme="dark"] .invoice-totals .grand-total { color: var(--turquoise); }

.finance-filter {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.finance-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin: 1.25rem 0;
}

.finance-kpi,
.finance-year-card {
  display: grid;
  gap: 0.45rem;
  padding: 1.15rem 1.2rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.finance-kpi span,
.finance-year-card span {
  color: var(--muted-text);
  font-size: 0.88rem;
}

.finance-kpi strong,
.finance-year-card strong {
  font-size: clamp(1.25rem, 2vw, 1.8rem);
}

.finance-years {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1.25rem 0;
}

.finance-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.finance-bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--turquoise);
}

.finance-table-wrap {
  margin-top: 1.25rem;
}

.finance-table {
  min-width: 900px;
}

.finance-table th.numeric,
.finance-table td.numeric {
  text-align: right;
  white-space: nowrap;
}

.finance-table thead a {
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
}

.finance-table thead a:hover {
  color: var(--turquoise);
}

.finance-table tfoot td {
  border-top: 2px solid var(--line);
  font-weight: 700;
}

.finance-total {
  color: var(--turquoise);
  font-weight: 800;
}

.finance-note {
  margin-top: 1rem;
  color: var(--muted-text);
  font-size: 0.92rem;
}

@media (max-width: 1100px) {
  .finance-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .site-header { align-items: flex-start; }
  .header-tools { flex-wrap: wrap; }
  .site-header nav { order: 3; width: 100%; justify-content: flex-end; }
  .account-menu { border-left: 0; }
  .invoice-layout { grid-template-columns: 1fr; }
  .invoice-list-totals { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
}

@media (max-width: 760px) {
  .finance-filter,
  .finance-kpis {
    grid-template-columns: 1fr;
  }

  .site-header { position: relative; display: block; padding: .75rem 1rem; }
  .brand img { width: 48px; height: 48px; }
  .header-tools { margin-top: .7rem; display: grid; grid-template-columns: 1fr auto; gap: .6rem; }
  .site-header nav { grid-column: 1 / -1; order: 0; justify-content: flex-start; overflow-x: auto; padding-bottom: .25rem; }
  .site-header nav a { white-space: nowrap; }
  .account-menu { justify-content: flex-start; overflow: hidden; }
  .account-menu a { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .account-menu .logout-link { display: none; }
  main { padding-top: 2rem; }
  .page-heading { margin-bottom: 1.3rem; }
  .form-title small { display: none; }
  .grid { grid-template-columns: 1fr; }
  .actions .button { flex: 1 1 auto; text-align: center; }
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { min-height: 210px; }
  .login-brand img { width: 90px; height: 90px; }
  .login-form { min-height: 360px; }
  .invoice-list-totals { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .invoice-list-totals > div:last-child { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
