:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --text-2: #6c6c70;
  --text-3: #a1a1a6;
  --accent: #007AFF;
  --accent-2: #0051d5;
  --green: #34C759;
  --orange: #FF9500;
  --red: #FF3B30;
  --border: #e5e5ea;
  --hero-1: #007AFF;
  --hero-2: #0051d5;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,0.04);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #ffffff;
    --text-2: #a1a1a6;
    --text-3: #636366;
    --border: #2c2c2e;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 17px;
  line-height: 1.4;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  padding: max(env(safe-area-inset-top), 12px) 20px 8px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

main {
  padding: 8px 16px 40px;
  max-width: 640px;
  margin: 0 auto;
}

/* SOLDE PRINCIPAL */
.hero-balance {
  background: linear-gradient(135deg, var(--hero-1), var(--hero-2));
  border-radius: 20px;
  padding: 28px 24px;
  color: #fff;
  margin: 8px 0 20px;
  box-shadow: 0 8px 24px rgba(0,122,255,0.25);
}
.hero-balance .label {
  font-size: 14px;
  font-weight: 500;
  opacity: 0.85;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.hero-balance .amount {
  font-size: 48px;
  font-weight: 700;
  letter-spacing: -1.5px;
  margin-top: 4px;
  line-height: 1.1;
}
.hero-balance .future {
  font-size: 15px;
  margin-top: 10px;
  opacity: 0.9;
  min-height: 20px;
}
.hero-pills {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.2);
}
.hero-pills .pill {
  flex: 1;
  background: rgba(255,255,255,0.15);
  border-radius: 12px;
  padding: 10px 12px;
}
.hero-pills .pill-label {
  display: block;
  font-size: 12px;
  opacity: 0.85;
  font-weight: 500;
}
.hero-pills .pill-value {
  display: block;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-top: 2px;
}
.hero-balance.negative {
  background: linear-gradient(135deg, #FF3B30, #c1281f);
  box-shadow: 0 8px 24px rgba(255,59,48,0.25);
}

/* CARDS */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.card-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.btn-add {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0 2px;
  transition: transform 0.1s, background 0.15s;
}
.btn-add:hover { background: var(--accent-2); }
.btn-add:active { transform: scale(0.92); }

/* LIST */
.list {
  display: flex;
  flex-direction: column;
}
.list-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.list-item:last-child { border-bottom: none; }
.item-main {
  flex: 1;
  min-width: 0;
}
.item-name {
  font-size: 16px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-sub {
  font-size: 13px;
  color: var(--text-2);
  margin-top: 2px;
}
.item-value {
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
}
.item-value.expense { color: var(--red); }
.item-value.pending { color: var(--orange); }
.item-value.paid { color: var(--green); }

.item-actions {
  display: flex;
  gap: 6px;
}
.btn-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.btn-icon:hover { background: var(--border); }
.btn-icon:active { transform: scale(0.9); }
.btn-icon.check { color: var(--green); }
.btn-icon.check:hover { background: rgba(52,199,89,0.15); }
.btn-icon.delete { color: var(--red); }
.btn-icon.delete:hover { background: rgba(255,59,48,0.12); }

.tag {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  display: inline-block;
  margin-top: 3px;
}
.tag.pending { background: rgba(255,149,0,0.15); color: var(--orange); }
.tag.paid { background: rgba(52,199,89,0.15); color: var(--green); }
.tag.advanced { background: rgba(0,122,255,0.15); color: var(--accent); }
.tags-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 3px;
}
.tags-row .tag { margin-top: 0; }

.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 12px;
  margin-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 15px;
  color: var(--text-2);
}
.total-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.total-value.expense { color: var(--red); }
.total-value.pending { color: var(--orange); }

.total-row.grand {
  border-top: 2px solid var(--border);
  margin-top: 4px;
}
.total-row.grand span:first-child {
  font-weight: 600;
  color: var(--text);
}
.total-row.grand .total-value { font-size: 20px; }

/* GROUPES DE COMPTES */
.group-block { margin-bottom: 6px; }
.group-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin: 10px 0 2px;
}
.total-row.grand + .group-block .group-title { margin-top: 0; }

.empty {
  color: var(--text-3);
  font-size: 14px;
  text-align: center;
  padding: 14px 0 6px;
  font-style: italic;
}

/* FORM */
.form-inline {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.form-inline.hidden { display: none; }
.form-inline input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}
.form-inline input:focus { border-color: var(--accent); }

.field-label {
  font-size: 13px;
  color: var(--text-2);
  font-weight: 500;
  margin-bottom: -4px;
}
.select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-family: var(--font);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236c6c70' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
.select:focus { border-color: var(--accent); }

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  color: var(--text-2);
  cursor: pointer;
  line-height: 1.35;
}
.check-row input {
  width: 22px !important;
  height: 22px;
  flex-shrink: 0;
  margin: 0;
  accent-color: var(--accent);
}

/* SEGMENTED CONTROL */
.segmented {
  display: flex;
  background: var(--bg);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
  border: 1px solid var(--border);
}
.seg-opt {
  flex: 1;
  padding: 9px 8px;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg-opt.active {
  background: var(--card);
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.btn-primary, .btn-secondary {
  padding: 10px 16px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn-primary:active { transform: scale(0.97); }
.btn-secondary { background: var(--bg); color: var(--text); }
.btn-secondary:hover { background: var(--border); }

/* BARCELONE */
.card.barcelona { border: 1px solid var(--border); }
.switch {
  position: relative;
  display: inline-block;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 34px;
  transition: 0.25s;
}
.slider::before {
  content: "";
  position: absolute;
  height: 27px;
  width: 27px;
  left: 2px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: 0.25s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(20px); }

.barcelona-inputs {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.form-row label {
  font-size: 15px;
  color: var(--text-2);
  min-width: 90px;
}
.form-row input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-family: var(--font);
  text-align: right;
  outline: none;
}
.form-row input:focus { border-color: var(--accent); }

.barcelona-sim {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sim-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--bg);
}
.sim-row.take-it { background: rgba(0,122,255,0.10); }
.sim-row.skip-it { background: rgba(52,199,89,0.10); }
.sim-label {
  font-size: 14px;
  color: var(--text-2);
  font-weight: 500;
}
.sim-row.take-it .sim-label { color: var(--accent); }
.sim-row.skip-it .sim-label { color: var(--green); }
.sim-value {
  font-size: 18px;
  font-weight: 700;
}
.sim-row.take-it .sim-value { color: var(--accent); }
.sim-row.skip-it .sim-value { color: var(--green); }

.app-footer {
  text-align: center;
  padding: 20px 20px 30px;
}
.app-footer p {
  font-size: 12px;
  color: var(--text-3);
  margin: 0;
}

/* MODALE RÉPARTITION */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  animation: fadeIn 0.2s ease;
}
.modal-sheet {
  position: relative;
  width: 100%;
  max-width: 640px;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0,0,0,0.2);
  animation: slideUp 0.25s cubic-bezier(0.16,1,0.3,1);
  max-height: 88vh;
  overflow-y: auto;
}
@media (min-width: 641px) {
  .modal { align-items: center; }
  .modal-sheet { border-radius: 20px; }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.modal-head h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.modal-head .btn-icon { font-size: 15px; }
.modal-sub {
  font-size: 14px;
  color: var(--text-2);
  margin: 2px 0 16px;
}
.split-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.split-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.split-row-info {
  flex: 1;
  min-width: 0;
}
.split-row-name {
  font-size: 16px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.split-row-type {
  font-size: 12px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.split-row input {
  width: 130px;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-family: var(--font);
  text-align: right;
  outline: none;
}
.split-row input:focus { border-color: var(--accent); }
.split-recap {
  margin: 16px 0;
  padding: 14px;
  background: var(--bg);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.split-recap-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
  color: var(--text-2);
}
.split-recap-row span:last-child {
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
}
.split-remaining.ok { color: var(--green) !important; }
.split-remaining.over { color: var(--red) !important; }
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* Animations */
.list-item {
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
