/* Tri de factures — système de design partagé.
   Registre : outil comptable professionnel. Cartes nettes, chiffres
   tabulaires, statuts de fiabilité en badges sobres. Rien de ludique —
   l'objectif est la confiance immédiate d'un expert-comptable. */

:root {
  --ink: #0f172a;
  --ink-70: rgba(15, 23, 42, 0.82);
  --ink-45: rgba(15, 23, 42, 0.64);
  --ink-20: rgba(15, 23, 42, 0.16);
  --ink-10: rgba(15, 23, 42, 0.08);

  --paper: #eef1f7;
  --paper-deep: #dfe5f0;
  --surface: #ffffff;

  --accent: #2354d6;
  --accent-deep: #1a3fa8;
  --accent-bright: #4d7dff;
  --accent-soft: #e6ecfc;

  --sage: #157a5f;
  --sage-soft: #e1f3ec;

  --rust: #b7261f;
  --rust-soft: #fbe8e6;

  --gold: #a8710a;
  --gold-soft: #fbeed4;

  --font-display: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  --font-body: "Work Sans", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "Space Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 7px;

  --shadow-card: 0 2px 4px rgba(15, 23, 42, 0.06), 0 12px 28px -12px rgba(15, 23, 42, 0.22);
  --shadow-pop: 0 4px 8px rgba(15, 23, 42, 0.10), 0 20px 40px -16px rgba(15, 23, 42, 0.32);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  background:
    radial-gradient(1100px 420px at 50% -180px, rgba(35, 84, 214, 0.16), transparent 70%),
    var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px 64px;
}

.page--narrow { max-width: 420px; }

/* --- En-tête --------------------------------------------------------- */

.app-header {
  background: linear-gradient(120deg, #0b1327 0%, #14213f 45%, #1a3fa8 130%);
  color: #fff;
  padding: 18px 16px;
  margin-bottom: 28px;
  border-bottom: 3px solid var(--accent-bright);
  box-shadow: 0 16px 32px -18px rgba(15, 23, 42, 0.55);
}

.app-header__row {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  row-gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #fff;
}

.brand__mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent-bright), var(--accent-deep));
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.02em;
  flex-shrink: 0;
  box-shadow: 0 6px 14px -4px rgba(35, 84, 214, 0.65);
}

.brand__name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.app-header nav {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
}

.app-header nav a {
  text-decoration: none;
  color: rgba(255, 255, 255, 0.82);
}
.app-header nav a:hover { color: #fff; }

.icon-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: rgba(255, 255, 255, 0.85);
  font-family: var(--font-body);
  font-size: 12.5px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.icon-btn:hover { border-color: #fff; color: #fff; }

.app-header__actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-btn--accent {
  background: var(--accent-bright);
  border-color: var(--accent-bright);
  color: #fff;
  font-weight: 600;
}
.icon-btn--accent:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* --- Typo générale ----------------------------------------------------- */

h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
  color: var(--ink);
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-45);
}

.subtitle {
  color: var(--ink-70);
  font-size: 13.5px;
  margin-bottom: 4px;
}

/* --- Cartes génériques --------------------------------------------------- */

.panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--ink-10);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}

/* --- Flash messages ------------------------------------------------------ */

.flash {
  background: var(--accent-soft);
  color: var(--accent-deep);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 14px;
  font-weight: 500;
  border: 1px solid rgba(35, 84, 214, 0.18);
}
.flash--error { background: var(--rust-soft); color: var(--rust); border-color: rgba(183, 38, 31, 0.2); }

/* --- Boutons -------------------------------------------------------------- */

.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  transition: transform 0.12s ease, background-color 0.12s ease, box-shadow 0.12s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:disabled:active { transform: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 16px -6px rgba(35, 84, 214, 0.45);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-deep); }

.btn-ink {
  background: var(--ink);
  color: #fff;
}
.btn-ink:hover:not(:disabled) { background: #1e293b; }

.btn-ghost {
  background: transparent;
  color: var(--ink-70);
  border: 1px solid var(--ink-20);
}
.btn-ghost:hover { border-color: var(--ink-45); color: var(--ink); }

.btn-danger-ghost {
  background: transparent;
  color: var(--rust);
  border: 1px solid rgba(183, 38, 31, 0.3);
}
.btn-danger-ghost:hover { background: var(--rust-soft); }

.btn-block { width: 100%; }

/* Focus visible partout — accessibilité */
a:focus-visible, button:focus-visible, input:focus-visible, label:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Formulaires ------------------------------------------------------- */

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-70);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field input[type="text"],
.field input[type="password"] {
  width: 100%;
  box-sizing: border-box;
  padding: 12px 14px;
  border: 1.5px solid var(--ink-20);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 16px;
  background: var(--surface);
  color: var(--ink);
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* --- Zone d'import -------------------------------------------------------- */

.upload-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 19px;
  background: linear-gradient(120deg, var(--accent-deep), var(--accent) 60%, var(--accent-bright));
  color: #fff;
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 14px 28px -12px rgba(35, 84, 214, 0.55);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.upload-tile:hover { box-shadow: 0 18px 34px -12px rgba(35, 84, 214, 0.65); }
.upload-tile:active { transform: scale(0.99); }
.upload-tile__icon { font-size: 20px; line-height: 1; opacity: 0.9; }

.upload-secondary {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--ink-10);
}
.upload-secondary input[type="file"] {
  flex: 1;
  min-width: 160px;
  font-size: 12.5px;
  color: var(--ink-70);
}

/* --- Cartes pièce comptable ------------------------------------------------------- */

.receipt-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.receipt-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--ink-10);
  border-left: 5px solid var(--accent);
  overflow: hidden;
}
.receipt-card--certain { border-left-color: var(--sage); }
.receipt-card--deduit { border-left-color: var(--gold); }
.receipt-card--ambigu { border-left-color: var(--rust); }

.receipt-card__head {
  padding: 16px 18px 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.receipt-card__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  color: var(--ink);
  line-height: 1.25;
}

.receipt-card__file {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-45);
  margin-top: 3px;
  word-break: break-all;
}

/* Séparateur net entre l'en-tête de la pièce et le détail des champs */
.receipt-card__perf {
  border-top: 1px solid var(--ink-10);
  margin: 0 18px;
}

.receipt-card__rows { padding: 12px 18px 4px; }

.receipt-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(15, 23, 42, 0.045);
}
.receipt-row:last-child { border-bottom: none; }

.receipt-row__label {
  font-size: 12px;
  color: var(--ink-45);
  flex-shrink: 0;
}

.receipt-row__value-wrap {
  text-align: right;
  min-width: 0;
}

.receipt-row__chip { display: inline-flex; margin-top: 4px; }

.total-value {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  max-width: 100%;
}

.visually-hidden-file {
  position: absolute;
  left: -9999px;
}

.receipt-row__value {
  font-family: var(--font-mono);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.receipt-row__note {
  display: block;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 400;
  font-style: italic;
  color: var(--ink-45);
  margin-top: 2px;
  max-width: 240px;
  text-align: right;
  margin-left: auto;
}

.receipt-card__total {
  margin: 4px 18px 0;
  padding: 14px 0 16px;
  border-top: 1.5px solid var(--ink-10);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.receipt-card__total-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  color: var(--ink-70);
  white-space: nowrap;
  padding-top: 3px;
  flex-shrink: 0;
}

.receipt-card__total-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 22px;
  color: var(--accent-deep);
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.receipt-card__error {
  padding: 16px 18px 18px;
  color: var(--rust);
  font-size: 13.5px;
}

/* Chip discret — statut d'un champ secondaire */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 3px 8px;
  border-radius: 999px;
}
.chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.85);
}
.chip--certain { color: #fff; background: var(--sage); box-shadow: 0 2px 6px -2px rgba(21, 122, 95, 0.55); }
.chip--deduit { color: #fff; background: var(--gold); box-shadow: 0 2px 6px -2px rgba(168, 113, 10, 0.55); }
.chip--ambigu { color: #fff; background: var(--rust); box-shadow: 0 2px 6px -2px rgba(183, 38, 31, 0.55); }

/* Statut du total — même famille de badge que .chip, en plus affirmé */
.stamp {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  flex-shrink: 0;
  color: #fff;
}
.stamp--certain { background: var(--sage); box-shadow: 0 4px 10px -4px rgba(21, 122, 95, 0.6); }
.stamp--deduit { background: var(--gold); box-shadow: 0 4px 10px -4px rgba(168, 113, 10, 0.6); }
.stamp--ambigu { background: var(--rust); box-shadow: 0 4px 10px -4px rgba(183, 38, 31, 0.6); }

/* --- Cartes "envoi" (archives) -------------------------------------------- */

.envoi-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.envoi-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--ink-10);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.envoi-card__date {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14.5px;
}

.envoi-card__meta {
  font-size: 12px;
  color: var(--ink-45);
  margin-top: 2px;
}

.envoi-card__total {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 16.5px;
  margin-right: 6px;
  font-variant-numeric: tabular-nums;
}

.envoi-card__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.link-action {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent-deep);
  text-decoration: none;
  border-bottom: 1.5px solid var(--accent);
  padding-bottom: 1px;
}
.link-action:hover { color: var(--accent); }

/* --- États vides ------------------------------------------------------- */

.empty-state {
  text-align: center;
  padding: 36px 20px;
  color: var(--ink-70);
}
.empty-state__icon {
  font-size: 28px;
  margin-bottom: 10px;
  display: block;
  opacity: 0.55;
}
.empty-state__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15.5px;
  color: var(--ink);
  margin-bottom: 4px;
}
.empty-state__hint {
  font-size: 13px;
  color: var(--ink-45);
  max-width: 320px;
  margin: 0 auto;
}

/* --- Divers -------------------------------------------------------------- */

.actions-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.hint {
  font-size: 12px;
  color: var(--ink-45);
  margin-top: 10px;
  line-height: 1.5;
}

.footer-note {
  font-size: 11.5px;
  color: var(--ink-45);
  margin-top: 24px;
  text-align: center;
  line-height: 1.6;
}

/* --- Connexion ----------------------------------------------------------- */

.login-hero {
  text-align: center;
  padding: 44px 24px 32px;
  margin: 24px 0 20px;
  border-radius: 22px;
  background: linear-gradient(150deg, #0b1327 0%, #14213f 50%, #1a3fa8 140%);
  box-shadow: 0 20px 40px -20px rgba(15, 23, 42, 0.5);
}
.login-hero .brand__mark {
  width: 56px;
  height: 56px;
  border-radius: 15px;
  font-size: 20px;
  margin: 0 auto 18px;
  color: #fff;
  box-shadow: 0 10px 22px -6px rgba(35, 84, 214, 0.7);
}
.login-hero h1 { font-size: 22px; color: #fff; }
.login-hero p {
  color: rgba(255, 255, 255, 0.92);
  font-weight: 600;
  font-size: 14px;
  line-height: 1.5;
  max-width: 300px;
  margin: 10px auto 0;
}

/* --- Animation d'entrée douce (respecte prefers-reduced-motion) ---------- */

@media (prefers-reduced-motion: no-preference) {
  .receipt-card, .envoi-card, .panel {
    animation: rise 0.3s ease both;
  }
  .receipt-list .receipt-card:nth-child(n) { animation-delay: calc(var(--i, 0) * 35ms); }
  @keyframes rise {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
  }
}

/* --- Petit mobile : header resserré, le repère "TF" suffit --------------- */

@media (max-width: 420px) {
  .brand__name { display: none; }
  .app-header__row { gap: 8px; }
  .app-header nav { gap: 8px; }
}

/* --- Modale d'installation (instructions iPhone/Safari) ------------------ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-overlay[hidden] { display: none; }

.modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow-pop);
}
.modal-card__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  color: var(--ink);
  margin: 0 0 12px;
}
.modal-card p {
  font-size: 13.5px;
  color: var(--ink-70);
  margin: 0 0 10px;
}
.modal-card .btn { margin-top: 6px; }

/* --- Desktop : un peu plus d'air, grille 2 colonnes pour les pièces -------- */

@media (min-width: 720px) {
  .page { padding-left: 24px; padding-right: 24px; }
  .receipt-list { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .receipt-list > *:only-child { grid-column: 1 / -1; max-width: 380px; }
  .envoi-card { padding: 18px 22px; }
}
