* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  background: #f4f4f6;
  color: #222;
  min-height: 100vh;
}

section {
  max-width: 520px;
  margin: 0 auto;
  padding: env(safe-area-inset-top, 16px) 16px 32px;
}

/* Marge basse quand la tabbar est visible, pour eviter le recouvrement. */
body.has-tabbar section.tab-screen {
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
}

h1 {
  font-size: 1.4rem;
  margin: 16px 0 20px;
  color: #1a4d7a;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.topbar h1 { margin: 0; }

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

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: #555;
  font-weight: 500;
}

label[hidden] { display: none; }

label.inline {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  color: #222;
  font-weight: normal;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
select {
  font-size: 1.05rem;
  padding: 11px 12px;
  border: 1px solid #bbb;
  border-radius: 8px;
  background: #fff;
  color: #222;
  width: 100%;
}

input:focus, select:focus {
  outline: 2px solid #1a4d7a;
  outline-offset: -1px;
  border-color: #1a4d7a;
}

input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin: 0;
}

button {
  font-size: 1.05rem;
  padding: 13px 20px;
  border: none;
  border-radius: 8px;
  background: #1a4d7a;
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  margin-top: 6px;
}

button:disabled {
  background: #999;
  cursor: not-allowed;
}

button:active:not(:disabled) {
  background: #123a5c;
}

.link-btn {
  background: none;
  color: #1a4d7a;
  padding: 6px 10px;
  font-size: 0.9rem;
  font-weight: normal;
  margin-top: 0;
}

.link-btn:active:not(:disabled) {
  background: #e6eef5;
}

.error {
  color: #c0392b;
  font-size: 0.9rem;
  margin: 6px 0 0;
}

/* Balance card (ecran Recent) */
.balance-card {
  background: #1a4d7a;
  color: #fff;
  border-radius: 12px;
  padding: 16px 20px;
  margin: 16px 0;
  text-align: center;
  box-shadow: 0 2px 8px rgba(26, 77, 122, 0.25);
}
.balance-label {
  font-size: 0.85rem;
  opacity: 0.85;
  margin-bottom: 4px;
}
.balance-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.balance-value {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  transition: filter 0.15s ease;
}
.balance-value.negative {
  color: #ffb3b3;
}
.balance-value.blurred {
  filter: blur(10px);
  user-select: none;
}
.balance-toggle {
  background: transparent;
  border: none;
  color: #fff;
  padding: 8px;
  cursor: pointer;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
}
.balance-toggle:hover,
.balance-toggle:focus-visible {
  opacity: 1;
  background: rgba(255, 255, 255, 0.12);
  outline: none;
}
.balance-toggle svg {
  width: 22px;
  height: 22px;
}
.balance-toggle .eye-closed {
  display: none;
}
.balance-toggle[aria-pressed="true"] .eye-open {
  display: none;
}
.balance-toggle[aria-pressed="true"] .eye-closed {
  display: inline-block;
}

/* Liste Recent */
.recent-list {
  list-style: none;
  padding: 0;
  margin: 0;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.recent-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 12px 14px;
  border-bottom: 1px solid #eee;
}
.recent-list li:last-child { border-bottom: none; }

/* Swipe-to-action sur les rangees */
.recent-list li.swipe-row {
  display: block;
  padding: 0;
  position: relative;
  overflow: hidden;
}
.swipe-content {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 12px 14px;
  background: #fff;
  position: relative;
  transform: translateX(0);
  transition: transform 0.2s ease;
  touch-action: pan-y;
  z-index: 1;
}
.swipe-content.no-anim { transition: none; }
.swipe-action {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 88px;
  border: none;
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0;
  margin: 0;
  border-radius: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.swipe-action.edit {
  left: 0;
  background: #2d6e3b;
}
.swipe-action.delete {
  right: 0;
  background: #c0392b;
}
.recent-list .rx-label {
  font-weight: 500;
  color: #222;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recent-list .rx-amount {
  font-weight: 600;
  white-space: nowrap;
  align-self: start;
}
.recent-list .rx-amount.debit  { color: #c0392b; }
.recent-list .rx-amount.credit { color: #2d6e3b; }
.recent-list .rx-meta {
  grid-column: 1 / -1;
  font-size: 0.82rem;
  color: #888;
}
.recent-list .rx-empty {
  padding: 24px;
  text-align: center;
  color: #888;
  font-style: italic;
}

/* Enveloppes : liste de cartes */
.env-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.env-card {
  background: #fff;
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border-left: 5px solid #4a90d9;
  cursor: pointer;
}
.env-card:active { background: #f6f8fa; }
.env-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.env-card-name {
  font-weight: 600;
  font-size: 1.05rem;
  color: #222;
}
.env-card-balance {
  font-weight: 700;
  font-size: 1.1rem;
  color: #1a4d7a;
  white-space: nowrap;
}
.env-card-balance.negative { color: #c0392b; }
.env-card-meta {
  font-size: 0.82rem;
  color: #888;
  margin: 4px 0 8px;
}
.env-bar {
  height: 8px;
  background: #eee;
  border-radius: 4px;
  overflow: hidden;
}
.env-bar-fill {
  height: 100%;
  background: #4a90d9;
  transition: width 0.2s ease;
}
.env-bar-fill.warn { background: #d9923c; }
.env-bar-fill.over { background: #c83c3c; }
.env-empty {
  padding: 24px;
  text-align: center;
  color: #888;
  font-style: italic;
}

/* Selecteur periode (historique enveloppe) */
.env-period-selector {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 4px 0 12px;
}
.env-period-year {
  display: flex;
  align-items: center;
  gap: 8px;
}
.env-period-year #env-year-label {
  font-weight: 600;
  font-size: 1.05rem;
  color: #1a4d7a;
  min-width: 60px;
  text-align: center;
}
.period-nav {
  width: 36px;
  height: 36px;
  padding: 0;
  margin: 0;
  background: #fff;
  color: #1a4d7a;
  border: 1px solid #cfd8e0;
  border-radius: 8px;
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.period-nav:active { background: #e6eef5; }
.period-all {
  margin: 0 0 0 auto;
  padding: 8px 14px;
  font-size: 0.85rem;
  background: #fff;
  color: #1a4d7a;
  border: 1px solid #cfd8e0;
  font-weight: 500;
}
.period-all.active {
  background: #1a4d7a;
  color: #fff;
  border-color: #1a4d7a;
}
.env-period-months {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.month-chip {
  flex: 0 0 auto;
  padding: 6px 12px;
  background: #fff;
  color: #555;
  border: 1px solid #cfd8e0;
  border-radius: 16px;
  font-size: 0.85rem;
  font-weight: 500;
  margin: 0;
  cursor: pointer;
}
.month-chip:active { background: #e6eef5; }
.month-chip.active {
  background: #1a4d7a;
  color: #fff;
  border-color: #1a4d7a;
}

/* Historique enveloppe */
.env-summary {
  background: #fff;
  border-radius: 10px;
  padding: 10px 14px;
  margin: 4px 0 12px;
  font-size: 0.85rem;
  color: #444;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.env-summary .env-summary-balance {
  font-weight: 700;
  color: #1a4d7a;
  font-size: 1rem;
}
.env-summary .env-summary-balance.negative { color: #c0392b; }
.env-summary .env-summary-projection {
  font-style: italic;
  color: #888;
  margin-top: 4px;
}
.env-history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.env-history-list li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 4px 10px;
  padding: 10px 14px;
  border-bottom: 1px solid #eee;
  align-items: baseline;
}
.env-history-list li:last-child { border-bottom: none; }
.env-history-list li.virtual { background: #f8f6ee; }
.env-history-list li.future { opacity: 0.55; }
.eh-date {
  font-size: 0.8rem;
  color: #888;
  white-space: nowrap;
}
.eh-main {
  font-size: 0.95rem;
  color: #222;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.eh-amount {
  font-weight: 600;
  white-space: nowrap;
  text-align: right;
}
.eh-amount.debit  { color: #c0392b; }
.eh-amount.credit { color: #2d6e3b; }
.eh-meta {
  grid-column: 2 / 4;
  font-size: 0.78rem;
  color: #888;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.eh-meta .eh-balance {
  font-weight: 600;
  color: #1a4d7a;
}
.eh-meta .eh-balance.negative { color: #c0392b; }

/* Tab bar */
#tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: #fff;
  border-top: 1px solid #ddd;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 5;
}
.tab-btn {
  flex: 1;
  background: none;
  color: #888;
  padding: 8px 4px;
  margin: 0;
  border: none;
  border-radius: 0;
  font-weight: 500;
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}
.tab-btn.active { color: #1a4d7a; }
.tab-btn:active:not(.active) { background: #f0f0f0; }
.tab-icon {
  font-size: 1.5rem;
  line-height: 1;
  font-weight: normal;
}

#toast {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  transform: translateX(-50%);
  background: #2d6e3b;
  color: #fff;
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 0.95rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  z-index: 10;
  animation: toast-in 0.2s ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
