/* ============================================
   DindiDigit Finance — Suivi des Dépenses
   Design professionnel, responsive mobile-first
   ============================================ */

:root {
  /* Fond & surfaces */
  --bg: #0f1419;
  --bg-elevated: #1a1f26;
  --bg-card: #161b22;
  --border: #30363d;
  --border-subtle: #21262d;

  /* Texte */
  --text: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;

  /* Actions */
  --primary: #238636;
  --primary-hover: #2ea043;
  --primary-active: #26a641;
  --ghost-hover: rgba(255, 255, 255, 0.06);
  --danger: #f85149;
  --danger-hover: rgba(248, 81, 73, 0.15);

  /* Sémantique */
  --expense: #d29922;
  --balance: #3fb950;

  /* Espacement */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;

  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --touch-min: 44px;
}

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

.banner-file-mode {
  background: #9a6700;
  color: #1a1a1a;
  padding: var(--space-3) var(--space-4);
  font-size: 0.875rem;
  text-align: center;
}

.banner-file-mode[hidden] {
  display: none;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-4);
  min-height: 100vh;
}

/* ---- Header ---- */
.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.header-brand {
  min-width: 0;
}

.header-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.header-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.data-source {
  font-weight: 500;
  color: var(--balance);
}

.data-source--offline {
  color: var(--expense);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-min);
  padding: 0 var(--space-4);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-primary:active {
  background: var(--primary-active);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--ghost-hover);
  color: var(--text);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-sm {
  min-height: 36px;
  padding: 0 var(--space-3);
  font-size: 0.8125rem;
}

@media (max-width: 480px) {
  .btn-block-mobile {
    width: 100%;
  }
}

/* ---- Cards ---- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--space-4);
}

/* ---- KPI ---- */
.kpi-section {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.kpi-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: var(--space-4);
}

.kpi-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-2);
}

.kpi-value {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.kpi-card--expense .kpi-value {
  color: var(--expense);
}

.kpi-card--balance .kpi-value {
  color: var(--balance);
}

/* ---- Form ---- */
.form-depense .form-field,
.form-depense .form-grid {
  margin-bottom: var(--space-4);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.form-field label,
.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.form-field input[type="number"],
.form-field input[type="date"],
.form-field textarea {
  width: 100%;
  min-height: var(--touch-min);
  padding: 0 var(--space-3);
  font-family: var(--font);
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s;
}

.form-field textarea {
  min-height: 72px;
  padding: var(--space-3);
  resize: vertical;
}

.form-field input::placeholder,
.form-field textarea::placeholder {
  color: var(--text-muted);
}

.form-field input:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(35, 134, 54, 0.2);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

/* ---- Upload ---- */
.upload-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80px;
  padding: var(--space-4);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--primary);
  background: rgba(35, 134, 54, 0.06);
}

.upload-text {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.upload-link {
  color: var(--primary);
  font-weight: 500;
}

.preview-image {
  margin-top: var(--space-3);
}

.preview-image img {
  max-width: 160px;
  max-height: 100px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  object-fit: cover;
}

/* ---- List / Table ---- */
.list-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.filters select {
  min-height: 36px;
  padding: 0 var(--space-3);
  font-family: var(--font);
  font-size: 0.875rem;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.table-wrap {
  overflow-x: auto;
  margin: 0 calc(-1 * var(--space-5));
  padding: 0 var(--space-5);
}

.table-depenses {
  width: 100%;
  border-collapse: collapse;
}

.table-depenses thead {
  display: none;
}

.table-depenses tbody tr {
  display: block;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  background: var(--bg-elevated);
}

.table-depenses tbody tr:last-child {
  margin-bottom: 0;
}

.table-depenses td {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  font-size: 0.9375rem;
  border: none;
}

.table-depenses td::before {
  content: attr(data-label);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.table-depenses td.montant {
  font-weight: 700;
  color: var(--expense);
  border-top: 1px solid var(--border-subtle);
  padding-top: var(--space-3);
  margin-top: var(--space-2);
}

.table-depenses td.cell-image {
  justify-content: flex-start;
}

.table-depenses td.cell-image img {
  max-width: 48px;
  max-height: 48px;
  border-radius: var(--radius-sm);
  object-fit: cover;
}

.table-depenses td.cell-image .no-img {
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.table-depenses td.cell-action {
  border-top: 1px solid var(--border-subtle);
  padding-top: var(--space-3);
  margin-top: var(--space-2);
}

.table-depenses td.cell-action::before {
  content: '';
  display: none;
}

.table-depenses td.cell-action .btn-delete {
  margin-left: auto;
}

.empty-state {
  display: none;
  text-align: center;
  padding: var(--space-8);
  font-size: 0.9375rem;
  color: var(--text-muted);
}

.empty-state.visible {
  display: block;
}

/* ---- Table desktop ---- */
@media (min-width: 640px) {
  .table-wrap {
    margin: 0;
    padding: 0;
  }

  .table-depenses thead {
    display: table-header-group;
  }

  .table-depenses thead th {
    padding: var(--space-2) var(--space-3);
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    text-align: left;
    border-bottom: 1px solid var(--border-subtle);
  }

  .table-depenses tbody tr {
    display: table-row;
    border: none;
    border-radius: 0;
    padding: 0;
    margin: 0;
    background: transparent;
    border-bottom: 1px solid var(--border-subtle);
  }

  .table-depenses tbody tr:hover {
    background: var(--ghost-hover);
  }

  .table-depenses td {
    display: table-cell;
    padding: var(--space-3);
    font-size: 0.9375rem;
    border: none;
    border-top: none;
    margin-top: 0;
    justify-content: unset;
  }

  .table-depenses td::before {
    display: none;
  }

  .table-depenses td.montant {
    font-weight: 600;
    color: var(--expense);
    border-top: none;
    padding-top: var(--space-3);
  }

  .table-depenses td.cell-action {
    border-top: none;
    padding-top: var(--space-3);
  }

  .table-depenses .th-image {
    width: 72px;
  }

  .table-depenses .th-action {
    width: 100px;
  }
}

/* ---- Modal ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.modal.is-open {
  opacity: 1;
  visibility: visible;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  -webkit-tap-highlight-color: transparent;
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-large {
  max-width: 520px;
}

.modal-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.modal-desc {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-5);
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

.modal-close {
  margin-top: var(--space-4);
}

/* ---- Rapport ---- */
.rapport-select {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  align-items: flex-end;
}

.form-field--inline {
  margin-bottom: 0;
}

.form-field--inline label {
  margin-bottom: var(--space-2);
}

.form-field--inline select {
  min-height: 40px;
  padding: 0 var(--space-3);
  font-family: var(--font);
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.rapport-content {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: var(--space-4);
  font-size: 0.9375rem;
}

.rapport-content .line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-4);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border-subtle);
}

.rapport-content .line:last-child {
  border-bottom: none;
}

.rapport-content .total {
  font-weight: 700;
  margin-top: var(--space-2);
  padding-top: var(--space-3);
  border-top: 2px solid var(--border);
}

/* ---- Responsive tablette / desktop ---- */
@media (min-width: 640px) {
  .app {
    padding: var(--space-6);
    max-width: 900px;
  }

  .header-title {
    font-size: 1.5rem;
  }

  .kpi-section {
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-4);
  }

  .kpi-value {
    font-size: 1.375rem;
  }

  .form-grid {
    grid-template-columns: 160px 160px;
  }
}

@media (min-width: 900px) {
  .app {
    max-width: 1000px;
  }
}
