:root {
  --bg: #f4f6f8;
  --card-bg: #ffffff;
  --border: #e3e6ea;
  --text: #101828;
  --text-muted: #667085;
  --primary: #0e7c86;
  --primary-dark: #095a62;

  --red-bg: #fee2e2;
  --red-text: #b91c1c;
  --blue-bg: #dbeafe;
  --blue-text: #1d4ed8;
  --green-bg: #dcfce7;
  --green-text: #15803d;

  color-scheme: light;
}

* { box-sizing: border-box; }

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

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: 32px;
}

/* ---------- Header / bloc trésorerie ---------- */

.balance-header {
  background: linear-gradient(160deg, var(--primary), var(--primary-dark));
  color: #fff;
  padding: max(20px, env(safe-area-inset-top)) 20px 28px;
  border-radius: 0 0 24px 24px;
}

.balance-header .label {
  font-size: 0.85rem;
  opacity: 0.85;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.balance-header .amount {
  font-size: 2.6rem;
  font-weight: 700;
  margin-top: 6px;
  letter-spacing: -0.02em;
  word-break: break-word;
}

.balance-header .accounts-count {
  font-size: 0.85rem;
  opacity: 0.8;
  margin-top: 4px;
}

/* ---------- Cartes ---------- */

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  margin: 16px;
  padding: 16px;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
}

.card-title .icon { font-size: 1.1rem; }

.card-total {
  font-size: 1.8rem;
  font-weight: 700;
  margin-top: 6px;
}

.card-sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}

.recap-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  gap: 10px;
}

.recap-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
  color: var(--text);
}

.recap-row.sub .recap-label {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding-left: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.badge.red { background: var(--red-bg); color: var(--red-text); }
.badge.blue { background: var(--blue-bg); color: var(--blue-text); }
.badge.green { background: var(--green-bg); color: var(--green-text); }

.recap-amount {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}

/* ---------- Liste fournisseurs ---------- */

.section-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 24px 16px 8px;
}

.search-wrap {
  position: relative;
  margin: 0 16px 10px;
}

.search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  opacity: 0.6;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 11px 14px 11px 38px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-size: 0.95rem;
  color: var(--text);
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 124, 134, 0.15);
}

.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.supplier-list {
  margin: 0 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}

.supplier-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.supplier-row:last-child { border-bottom: none; }
.supplier-row:active { background: var(--bg); }

.supplier-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.supplier-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.supplier-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.chevron { color: var(--text-muted); }

/* ---------- Header de navigation (détail fournisseur) ---------- */

.nav-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(16px, env(safe-area-inset-top)) 16px 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

.back-btn {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
}

.nav-title {
  font-size: 1.15rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Liste de factures ---------- */

.invoice-list {
  margin: 8px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.invoice-row {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
}

.invoice-row:active { background: var(--bg); }

.invoice-info { min-width: 0; }

.invoice-amount {
  font-weight: 700;
  font-size: 1.05rem;
}

.invoice-due {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 3px;
}

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

.state-msg {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 0.95rem;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}

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

/* ---------- Visionneuse de document ---------- */

.viewer-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 50;
  display: flex;
  flex-direction: column;
}

.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: max(14px, env(safe-area-inset-top)) 14px 12px;
  background: #111;
  color: #fff;
}

.viewer-title {
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-close {
  background: rgba(255,255,255,0.12);
  border: none;
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 1.1rem;
  cursor: pointer;
}

.viewer-body {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1a1a1a;
}

.viewer-body iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.viewer-body img {
  max-width: 100%;
  max-height: 100%;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #101828;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 0.88rem;
  z-index: 60;
}
