/* =========================================================
   Ma compta — design tokens & styles partagés
   Aesthétique : carnet de comptes — fond crème, encre profonde,
   vert forêt en accent, typographie Fraunces (italique) + Albert Sans
   ========================================================= */

:root {
  /* Couleurs */
  --bg:            #faf7f2;
  --bg-warm:       #f4eee3;
  --surface:       #ffffff;
  --ink:           #1a1814;
  --ink-muted:     #6b6457;
  --line:          #e8e3da;
  --primary:       #2d4a2b;
  --primary-hover: #1f3a1d;
  --primary-soft:  rgba(45, 74, 43, 0.10);
  --accent:        #c8553d;
  --danger:        #b3422f;
  --danger-bg:     #fdf2ee;
  --warning:       #8b6914;
  --warning-bg:    #fef9e7;
  --warning-line:  #f3e8b0;

  /* Forme */
  --radius:        14px;
  --radius-sm:     10px;
  --shadow-sm:     0 1px 2px rgba(26, 24, 20, 0.04);
  --shadow:        0 4px 16px -4px rgba(26, 24, 20, 0.08),
                   0 2px 4px rgba(26, 24, 20, 0.04);
  --shadow-lg:     0 16px 48px -8px rgba(26, 24, 20, 0.18);
}

*, *::before, *::after { box-sizing: border-box; }

/* L'attribut HTML `hidden` doit toujours masquer, même si une règle CSS
   définit display:flex / display:grid sur l'élément. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Albert Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

body {
  background-image:
    radial-gradient(circle at 15% 20%, rgba(200, 85, 61, 0.04) 0%, transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(45, 74, 43, 0.05) 0%, transparent 50%);
  background-attachment: fixed;
  padding-top: env(safe-area-inset-top);
}

/* =====================================================
   Page d'authentification
   ===================================================== */

.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 24px;
  max-width: 440px;
  margin: 0 auto;
}

.brand           { text-align: center; margin-bottom: 36px; }
.brand-mark      {
  font-family: 'Fraunces', Georgia, serif;
  font-style: italic; font-weight: 600;
  font-size: 46px; line-height: 1; margin: 0;
  color: var(--ink); letter-spacing: -0.02em;
}
.brand-mark::first-letter { color: var(--primary); }
.tagline {
  margin: 14px 0 0; color: var(--ink-muted);
  font-size: 14px; letter-spacing: 0.04em; font-style: italic;
}

/* =====================================================
   Cartes & formulaires
   ===================================================== */

.card {
  background: var(--surface);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

.form { display: flex; flex-direction: column; gap: 18px; }

.field { display: flex; flex-direction: column; gap: 6px; }

.field span {
  font-size: 12px; font-weight: 600;
  color: var(--ink-muted); letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: inherit;
  background: var(--bg);
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.field textarea { resize: vertical; min-height: 56px; }

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
  background: var(--surface);
}

.amount-input        { display: flex; gap: 8px; }
.amount-input input  { flex: 1; }
.amount-input select { width: auto; padding-right: 30px; font-weight: 500; }

/* =====================================================
   Boutons
   ===================================================== */

.btn-primary {
  width: 100%; padding: 14px;
  border: none; border-radius: var(--radius-sm);
  background: var(--primary); color: white;
  font-size: 15px; font-weight: 600;
  font-family: inherit; letter-spacing: 0.02em;
  cursor: pointer; margin-top: 6px;
  min-height: 50px;
  transition: background 0.15s, transform 0.05s;
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-primary:hover  { background: var(--primary-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled {
  opacity: 0.55; cursor: not-allowed; transform: none;
}
.btn-primary.as-link { margin-top: 16px; }

.btn-ghost {
  padding: 8px 14px; background: transparent;
  border: 1px solid var(--line); border-radius: 8px;
  color: var(--ink-muted); cursor: pointer;
  font-size: 13px; font-family: inherit; font-weight: 500;
  transition: all 0.15s;
}
.btn-ghost:hover {
  background: var(--bg-warm); color: var(--ink); border-color: var(--ink-muted);
}

.btn-ghost-block {
  width: 100%; padding: 12px;
  background: transparent; border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink); cursor: pointer;
  font-size: 15px; font-family: inherit; font-weight: 500;
  margin-top: 10px; min-height: 48px;
  transition: all 0.15s;
}
.btn-ghost-block:hover {
  background: var(--bg-warm); border-color: var(--ink-muted);
}

.btn-danger {
  flex: 1;
  padding: 12px;
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(179, 66, 47, 0.2);
  border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  min-height: 48px;
  transition: all 0.15s;
}
.btn-danger:hover {
  background: rgba(179, 66, 47, 0.12);
  border-color: var(--danger);
}

.form-actions { display: flex; gap: 10px; margin-top: 6px; }
.form-actions .btn-primary,
.form-actions .btn-ghost-block { flex: 1; margin-top: 0; }

/* =====================================================
   Alertes
   ===================================================== */

.error {
  margin: 0; padding: 10px 12px;
  background: var(--danger-bg); color: var(--danger);
  border-radius: 8px; font-size: 14px; text-align: center;
  border: 1px solid rgba(179, 66, 47, 0.18);
}

.warning {
  margin: 0 0 16px; padding: 10px 12px;
  background: var(--warning-bg); color: var(--warning);
  border-radius: 8px; font-size: 13px; text-align: center;
  border: 1px solid var(--warning-line);
}

/* =====================================================
   Pages authentifiées (capture / comptabilité)
   ===================================================== */

.page {
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.page--with-nav {
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 4px 0;
  margin-bottom: 4px;
}

.topbar h1 {
  margin: 0;
  font-family: 'Fraunces', Georgia, serif;
  font-style: italic; font-weight: 600;
  font-size: 26px; letter-spacing: -0.01em;
  color: var(--ink);
}

/* =====================================================
   Page Capture
   ===================================================== */

.capture-zone { text-align: center; padding: 36px 24px 28px; }
.capture-hero { margin-bottom: 24px; }

.capture-icon {
  width: 76px; height: 76px;
  margin: 0 auto 18px;
  background: var(--bg-warm);
  border: 1px solid var(--line);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--primary);
}
.capture-icon svg { width: 38px; height: 38px; }

.capture-title {
  font-family: 'Fraunces', Georgia, serif;
  font-style: italic; font-size: 24px;
  margin: 0 0 8px;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.preview-thumb {
  display: block; width: 100%;
  max-height: 240px; object-fit: cover;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  background: var(--bg);
  border: 1px solid var(--line);
}

.analyzing { text-align: center; padding: 24px; }

.spinner {
  width: 32px; height: 32px;
  margin: 16px auto;
  border: 3px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.success { text-align: center; padding: 36px 24px; }

.success-icon {
  width: 64px; height: 64px;
  margin: 0 auto 18px;
  background: var(--primary); color: white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; font-weight: 600;
}

.success-title {
  font-family: 'Fraunces', Georgia, serif;
  font-style: italic; font-size: 24px;
  margin: 0 0 6px;
  color: var(--ink);
}

/* =====================================================
   Page Comptabilité — filtres
   ===================================================== */

.filters {
  display: flex; flex-direction: column; gap: 12px;
}

.period-tabs {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  box-shadow: var(--shadow-sm);
}

.period-tab {
  flex: 1;
  padding: 8px 6px;
  background: transparent;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
  transition: all 0.15s;
  min-height: 36px;
}

.period-tab:hover { color: var(--ink); }

.period-tab.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 1px 3px rgba(45, 74, 43, 0.2);
}

.custom-dates {
  display: flex; gap: 10px;
  background: var(--surface);
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}

.field-inline {
  flex: 1;
  display: flex; flex-direction: column; gap: 4px;
}
.field-inline span {
  font-size: 11px;
  font-weight: 600; color: var(--ink-muted);
  letter-spacing: 0.06em; text-transform: uppercase;
}
.field-inline input {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px; font-family: inherit;
  background: var(--bg); color: var(--ink);
}

.search-bar {
  position: relative;
  display: flex; align-items: center;
}

.search-icon {
  position: absolute;
  left: 14px;
  width: 18px; height: 18px;
  color: var(--ink-muted);
  pointer-events: none;
}

.search-bar input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 16px;
  font-family: inherit;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-bar input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.search-bar input::placeholder { color: var(--ink-muted); }

/* =====================================================
   Page Comptabilité — stats
   ===================================================== */

.stats {
  padding: 22px 22px 18px;
}

.stats-total {
  display: flex; flex-direction: column; gap: 2px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}

.stats-label {
  font-size: 11px; font-weight: 600;
  color: var(--ink-muted);
  letter-spacing: 0.1em; text-transform: uppercase;
}

.stats-value {
  font-family: 'Fraunces', Georgia, serif;
  font-style: italic;
  font-size: 38px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

#stats-count { font-size: 13px; }

.top-suppliers {
  display: flex; flex-direction: column; gap: 10px;
}

.top-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 80px;
  gap: 10px;
  align-items: center;
}

.top-supplier-name {
  font-size: 14px;
  color: var(--ink);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  grid-column: 1 / 2;
}

.top-bar-wrap {
  grid-column: 1 / 2;
  height: 4px;
  background: var(--bg-warm);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 2px;
}

.top-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.top-amount {
  grid-column: 2 / 3;
  grid-row: 1 / 3;
  text-align: right;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* =====================================================
   Page Comptabilité — liste groupée
   ===================================================== */

.groups-list {
  display: flex; flex-direction: column; gap: 14px;
}

.group-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  background: var(--bg-warm);
  border-bottom: 1px solid var(--line);
}

.group-supplier {
  margin: 0;
  font-family: 'Fraunces', Georgia, serif;
  font-style: italic;
  font-weight: 600;
  font-size: 19px;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.group-meta {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
}

.group-total {
  font-size: 17px;
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ticket-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ticket-list li + li {
  border-top: 1px solid var(--line);
}

.ticket-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: 15px;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
}

.ticket-row:hover,
.ticket-row:active {
  background: var(--bg-warm);
}

.ticket-date {
  color: var(--ink-muted);
  font-size: 14px;
}

.ticket-amount {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* =====================================================
   Empty state & loading
   ===================================================== */

.loading-card {
  text-align: center;
  padding: 30px 24px;
}

.empty-state {
  text-align: center;
  padding: 40px 24px;
}

.empty-title {
  font-family: 'Fraunces', Georgia, serif;
  font-style: italic;
  font-size: 22px;
  margin: 0 0 8px;
  color: var(--primary);
}

.placeholder { text-align: center; padding: 40px 24px; }
.placeholder-title {
  font-family: 'Fraunces', Georgia, serif;
  font-style: italic;
  font-size: 22px;
  margin: 0 0 12px;
  color: var(--primary);
}
.placeholder p { margin: 6px 0; }

.muted { color: var(--ink-muted); font-size: 14px; }

/* =====================================================
   Modal de détail
   ===================================================== */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(26, 24, 20, 0.5);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-content {
  background: var(--bg);
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.modal-header h2 {
  margin: 0;
  font-family: 'Fraunces', Georgia, serif;
  font-style: italic;
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
}

.modal-close {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-warm);
  border: none;
  border-radius: 50%;
  color: var(--ink-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.modal-close:hover { background: var(--line); color: var(--ink); }
.modal-close svg { width: 18px; height: 18px; }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.photo-wrapper {
  background: var(--bg-warm);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100px;
  max-height: 320px;
}

.photo-wrapper img {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  display: block;
}

.detail-view {
  display: flex;
  flex-direction: column;
}

.detail-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.detail-row:last-child { border-bottom: none; }

.detail-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.detail-value {
  font-size: 16px;
  color: var(--ink);
}

.detail-amount {
  font-family: 'Fraunces', Georgia, serif;
  font-style: italic;
  font-weight: 600;
  font-size: 22px;
  color: var(--primary);
}

.modal-actions {
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 14px 16px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
}

.modal-actions-row {
  display: flex;
  gap: 10px;
}

.modal-actions-row .btn-primary,
.modal-actions-row .btn-ghost-block,
.modal-actions-row .btn-danger {
  margin-top: 0;
  flex: 1;
}

/* =====================================================
   Bottom nav
   ===================================================== */

.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-around;
  padding: 8px 12px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  z-index: 10;
  box-shadow: 0 -2px 8px rgba(26, 24, 20, 0.04);
}

.nav-item {
  flex: 1;
  max-width: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 8px;
  text-decoration: none;
  color: var(--ink-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}

.nav-item svg {
  width: 22px; height: 22px;
  stroke-width: 1.75;
}

.nav-item.active { color: var(--primary); }
.nav-item:active { background: var(--bg-warm); }
