/* ── POLICES AUTO-HÉBERGÉES (variables) ── */
@font-face {
  font-family: 'Syne';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url(fonts/syne-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Syne';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url(fonts/syne-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 300 500;
  font-display: swap;
  src: url(fonts/jetbrainsmono-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 300 500;
  font-display: swap;
  src: url(fonts/jetbrainsmono-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --bg: #0f1117;
  --surface: #171b25;
  --surface2: #1e2436;
  --border: #2a3050;
  --accent: #4fd1c5;
  --accent2: #7c6af5;
  --positive: #4fd1c5;
  --negative: #f87171;
  --text: #e2e8f0;
  --text-muted: #64748b;
  --label: #94a3b8;
  --highlight: #fbbf24;
  --group1: rgba(124, 106, 245, 0.08);
  --group2: rgba(79, 209, 197, 0.08);
  --groupd: rgba(248, 113, 113, 0.08);
  --radius: 10px;
  --transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  font-family: 'Syne', sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
  padding-top: max(2rem, env(safe-area-inset-top));
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

/* ── PWA STANDALONE MODE ── */
@media (display-mode: standalone) {
  body {
    padding-top: max(1rem, env(safe-area-inset-top));
  }

  #app-card {
    border-radius: 12px;
  }
}

/* Pull-to-refresh prevention in standalone */
html {
  overscroll-behavior: none;
}

/* ── SR-ONLY (accessibilité) ── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── WRAPPER ── */
#app-wrapper {
  position: relative;
  width: 100%;
  max-width: 580px;
}

@media (min-width: 768px) {
  #app-wrapper {
    max-width: 680px;
  }
}

@media (min-width: 1200px) {
  #app-wrapper {
    max-width: 780px;
  }
}

#minimized-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1.25rem;
  cursor: pointer;
  user-select: none;
  transition: border-color var(--transition);
}

#minimized-bar:hover {
  border-color: var(--accent);
}

#minimized-bar span {
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
}

#minimized-bar .mini-total {
  color: var(--accent);
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
}

/* ── CARTE PRINCIPALE ── */
#app-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.03);
  transition: opacity var(--transition), transform var(--transition);
}

/* ── HEADER ── */
.app-header {
  background: linear-gradient(135deg, #1a1f35 0%, #0f1117 100%);
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
}

/* ── EDITABLE INPUT (classe commune) ── */
.editable-input {
  background: none;
  border: none;
  outline: none;
  font-family: 'Syne', sans-serif;
  cursor: text;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background var(--transition);
}

.editable-input:hover {
  background: rgba(255, 255, 255, 0.05);
}

.editable-input:focus {
  background: rgba(255, 255, 255, 0.07);
}

.app-title-editable {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: 0.02em;
  min-width: 10px;
  width: 100%;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.35rem 0.5rem;
  font-size: 0.8rem;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-family: 'Syne', sans-serif;
  font-weight: 600;
}

.btn-icon:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(79, 209, 197, 0.08);
}

.btn-icon:focus-visible,
.lock-dialog-btn:focus-visible,
.lock-btn:focus-visible,
.btn-export:focus-visible,
.btn-import:focus-visible,
.btn-lock-app:focus-visible,
.add-row-btn:focus-visible,
.btn-clear:focus-visible,
.btn-remove-row:focus-visible,
.group-header:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-icon.active {
  border-color: var(--accent2);
  color: var(--accent2);
  background: rgba(124, 106, 245, 0.12);
}

.btn-icon:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.datetime {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.datetime span {
  color: var(--accent);
}

/* ── CONTENU ── */
.app-body {
  padding: 1rem 0 0.5rem;
}

/* ── LIGNE TITRE 1 ── */
.title1-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1.5rem;
  background: linear-gradient(90deg, rgba(251, 191, 36, 0.1) 0%, transparent 100%);
  border-left: 3px solid var(--highlight);
  margin: 0 0 0.75rem;
}

.title1-label-input {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--highlight);
}

/* ── LIGNE CHAMP 3 (standalone) ── */
.title3-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1.5rem;
  background: linear-gradient(90deg, rgba(79, 209, 197, 0.1) 0%, transparent 100%);
  border-left: 3px solid var(--accent);
  margin: 0.5rem 0 0;
}

.title3-label-input {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
}

/* ── GROUPES ── */
.group {
  margin: 0.5rem 0;
  border-radius: var(--radius);
  overflow: hidden;
}

.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1.5rem;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
  position: relative;
}

.group-header:hover {
  background: rgba(255, 255, 255, 0.03);
}

.group-1 .group-header {
  background: rgba(124, 106, 245, 0.06);
}

.group-1 .group-header:hover {
  background: rgba(124, 106, 245, 0.1);
}

.group-2 .group-header {
  background: rgba(79, 209, 197, 0.06);
}

.group-2 .group-header:hover {
  background: rgba(79, 209, 197, 0.1);
}

.group-d .group-header {
  background: rgba(248, 113, 113, 0.06);
}

.group-d .group-header:hover {
  background: rgba(248, 113, 113, 0.1);
}

.group-header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.group-name-input {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  width: 100%;
  min-width: 10px;
}

.group-1 .group-name-input {
  color: var(--accent2);
}

.group-2 .group-name-input {
  color: var(--accent);
}

.group-d .group-name-input {
  color: var(--negative);
}

.group-subtotal {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: auto;
  margin-right: 0.75rem;
  white-space: nowrap;
  transition: color var(--transition);
}

.group-subtotal.positive {
  color: var(--positive);
}

.group-subtotal.negative {
  color: var(--negative);
}

.group-chevron {
  font-size: 0.7rem;
  transition: transform var(--transition);
  color: var(--text-muted);
  flex-shrink: 0;
}

.group-header.collapsed .group-chevron {
  transform: rotate(-90deg);
}

.group-body {
  overflow: hidden;
  max-height: 2000px;
  transition: max-height 0.45s cubic-bezier(0, 1, 0, 1);
}

.group-body.collapsed {
  max-height: 0;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── LIGNES ── */
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  padding: 0.5rem 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  transition: background var(--transition);
}

.row:hover {
  background: rgba(255, 255, 255, 0.02);
}

.group-1 .row {
  background: var(--group1);
}

.group-1 .row:hover {
  background: rgba(124, 106, 245, 0.12);
}

.group-2 .row {
  background: var(--group2);
}

.group-2 .row:hover {
  background: rgba(79, 209, 197, 0.12);
}

.group-d .row {
  background: var(--groupd);
}

.group-d .row:hover {
  background: rgba(248, 113, 113, 0.12);
}

.row-label {
  font-size: 0.88rem;
  font-weight: 400;
  color: var(--label);
  flex: 1;
  min-width: 10px;
  width: 100%;
  transition: background var(--transition), color var(--transition);
}

.row-label:hover {
  color: var(--text);
}

.row-label:focus {
  color: var(--text);
}

.row-value {
  background: none;
  border: none;
  outline: none;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.92rem;
  font-weight: 400;
  text-align: right;
  width: 130px;
  flex-shrink: 0;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: all var(--transition);
  color: var(--text);
}

.row-value:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border);
}

.row-value:focus {
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--accent);
}

.row-value.negative {
  color: var(--negative);
}

.row-value.positive {
  color: var(--positive);
}

/* ── BOUTON EFFACEMENT ── */
.btn-clear {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.7rem;
  padding: 4px 6px;
  border-radius: 4px;
  opacity: 0.35;
  transition: all var(--transition);
  flex-shrink: 0;
  line-height: 1;
}

.btn-clear:hover {
  opacity: 1;
  color: var(--negative);
  background: rgba(248, 113, 113, 0.15);
}

@media (max-width: 480px) {
  .btn-clear {
    opacity: 0.5;
    padding: 4px 8px;
    font-size: 0.8rem;
  }
}

/* ── TOTAL ── */
.total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  margin: 0.5rem 0 0;
  border-top: 1px solid var(--border);
  background: linear-gradient(90deg, rgba(79, 209, 197, 0.06) 0%, transparent 100%);
}

.total-label {
  font-family: 'Syne', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}

.total-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--accent);
  transition: color var(--transition);
}

.total-value.negative {
  color: var(--negative);
}

.total-value.positive {
  color: var(--positive);
}

/* ── SOUS-TOTAL CHAMP 1 + CHAMP 2 ── */
.subtotal-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  margin: 0.5rem 0 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, rgba(124, 106, 245, 0.05) 0%, rgba(79, 209, 197, 0.05) 100%);
}

.subtotal-label {
  font-family: 'Syne', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--label);
  letter-spacing: 0.02em;
}

.subtotal-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
  font-weight: 500;
  color: var(--accent2);
  transition: color var(--transition);
}

.subtotal-value.negative {
  color: var(--negative);
}

.subtotal-value.positive {
  color: var(--accent);
}

/* ── DIVISION ── */
.divide-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: linear-gradient(90deg, rgba(124, 106, 245, 0.04) 0%, transparent 100%);
  gap: 0.75rem;
}

.divide-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: 'Syne', sans-serif;
  font-size: 0.88rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.divide-input {
  background: none;
  border: none;
  outline: none;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  color: var(--accent2);
  text-align: center;
  width: 55px;
  padding: 3px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.divide-input:hover {
  border-color: var(--accent2);
}

.divide-input:focus {
  border-color: var(--accent2);
  background: rgba(124, 106, 245, 0.08);
}

.divide-result {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--accent2);
  white-space: nowrap;
  transition: color var(--transition);
}

.divide-result.negative {
  color: var(--negative);
}

/* ── LABEL COMMUN ── */
.field-label {
  font-family: 'Syne', sans-serif;
  font-size: 0.88rem;
  color: var(--label);
}

/* ── TOOLBAR BOTTOM ── */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem 1rem;
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.btn-export,
.btn-csv {
  background: rgba(124, 106, 245, 0.1);
  border: 1px solid rgba(124, 106, 245, 0.3);
  border-radius: 6px;
  color: var(--accent2);
  cursor: pointer;
  padding: 0.35rem 0.75rem;
  font-size: 0.78rem;
  font-family: 'Syne', sans-serif;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: all var(--transition);
}

.btn-export:hover,
.btn-csv:hover {
  background: rgba(124, 106, 245, 0.2);
  border-color: var(--accent2);
}

.btn-csv {
  background: rgba(251, 191, 36, 0.08);
  border-color: rgba(251, 191, 36, 0.3);
  color: var(--highlight);
}

.btn-csv:hover {
  background: rgba(251, 191, 36, 0.18);
  border-color: var(--highlight);
}

.btn-import {
  background: rgba(79, 209, 197, 0.08);
  border: 1px solid rgba(79, 209, 197, 0.25);
  border-radius: 6px;
  color: var(--accent);
  cursor: pointer;
  padding: 0.35rem 0.75rem;
  font-size: 0.78rem;
  font-family: 'Syne', sans-serif;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: all var(--transition);
}

.btn-import:hover {
  background: rgba(79, 209, 197, 0.15);
  border-color: var(--accent);
}

/* ── MASQUAGE VALEURS ── */
.values-hidden .row-value,
.values-hidden .total-value,
.values-hidden .title1-value,
.values-hidden .title3-value,
.values-hidden .group-subtotal,
.values-hidden .subtotal-value,
.values-hidden .divide-result,
.values-hidden .divide-input {
  filter: blur(8px);
  user-select: none;
  pointer-events: none;
}

.values-hidden .btn-clear {
  opacity: 0;
  pointer-events: none;
}

/* ── TOOLTIP SAUVEGARDE ── */
.save-indicator {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.5s;
  margin-right: auto;
}

.save-indicator.show {
  opacity: 1;
}

#import-file {
  display: none;
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* ── SW UPDATE BANNER ── */
.sw-update-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: linear-gradient(90deg, rgba(79, 209, 197, 0.12) 0%, rgba(124, 106, 245, 0.12) 100%);
  border-bottom: 1px solid var(--border);
  font-family: 'Syne', sans-serif;
  font-size: 0.8rem;
  color: var(--text);
  animation: slideDown 0.3s ease-out;
}

.sw-update-banner.visible {
  display: flex;
}

.sw-update-banner button {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 4px;
  padding: 0.3rem 0.7rem;
  font-family: 'Syne', sans-serif;
  font-weight: 600;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity var(--transition);
}

.sw-update-banner button:hover {
  opacity: 0.85;
}

@keyframes slideDown {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 1.2rem;
  font-family: 'Syne', sans-serif;
  font-size: 0.85rem;
  color: var(--accent);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s;
  opacity: 0;
  z-index: 1000;
  pointer-events: none;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ── ADD/REMOVE ROW ── */
.add-row-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  width: 100%;
  padding: 0.4rem;
  background: none;
  border: 1px dashed var(--border);
  border-radius: 0;
  color: var(--text-muted);
  font-family: 'Syne', sans-serif;
  font-size: 0.75rem;
  cursor: pointer;
  opacity: 0.4;
  transition: all var(--transition);
}

.add-row-btn:hover {
  opacity: 1;
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(79, 209, 197, 0.05);
}

.drag-handle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: grab;
  font-size: 0.7rem;
  padding: 4px 2px;
  border-radius: 4px;
  opacity: 0.3;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  flex-shrink: 0;
  line-height: 1;
  transition: opacity var(--transition), color var(--transition);
}

.row:hover .drag-handle {
  opacity: 0.6;
}

.drag-handle:hover {
  opacity: 1;
  color: var(--accent);
}

.drag-handle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  opacity: 1;
}

.row.dragging {
  background: rgba(79, 209, 197, 0.1) !important;
  box-shadow: inset 0 0 0 1px var(--accent);
}

.row.dragging .drag-handle {
  cursor: grabbing;
  opacity: 1;
  color: var(--accent);
}

@media (max-width: 480px) {
  .drag-handle {
    opacity: 0.45;
    padding: 6px 4px;
  }
}

.btn-remove-row {
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 4px 8px;
  border-radius: 5px;
  opacity: 0.45;
  transition: all var(--transition);
  flex-shrink: 0;
  line-height: 1;
}

.row:hover .btn-remove-row {
  opacity: 0.75;
}

.btn-remove-row:hover {
  opacity: 1 !important;
  color: var(--negative);
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.15);
}

.btn-remove-row:focus-visible {
  opacity: 1;
}

@media (max-width: 480px) {
  .btn-remove-row {
    opacity: 0.55;
    padding: 6px 9px;
  }
}

/* ── LOCK SCREEN ── */
#lock-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s ease, visibility 0.4s;
}

#lock-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.lock-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem 2rem 2rem;
  width: 90%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.03);
  animation: lockAppear 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes lockAppear {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.lock-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  display: block;
  animation: lockPulse 2s ease-in-out infinite;
}

@keyframes lockPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.lock-title {
  font-family: 'Syne', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.3rem;
}

.lock-subtitle {
  font-family: 'Syne', sans-serif;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.lock-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 1rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
  color: var(--text);
  text-align: center;
  letter-spacing: 0.2em;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  margin-bottom: 0.5rem;
}

.lock-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 209, 197, 0.15);
}

.lock-input.error {
  border-color: var(--negative);
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.15);
  animation: lockShake 0.4s ease;
}

@keyframes lockShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

.lock-btn {
  width: 100%;
  padding: 0.65rem;
  margin-top: 0.5rem;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
  border: none;
  border-radius: 8px;
  font-family: 'Syne', sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--bg);
  cursor: pointer;
  transition: opacity var(--transition), transform var(--transition);
  letter-spacing: 0.03em;
}

.lock-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.lock-btn:active {
  transform: translateY(0);
}

.lock-error-msg {
  font-family: 'Syne', sans-serif;
  font-size: 0.78rem;
  color: var(--negative);
  margin-top: 0.5rem;
  min-height: 1.2em;
  transition: opacity var(--transition);
}

.lock-skip {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: 'Syne', sans-serif;
  font-size: 0.75rem;
  cursor: pointer;
  margin-top: 1rem;
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  transition: color var(--transition);
}

.lock-skip:hover {
  color: var(--text);
}

/* ── MODALES SÉCURITÉ & NOTES ── */
#security-modal-overlay,
#notes-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

#security-modal-overlay.visible,
#notes-modal-overlay.visible {
  display: flex;
}

.lock-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem 1.5rem 1.5rem;
  width: 90%;
  max-width: 340px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.lock-dialog-title {
  font-family: 'Syne', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1rem;
}

.lock-dialog-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.lock-dialog-btn {
  padding: 0.55rem;
  border-radius: 6px;
  font-family: 'Syne', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid var(--border);
}

.lock-dialog-btn.primary {
  background: rgba(79, 209, 197, 0.1);
  border-color: rgba(79, 209, 197, 0.3);
  color: var(--accent);
}

.lock-dialog-btn.primary:hover {
  background: rgba(79, 209, 197, 0.2);
  border-color: var(--accent);
}

.lock-dialog-btn.danger {
  background: rgba(248, 113, 113, 0.08);
  border-color: rgba(248, 113, 113, 0.25);
  color: var(--negative);
}

.lock-dialog-btn.danger:hover {
  background: rgba(248, 113, 113, 0.18);
  border-color: var(--negative);
}

.lock-dialog-btn.ghost {
  background: none;
  border-color: var(--border);
  color: var(--text-muted);
}

.lock-dialog-btn.ghost:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

/* ── BOUTON BIOMÉTRIQUE ── */
.lock-biometric-btn {
  width: 100%;
  padding: 0.75rem;
  background: linear-gradient(135deg, rgba(79, 209, 197, 0.12) 0%, rgba(124, 106, 245, 0.12) 100%);
  border: 1px solid rgba(79, 209, 197, 0.35);
  border-radius: 8px;
  font-family: 'Syne', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  letter-spacing: 0.02em;
}

.lock-biometric-btn:hover {
  background: linear-gradient(135deg, rgba(79, 209, 197, 0.22) 0%, rgba(124, 106, 245, 0.22) 100%);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.lock-biometric-btn:active {
  transform: translateY(0);
}

.lock-biometric-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.lock-separator {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
  font-family: 'Syne', sans-serif;
  font-size: 0.75rem;
}

.lock-separator::before,
.lock-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── MODAL PASSPHRASE ── */
#passphrase-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10001;
  background: rgba(0, 0, 0, 0.65);
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

#passphrase-modal-overlay.visible {
  display: flex;
}

.passphrase-modal-desc {
  font-family: 'Syne', sans-serif;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  line-height: 1.55;
}

/* ── MODALE HISTORIQUE DU TOTAL ── */
#history-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

#history-modal-overlay.visible {
  display: flex;
}

.history-dialog {
  max-width: 460px;
  text-align: left;
}

.history-dialog .lock-dialog-title {
  text-align: center;
}

.history-chart-wrap {
  position: relative;
}

.history-svg {
  display: block;
  width: 100%;
  height: auto;
}

.hist-grid {
  stroke: rgba(255, 255, 255, 0.07);
  stroke-width: 1;
}

.hist-grid-label,
.hist-axis-label {
  fill: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
}

.hist-area {
  fill: rgba(79, 209, 197, 0.09);
  stroke: none;
}

.hist-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.hist-dot,
.hist-marker {
  fill: var(--accent);
  stroke: var(--surface);
  stroke-width: 2;
}

.hist-cross {
  stroke: rgba(255, 255, 255, 0.18);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.history-tooltip {
  position: absolute;
  display: none;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.55rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  color: var(--text);
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

.history-stats {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.75rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}

.hs-label {
  display: block;
  font-family: 'Syne', sans-serif;
  font-size: 0.62rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.15rem;
}

.hs-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.88rem;
  color: var(--text);
}

.history-empty {
  font-family: 'Syne', sans-serif;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.55;
  padding: 1rem 0;
  text-align: center;
}

.history-table {
  margin-top: 0.6rem;
}

.history-table summary {
  font-family: 'Syne', sans-serif;
  font-size: 0.72rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.3rem 0;
}

.history-table summary:hover {
  color: var(--text);
}

.history-table-scroll {
  max-height: 180px;
  overflow-y: auto;
  margin-top: 0.4rem;
}

.history-table table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
}

.history-table th {
  text-align: left;
  font-family: 'Syne', sans-serif;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0.25rem 0.5rem 0.25rem 0;
  border-bottom: 1px solid var(--border);
}

.history-table td {
  color: var(--text);
  padding: 0.25rem 0.5rem 0.25rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.history-table td:last-child,
.history-table th:last-child {
  text-align: right;
  padding-right: 0;
}

/* Masquage des valeurs : flouter aussi l'historique */
.values-blurred .history-chart-wrap,
.values-blurred .hs-value,
.values-blurred .history-table {
  filter: blur(8px);
  pointer-events: none;
  user-select: none;
}

/* ── BOUTON VERROUILLER (footer) ── */
.btn-lock-app {
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.25);
  border-radius: 6px;
  color: var(--negative);
  cursor: pointer;
  padding: 0.35rem 0.75rem;
  font-size: 0.78rem;
  font-family: 'Syne', sans-serif;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: all var(--transition);
}

.btn-lock-app:hover {
  background: rgba(248, 113, 113, 0.18);
  border-color: var(--negative);
}

/* ── RESPONSIVE ── */
@media (max-width: 480px) {
  body {
    padding: 1rem 0.5rem;
  }

  .app-header {
    padding: 1rem 1rem 0.75rem;
  }

  .header-top {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .btn-icon {
    min-height: 36px;
  }

  .title1-row,
  .title3-row,
  .row,
  .total-row,
  .divide-section {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .group-header {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .app-footer {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .row-value {
    width: min(116px, 38vw);
  }

  .divide-section,
  .app-footer {
    align-items: stretch;
  }

  .divide-section {
    flex-direction: column;
  }

  .divide-left {
    justify-content: space-between;
  }

  .divide-result {
    text-align: right;
  }
}

/* ═══════════════════════════════════════════════
   AJOUTS SOLDO — onglets, budget, footer sticky,
   PIN, notes, historique bicolore
   ═══════════════════════════════════════════════ */

/* ── TABBAR ── */
.tabbar {
  position: relative;
  display: flex;
  margin: 0.9rem 1.5rem 0;
  padding: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  gap: 4px;
}

.tab-btn {
  position: relative;
  z-index: 1;
  flex: 1;
  padding: 0.55rem 0.5rem;
  background: none;
  border: none;
  border-radius: 9px;
  font-family: 'Syne', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tab-btn[aria-selected="true"] {
  color: var(--text);
}

#tab-budget[aria-selected="true"] {
  color: var(--accent2);
}

#tab-calc[aria-selected="true"] {
  color: var(--accent);
}

.tab-indicator {
  position: absolute;
  z-index: 0;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: calc(50% - 6px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  transition: transform 0.28s cubic-bezier(0.34, 1.3, 0.5, 1), border-color var(--transition);
  pointer-events: none;
}

.tabbar.on-budget .tab-indicator {
  transform: translateX(0);
  border-color: rgba(124, 106, 245, 0.45);
}

.tabbar.on-calc .tab-indicator {
  transform: translateX(calc(100% + 4px));
  border-color: rgba(79, 209, 197, 0.45);
}

/* Pastille d'alerte (reste à vivre négatif) */
.tab-alert {
  display: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--negative);
  box-shadow: 0 0 6px rgba(248, 113, 113, 0.8);
  flex-shrink: 0;
}

.tab-alert.visible {
  display: inline-block;
}

/* ── PANNEAUX ── */
.tab-panel[hidden] {
  display: none !important;
}

.tab-panel {
  animation: panelIn 0.25s ease-out;
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── BUDGET : groupes ── */
.group-exp .group-header {
  background: rgba(248, 113, 113, 0.06);
}

.group-exp .group-header:hover {
  background: rgba(248, 113, 113, 0.1);
}

.group-exp .group-name-input {
  color: var(--negative);
}

.group-exp .row {
  background: var(--groupd);
}

.group-exp .row:hover {
  background: rgba(248, 113, 113, 0.12);
}

.group-annexe {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.group-annexe .group-header {
  background: rgba(124, 106, 245, 0.05);
}

.group-annexe .group-header:hover {
  background: rgba(124, 106, 245, 0.09);
}

.group-annexe .group-name-input {
  color: var(--accent2);
}

.group-annexe .row {
  background: rgba(124, 106, 245, 0.04);
}

.group-annexe .row:hover {
  background: rgba(124, 106, 245, 0.1);
}

.group-hint {
  font-family: 'Syne', sans-serif;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  margin-right: 0.6rem;
}

/* ── BOUTON NOTES ── */
.notes-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin: 0.75rem 1.5rem 0.5rem;
  width: calc(100% - 3rem);
  padding: 0.55rem;
  background: rgba(251, 191, 36, 0.05);
  border: 1px dashed rgba(251, 191, 36, 0.3);
  border-radius: var(--radius);
  color: var(--highlight);
  font-family: 'Syne', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: all var(--transition);
}

.notes-btn:hover {
  background: rgba(251, 191, 36, 0.12);
  border-color: var(--highlight);
}

.notes-btn:focus-visible {
  outline: 2px solid var(--highlight);
  outline-offset: 2px;
}

.notes-badge {
  display: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--highlight);
  box-shadow: 0 0 6px rgba(251, 191, 36, 0.8);
}

.notes-badge.visible {
  display: inline-block;
}

.notes-textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.notes-textarea:focus {
  border-color: var(--highlight);
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.12);
}

.notes-dialog {
  max-width: 460px;
  text-align: left;
}

.notes-dialog .lock-dialog-title {
  text-align: center;
}

.notes-dialog .lock-dialog-actions {
  flex-direction: row;
  justify-content: flex-end;
}

/* ── FOOTER STICKY CONTEXTUEL ── */
#sticky-footer {
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: var(--surface);
  box-shadow: 0 -8px 20px rgba(0, 0, 0, 0.3);
}

.footer-panel[hidden] {
  display: none !important;
}

.footer-budget .total-row {
  margin: 0;
  border-top: 2px solid rgba(124, 106, 245, 0.4);
  background: linear-gradient(90deg, rgba(124, 106, 245, 0.08) 0%, transparent 100%);
}

.footer-calc .total-row {
  margin: 0;
  border-top: 2px solid rgba(79, 209, 197, 0.4);
}

#remaining-value {
  font-size: 1.25rem;
}

/* ── PIN (6 chiffres) ── */
.pin-inputs {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.pin-digit {
  width: 42px;
  height: 50px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.3rem;
  color: var(--text);
  text-align: center;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.pin-digit:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 209, 197, 0.15);
}

.pin-inputs.error .pin-digit {
  border-color: var(--negative);
  animation: lockShake 0.4s ease;
}

.lock-switch-method {
  background: none;
  border: none;
  color: var(--accent);
  font-family: 'Syne', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 0.75rem;
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  transition: color var(--transition);
}

.lock-switch-method:hover {
  color: var(--text);
}

/* ── MODALE SÉCURITÉ ── */
.security-dialog {
  max-width: 380px;
}

.security-desc {
  font-family: 'Syne', sans-serif;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  line-height: 1.55;
  min-height: 1.2em;
}

.security-menu {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.security-menu:empty {
  display: none;
}

.security-menu-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.9rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: 'Syne', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: all var(--transition);
}

.security-menu-btn:hover {
  border-color: var(--accent);
  background: rgba(79, 209, 197, 0.06);
}

.security-menu-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.security-menu-btn .status {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.68rem;
  font-weight: 400;
  color: var(--text-muted);
  white-space: nowrap;
}

.security-menu-btn .status.on {
  color: var(--positive);
}

.security-menu-btn.danger {
  color: var(--negative);
}

.security-menu-btn.danger:hover {
  border-color: var(--negative);
  background: rgba(248, 113, 113, 0.08);
}

/* ── HISTORIQUE : SÉLECTEUR DE SÉRIE ── */
.history-switch {
  display: flex;
  gap: 4px;
  padding: 3px;
  margin-bottom: 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 9px;
}

.hist-switch-btn {
  flex: 1;
  padding: 0.4rem;
  background: none;
  border: 1px solid transparent;
  border-radius: 7px;
  font-family: 'Syne', sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.hist-switch-btn:hover {
  color: var(--text);
}

.hist-switch-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#hist-switch-budget.active {
  color: var(--accent2);
  background: var(--surface);
  border-color: rgba(124, 106, 245, 0.45);
}

#hist-switch-calc.active {
  color: var(--accent);
  background: var(--surface);
  border-color: rgba(79, 209, 197, 0.45);
}

/* Série budget : graphique violet */
.history-body.series-budget .hist-line {
  stroke: var(--accent2);
}

.history-body.series-budget .hist-area {
  fill: rgba(124, 106, 245, 0.09);
}

.history-body.series-budget .hist-dot,
.history-body.series-budget .hist-marker {
  fill: var(--accent2);
}

/* ── MASQUAGE : extensions Soldo ── */
.values-hidden .mini-total,
.values-hidden .notes-textarea {
  filter: blur(8px);
  user-select: none;
  pointer-events: none;
}

/* ── RESPONSIVE : ajouts Soldo ── */
@media (max-width: 480px) {
  .tabbar {
    margin: 0.75rem 1rem 0;
  }

  .notes-btn {
    margin-left: 1rem;
    margin-right: 1rem;
    width: calc(100% - 2rem);
  }

  .pin-digit {
    width: 38px;
    height: 46px;
  }

  #sticky-footer {
    padding-bottom: env(safe-area-inset-bottom);
  }
}
