/* Ma Compta Photo — mobile first */
:root {
  --bg: #f2f3f5;
  --card: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #111827;
  --accent: #2f6fed;
  --danger: #d92d20;
  --warn: #b54708;
  --ok: #067647;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

button, input, select, textarea, a.btn-secondary {
  font: inherit;
  color: inherit;
}

/* ---------- barre du haut ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.topbar-row + .topbar-row { margin-top: 10px; }
.topbar h1 {
  font-size: 19px;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 9px;
}
.topbar h1 i { font-size: 18px; }
.r-supplier i { font-size: 13.5px; margin-right: 5px; }
#month-select {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-weight: 600;
}
.totals {
  margin: 10px 0 0;
  font-size: 14px;
  color: var(--muted);
}
.totals strong { color: var(--text); }

/* ---------- boutons ---------- */
.btn-primary, .btn-secondary, .btn-danger, .btn-ghost {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-primary i, .btn-secondary i, .btn-danger i { font-size: 15px; }
.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  padding: 10px 11px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { background: #f3f4f6; }
.icon-btn i { font-size: 19px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { opacity: .85; }
.btn-secondary {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
}
.btn-secondary:active { background: #f3f4f6; }
.btn-danger { background: #fff; border: 1px solid #fecdca; color: var(--danger); }
.btn-ghost {
  background: none;
  color: var(--muted);
  padding: 8px 10px;
  font-size: 14px;
}

/* ---------- liste ---------- */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 12px calc(env(safe-area-inset-bottom) + 110px);
}
#receipt-list { list-style: none; margin: 0; padding: 0; }
.receipt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.receipt:active { background: #fafafa; }
.receipt.flash { animation: flash 1.6s ease-out; }
@keyframes flash {
  0% { background: #e8f0fe; }
  100% { background: var(--card); }
}
.r-main { min-width: 0; }
.r-supplier {
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.r-meta {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.r-amounts { text-align: right; flex-shrink: 0; }
.r-ttc { font-weight: 700; font-variant-numeric: tabular-nums; }
.r-tva { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 999px;
  padding: 1px 8px;
  margin-right: 5px;
  vertical-align: 1px;
}
.badge.warn { background: #fef0c7; color: var(--warn); }
.badge.error { background: #fee4e2; color: var(--danger); }

.receipt.error-item { border: 1px solid #fecdca; }
.receipt.error-item .r-supplier { color: var(--danger); }

#empty-state {
  text-align: center;
  color: var(--muted);
  padding: 48px 24px;
}
#empty-state p:first-child { font-weight: 600; color: var(--text); }

/* ---------- file d'attente d'analyse ---------- */
.queue-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #eef4ff;
  border: 1px dashed #b8cdf8;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  font-size: 14.5px;
}
.queue-item.q-error { background: #fef3f2; border-color: #fecdca; }
.queue-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.queue-status { color: var(--muted); font-size: 13px; flex-shrink: 0; }
.spinner {
  width: 18px; height: 18px;
  border: 2.5px solid #b8cdf8;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.queue-dismiss {
  background: none; border: none; color: var(--muted);
  font-size: 18px; cursor: pointer; padding: 2px 6px;
}

/* ---------- boutons flottants ---------- */
.fab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  gap: 10px;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 14px);
  background: linear-gradient(to top, var(--bg) 65%, transparent);
  max-width: 640px;
  margin: 0 auto;
}
.fab-bar .btn-primary { flex: 1.4; padding: 15px; font-size: 16.5px; }
.fab-bar .btn-secondary { flex: 1; padding: 15px; }

/* ---------- panneaux coulissants (édition, réglages) ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(16, 24, 40, .45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
/* indispensable : sans cette règle, display:flex annule l'attribut hidden
   et les panneaux restent affichés en permanence */
.backdrop[hidden], #toast[hidden], #empty-state[hidden] { display: none; }
.sheet {
  background: var(--card);
  width: 100%;
  max-width: 640px;
  max-height: 92dvh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 8px 18px calc(env(safe-area-inset-bottom) + 18px);
  animation: slide-up .22s ease-out;
}
@keyframes slide-up {
  from { transform: translateY(40px); opacity: .6; }
  to { transform: translateY(0); opacity: 1; }
}
.sheet-handle {
  width: 42px; height: 5px;
  border-radius: 999px;
  background: var(--line);
  margin: 6px auto 10px;
}
.sheet h2 { font-size: 17px; margin: 0 0 10px; }
.topbar-actions { display: flex; align-items: center; gap: 2px; }
.key-status {
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  margin: 0 0 12px;
  background: #f3f4f6;
  color: var(--muted);
}
.key-status.key-ok { background: #ecfdf3; color: var(--ok); }
.key-status.key-missing { background: #fffaeb; color: var(--warn); }
.settings-help {
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.5;
  margin: 10px 0 0;
}
.settings-help a { color: var(--accent); }
#f-apikey { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; }
.sheet-error {
  background: #fef3f2;
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  margin: 0 0 10px;
}
.sheet-notes {
  background: #fffaeb;
  color: var(--warn);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  margin: 0 0 10px;
}
.field-row { display: flex; gap: 10px; margin-bottom: 12px; }
.field-row.two .field { flex: 1; }
.field-row.three .field { flex: 1; }
.field { flex: 1; min-width: 0; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}
.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}
.sheet-actions > * { flex: 1; padding: 11px 8px; font-size: 14.5px; }
.sheet-actions.main-actions { margin-top: 14px; }
.sheet-actions.main-actions .btn-primary { flex: 1.6; }

/* ---------- toast ---------- */
#toast {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--primary);
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14.5px;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(16, 24, 40, .25);
  max-width: 90vw;
  text-align: center;
}

/* ---------- page de connexion ---------- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 20px;
}
.login-card {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 30px 26px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.login-logo {
  width: 66px;
  height: 66px;
  margin: 0 auto;
  background: var(--primary);
  color: #fff;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-logo i { font-size: 30px; }
.login-card h1 { font-size: 21px; margin: 8px 0 4px; }
.login-sub { color: var(--muted); font-size: 14.5px; margin: 0 0 18px; }
.login-error {
  background: #fef3f2;
  color: var(--danger);
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
}
.login-card form { text-align: left; }
.login-card label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 12px 0 4px;
}
.login-card input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.login-hint { font-size: 12.5px; color: var(--muted); }
.login-card .btn-primary { width: 100%; margin-top: 18px; padding: 14px; }

@media (min-width: 700px) {
  .topbar { padding-left: calc(50vw - 320px + 16px); padding-right: calc(50vw - 320px + 16px); }
}
