/* SaaS Petits Commerces — styles mobile-first, thèmes Clair / Auto / Sombre */
:root {
  --green: #16a34a;
  --green-dark: #15803d;
  --red: #dc2626;
  --amber: #d97706;
  --radius: 14px;
}
html[data-theme="clair"] {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #eef1f4;
  --text: #17202a; --muted: #5b6b7a; --border: #dde3ea;
  --input-bg: #ffffff; --shadow: 0 2px 10px rgba(20, 30, 40, .08);
}
html[data-theme="sombre"] {
  --bg: #10151b; --surface: #1a212b; --surface-2: #232d3a;
  --text: #eef3f8; --muted: #9db0c2; --border: #2e3a49;
  --input-bg: #141b24; --shadow: 0 2px 10px rgba(0, 0, 0, .4);
}
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #10151b; --surface: #1a212b; --surface-2: #232d3a;
    --text: #eef3f8; --muted: #9db0c2; --border: #2e3a49;
    --input-bg: #141b24; --shadow: 0 2px 10px rgba(0, 0, 0, .4);
  }
}
@media (prefers-color-scheme: light) {
  html[data-theme="auto"] {
    --bg: #f6f7f9; --surface: #ffffff; --surface-2: #eef1f4;
    --text: #17202a; --muted: #5b6b7a; --border: #dde3ea;
    --input-bg: #ffffff; --shadow: 0 2px 10px rgba(20, 30, 40, .08);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  padding-bottom: 84px;
}
h1 { font-size: 1.35rem; margin: .2rem 0 .6rem; }
h2 { font-size: 1.1rem; margin: 1.1rem 0 .5rem; }
h3 { font-size: 1rem; margin: .9rem 0 .4rem; }
.muted { color: var(--muted); font-size: .9rem; }
.small { font-size: .82rem; }

/* Barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  padding: .55rem .8rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .55rem; min-width: 0; }
.brand-icon { width: 36px; height: 36px; border-radius: 9px; }
.brand-name { font-weight: 700; font-size: .95rem; white-space: nowrap; }
.brand-sub { color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 38vw; }
.theme-toggle { display: flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px; }
.theme-toggle button {
  border: 0; background: transparent; color: var(--muted);
  font-size: .75rem; padding: .3rem .55rem; border-radius: 999px; cursor: pointer;
}
.theme-toggle button.active { background: var(--green); color: #fff; font-weight: 600; }

.banner { margin: .7rem .8rem 0; padding: .6rem .8rem; border-radius: var(--radius); font-size: .88rem; }
.banner-warn { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }

/* Vues */
.view { padding: .9rem .8rem 1.2rem; max-width: 760px; margin: 0 auto; }
.auth-wrap { padding: 1.2rem .8rem; max-width: 460px; margin: 0 auto; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow);
  margin-bottom: .8rem;
}
.auth-switch { text-align: center; margin: .8rem 0 0; }
.linklike { background: none; border: 0; color: var(--green-dark); font-size: .92rem; cursor: pointer; text-decoration: underline; }
.form-msg { min-height: 1.2em; font-size: .9rem; }
.form-msg.error { color: var(--red); }
.form-msg.ok { color: var(--green-dark); }

/* Formulaires */
form label { display: block; font-size: .88rem; color: var(--muted); margin-bottom: .65rem; }
input, select, textarea {
  display: block; width: 100%; margin-top: .25rem;
  padding: .6rem .7rem; font-size: 1rem; color: var(--text);
  background: var(--input-bg); border: 1px solid var(--border); border-radius: 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green); outline-offset: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
@media (max-width: 420px) { .row2 { grid-template-columns: 1fr; } }

/* Boutons */
.btn {
  display: inline-block; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); padding: .55rem .9rem; border-radius: 10px;
  font-size: .95rem; cursor: pointer; text-align: center;
}
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.btn-primary:active { background: var(--green-dark); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; padding: .75rem; }
.btn-small { padding: .35rem .6rem; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: default; }

/* Statistiques accueil */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem; box-shadow: var(--shadow); }
.stat .stat-label { color: var(--muted); font-size: .8rem; }
.stat .stat-value { font-size: 1.35rem; font-weight: 700; margin-top: .2rem; }
.stat.alert .stat-value { color: var(--red); }

/* Listes */
.list { display: flex; flex-direction: column; gap: .6rem; }
.item {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .75rem .85rem; box-shadow: var(--shadow);
}
.item.low { border-color: var(--red); }
.item .item-top { display: flex; justify-content: space-between; gap: .6rem; align-items: baseline; }
.item .item-title { font-weight: 600; }
.item .item-amount { font-weight: 700; white-space: nowrap; }
.item .item-meta { color: var(--muted); font-size: .83rem; margin-top: .25rem; line-height: 1.45; }
.item .item-actions { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .6rem; }
.badge {
  display: inline-block; font-size: .72rem; font-weight: 600;
  padding: .12rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border);
}
.badge.green { background: #dcfce7; color: #166534; border-color: #86efac; }
.badge.red { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.badge.amber { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.empty { text-align: center; color: var(--muted); padding: 1.4rem .5rem; }

/* Navigation bas */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav button {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  font-size: .68rem; padding: .45rem 0 .5rem; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.bottom-nav .nav-ico { font-size: 1.05rem; line-height: 1; }
.bottom-nav button.active { color: var(--green-dark); font-weight: 700; }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 92px; z-index: 30; max-width: 92vw;
  background: #17202a; color: #fff; padding: .6rem .9rem; border-radius: 999px;
  font-size: .9rem; box-shadow: var(--shadow); text-align: center;
}
.toast.error { background: var(--red); }

.section-head { display: flex; justify-content: space-between; align-items: center; gap: .6rem; }
details.card summary { cursor: pointer; font-weight: 600; }
details.card form { margin-top: .8rem; }
