/* ===========================================================
   Compteur Vannes — feuille de style
   Design sobre, gros boutons, usage terrain (gants, faible lumière).
   =========================================================== */

:root {
  --bg: #f2efe9;
  --surface: #ffffff;
  --text: #1c2733;
  --text-muted: #6b7280;
  --border: #e1ddd3;

  --primary: #d9720a;
  --primary-dark: #b25c07;
  --primary-contrast: #ffffff;

  --topbar-bg: #1c2733;
  --topbar-text: #f2efe9;

  --danger: #c0392b;
  --danger-dark: #9c2d21;
  --success: #2e7d4f;

  --radius: 14px;
  --radius-lg: 20px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font-family: inherit;
  touch-action: manipulation;
}

input {
  font-family: inherit;
  user-select: text;
  -webkit-user-select: text;
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  overflow: hidden;
}

.screen[hidden] { display: none; }

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--topbar-bg);
  color: var(--topbar-text);
  padding: calc(var(--safe-top) + 14px) 8px 14px;
  flex-shrink: 0;
}

.topbar--home {
  position: relative;
  justify-content: center;
}

.btn-settings-gear {
  position: absolute;
  right: 8px;
  top: calc(var(--safe-top) + 6px);
}

.brand {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.topbar-title {
  flex: 1;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 4px;
}

.topbar-spacer {
  width: 44px;
  flex-shrink: 0;
}

.btn-icon-only {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--topbar-text);
  font-size: 1.3rem;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon-only:active {
  background: rgba(255, 255, 255, 0.15);
}

.btn-danger-icon { color: #ff8a75; }

/* ---------- Corps d'écran ---------- */

.screen-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.screen-body--center {
  justify-content: flex-start;
  padding-top: 32px;
}

.screen-body--count {
  padding-bottom: calc(14px + var(--safe-bottom));
  gap: 12px;
  overflow: hidden;
}

.foot-note {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.78rem;
  padding: 10px 16px calc(14px + var(--safe-bottom));
}

/* ---------- Boutons génériques ---------- */

.btn {
  border: none;
  border-radius: var(--radius);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform 0.06s ease, filter 0.15s ease;
}

.btn:active { transform: scale(0.97); filter: brightness(0.94); }

.btn-big {
  width: 100%;
  min-height: 76px;
  font-size: 1.15rem;
  padding: 14px 20px;
}

.btn-icon { font-size: 1.3rem; }

.btn-primary {
  background: var(--primary);
  color: var(--primary-contrast);
  box-shadow: 0 3px 0 var(--primary-dark);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
}

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
  min-height: 52px;
  font-size: 1rem;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  min-height: 52px;
  font-size: 1rem;
  box-shadow: 0 3px 0 var(--danger-dark);
}

.btn-menu-item {
  width: 100%;
  margin-top: 10px;
}

.btn-finish {
  width: 100%;
  min-height: 64px;
  flex-shrink: 0;
  background: var(--success);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1.05rem;
  font-weight: 700;
}

.btn-finish:active { transform: scale(0.98); filter: brightness(0.92); }

/* ---------- Accueil : reprise de projet ---------- */

.resume-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 6px;
}

.resume-list-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 4px 2px;
}

.resume-card {
  display: flex;
  align-items: stretch;
  background: #fff7ec;
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  overflow: hidden;
}

.resume-card-main {
  flex: 1;
  text-align: left;
  border: none;
  background: transparent;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.resume-card-name {
  font-weight: 700;
  font-size: 1.02rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.resume-card-total {
  font-size: 0.85rem;
  color: var(--primary-dark);
  font-weight: 600;
}

.resume-card-delete {
  width: 52px;
  flex-shrink: 0;
  border: none;
  background: transparent;
  font-size: 1.15rem;
  color: var(--text-muted);
  border-left: 1px solid var(--border);
}

/* ---------- Nouveau projet ---------- */

.form-new-project {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 8px;
}

.field-label {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}

.field-input {
  width: 100%;
  min-height: 56px;
  font-size: 1.1rem;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.field-input:focus {
  outline: none;
  border-color: var(--primary);
}

.field-help {
  margin: 6px 2px 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.settings-intro {
  margin: 0 0 4px;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.settings-section-title {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 8px 0 -6px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.field-row {
  display: flex;
  gap: 12px;
}

.field-row > div { flex: 1; min-width: 0; }

.devis-project-recap {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-weight: 700;
  text-align: center;
}

/* ---------- Comptage : catégories ---------- */

.categories {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.category-card {
  flex: 1;
  min-height: 0;
  position: relative;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.category-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 44px 4px 16px;
  flex-shrink: 0;
}

.category-label {
  font-weight: 700;
  font-size: 0.98rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-edit-label {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg);
  border-radius: 8px;
  font-size: 1rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.category-tap {
  flex: 1;
  width: 100%;
  border: none;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.category-tap:active { background: var(--bg); }

.category-count {
  font-size: clamp(2.6rem, 14vh, 4.2rem);
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.category-count.flash {
  animation: flashCount 0.22s ease;
}

@keyframes flashCount {
  0% { transform: scale(1.22); color: var(--success); }
  100% { transform: scale(1); color: var(--primary); }
}

.category-minus {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}

.category-minus:active { background: var(--bg); transform: scale(0.94); }

.category-set {
  position: absolute;
  left: 10px;
  bottom: 10px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}

.category-set:active { background: var(--bg); transform: scale(0.94); }

.count-total {
  flex-shrink: 0;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  padding: 2px 0;
}

/* ---------- Historique ---------- */

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

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.history-item-main {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: none;
  background: transparent;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-item-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-item-name {
  font-weight: 700;
  font-size: 1.02rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

.badge--active {
  background: #fff1dc;
  color: var(--primary-dark);
}

.history-item-delete {
  width: 52px;
  flex-shrink: 0;
  border: none;
  background: transparent;
  font-size: 1.1rem;
  color: var(--text-muted);
  border-left: 1px solid var(--border);
}

/* ---------- Détail projet ---------- */

.detail-meta {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.detail-breakdown {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.detail-breakdown-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-weight: 600;
}

.detail-breakdown-count {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.detail-total {
  margin-top: 6px;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 800;
  padding: 14px;
  background: var(--topbar-bg);
  color: var(--topbar-text);
  border-radius: var(--radius);
}

.detail-devis {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-devis-status {
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
  color: var(--text-muted);
  line-height: 1.4;
}

.detail-devis-status--ok { color: var(--success); }
.detail-devis-status--pending { color: var(--primary-dark); }
.detail-devis-status--error { color: var(--danger); }

/* ---------- Aperçu du devis ("devis B") ---------- */

.devis-doc {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.devis-doc-topbar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.devis-doc-number {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.devis-doc-number--pending {
  color: var(--primary-dark);
}

.devis-doc-date {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.devis-doc-parties {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.devis-doc-seller {
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text);
}

.devis-doc-client-box {
  font-size: 0.85rem;
  line-height: 1.5;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.devis-doc-site {
  margin: 0;
  font-weight: 700;
  color: var(--primary-dark);
  font-size: 0.95rem;
}

.devis-doc-product {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.devis-doc-product-head {
  display: flex;
  justify-content: space-between;
  background: var(--topbar-bg);
  color: var(--topbar-text);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 8px 14px;
}

.devis-doc-product-body {
  padding: 12px 14px;
  font-size: 0.9rem;
}

.devis-doc-product-desc {
  margin-top: 8px;
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.devis-doc-product-desc h6 { font-size: 0.82rem; margin: 10px 0 4px; color: var(--text); }
.devis-doc-product-desc ul { margin: 4px 0; padding-left: 18px; }
.devis-doc-product-desc li { margin-bottom: 3px; }

.devis-doc-product-foot {
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.devis-doc-terms {
  font-size: 0.76rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.devis-doc-signature {
  margin-top: 4px;
}

.devis-doc-signature-title {
  text-align: center;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 10px;
}

.devis-doc-signature-box {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 90px;
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.devis-doc-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.95rem;
}

.devis-doc-line-label { color: var(--text-muted); }
.devis-doc-line-value { font-weight: 700; font-variant-numeric: tabular-nums; }

.devis-doc-totals {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.devis-doc-totals .devis-doc-line-value { font-size: 1rem; }

.devis-doc-cee-row .devis-doc-line-value { color: var(--primary); }

.devis-doc-net {
  margin-top: 4px;
  text-align: center;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--success);
  color: #fff;
}

.devis-doc-net-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.9;
}

.devis-doc-net-value {
  font-size: 1.6rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.devis-doc-mention {
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text-muted);
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.devis-doc-missing {
  text-align: center;
  color: var(--text-muted);
  padding: 30px 16px;
  line-height: 1.6;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + var(--safe-bottom));
  background: var(--topbar-bg);
  color: #fff;
  padding: 13px 18px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  z-index: 500;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
}

.toast--visible { opacity: 1; transform: translateY(0); }
.toast--danger { background: var(--danger); }

/* ---------- Modales ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 27, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 600;
  padding: 0;
}

.modal-backdrop[hidden] { display: none; }

.modal {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 22px 20px calc(22px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal[hidden] { display: none; }

.modal-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-text {
  margin: 0;
  color: var(--text-muted);
  white-space: pre-line;
  line-height: 1.4;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.modal-actions .btn { flex: 1; }

/* ---------- Écrans étroits / petites hauteurs ---------- */

@media (max-height: 620px) {
  .category-count { font-size: clamp(2rem, 10vh, 3rem); }
  .btn-big { min-height: 60px; }
}
