:root {
  --bg: #f4ede5;
  --surface: #ffffff;
  --surface-2: #fbf7f2;
  --ink: #2f251f;
  --ink-soft: #756257;
  --line: #e5d8ca;
  --brand: #2c2520;
  --brand-2: #3e332b;
  --accent: #c4956a;
  --ok: #4f7658;
  --warn: #b68146;
  --danger: #b44d44;
  --shadow: 0 10px 28px rgba(44, 37, 32, 0.10);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: linear-gradient(180deg, #f7f1ea 0%, #f4ede5 45%, #f2e8de 100%);
  color: var(--ink);
  font-family: Manrope, sans-serif;
}

.app-shell { display: flex; min-height: 100vh; }
.app-sidebar {
  width: 280px;
  background: linear-gradient(165deg, #2c2520 0%, #3b2f27 70%, #4a3a2f 100%);
  color: #f3ebe2;
  padding: 26px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.sidebar-brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(140deg, #d2a27a, #b68458);
  color: #2c2520;
  font-family: Fraunces, serif;
  font-size: 24px;
  font-weight: 700;
}
.brand-title { font-family: Fraunces, serif; font-size: 24px; line-height: 1; }
.brand-subtitle { margin-top: 4px; opacity: .85; font-size: 12px; text-transform: uppercase; letter-spacing: .16em; }
.side-nav { display: grid; gap: 8px; }
.side-nav-item {
  color: #e8d8c9;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
}
.side-nav-item:hover { background: rgba(255,255,255,.07); }
.side-nav-item.active { background: rgba(196, 149, 106, .28); border-color: rgba(237, 205, 171, .42); color: #fff; }
.sidebar-date { margin-top: auto; font-size: 12px; opacity: .78; }

.app-main { flex: 1; min-width: 0; }
.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 26px 28px 8px;
}
.app-header h1 {
  margin: 0;
  font-family: Fraunces, serif;
  font-size: 34px;
  font-weight: 600;
}
.menu-btn { display: none; border: 0; background: transparent; font-size: 24px; }
.app-content { padding: 0 28px 28px; }

.panel, .card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.panel { padding: 16px 18px; margin-bottom: 14px; }
.card { padding: 20px; margin-bottom: 14px; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 15% 20%, #5c4b3f 0, #3e332b 48%, #2c2520 100%);
}
.login-card {
  width: min(460px, 100%);
  border-radius: 22px;
  background: var(--surface);
  border: 1px solid #dbe4ee;
  box-shadow: 0 24px 48px rgba(11, 22, 34, 0.36);
  padding: 34px;
}
.login-title { margin: 0; font-family: Fraunces, serif; font-size: 38px; }
.login-sub { margin: 8px 0 18px; color: var(--ink-soft); }
.login-error { color: var(--danger); font-size: 13px; margin-top: 10px; }

.btn {
  border: 1px solid transparent;
  background: #fff;
  color: var(--ink);
  border-radius: 11px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: linear-gradient(145deg, var(--brand), var(--brand-2)); color: #fff; }
.btn-secondary { background: #f6eee5; border-color: #e3d2bf; color: #5a4334; }
.btn-success { background: #edf4ef; border-color: #c5d8cb; color: #355a43; }
.btn-warning { background: #fcf2e7; border-color: #ecd2b4; color: #8a5a1e; }
.btn-danger { background: #fcefed; border-color: #efc6c1; color: #9c3830; }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink-soft); }

input, select, textarea {
  width: 100%;
  border: 1px solid #ddcec0;
  border-radius: 10px;
  background: #fffcf8;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #c4956a;
  box-shadow: 0 0 0 3px rgba(196, 149, 106, .16);
}

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }

.kpi {
  border: 1px solid #e1d4c7;
  border-radius: 14px;
  padding: 14px;
  background: linear-gradient(180deg, #fff, #fdf8f2);
}
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: #8a776a; }
.kpi-value { margin-top: 6px; font-size: 30px; font-family: Fraunces, serif; line-height: 1; }
.kpi-sub { margin-top: 6px; font-size: 12px; color: var(--ink-soft); }

.upload-title { margin: 0 0 6px; font-size: 17px; font-weight: 700; }
.upload-sub { margin: 0 0 12px; color: var(--ink-soft); font-size: 14px; }
.file-help { font-size: 13px; color: #6f5e52; margin: 8px 0 12px; }
.file-selected { margin-top: 8px; font-size: 12px; color: #735543; font-weight: 600; }
.file-valid { color: #0b7c51; }
.file-invalid { color: #ab3030; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  padding: 3px 9px;
  border: 1px solid transparent;
  font-size: 11px;
  font-weight: 700;
}
.badge.mode-cb { background: #e8f4ef; color: #186447; border-color: #c4dfd3; }
.badge.mode-cheque { background: #fff0dc; color: #87551c; border-color: #e8c7a0; }
.badge.mode-virement,
.badge.mode-virement-secu,
.badge.mode-virement-mutuelle { background: #f3ece4; color: #634b39; border-color: #e3d1be; }
.badge.mode-especes { background: #f5f1ea; color: #66513b; border-color: #ded3c4; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 8px 0 12px; }

.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.tab-btn {
  border: 1px solid #dfd0c2;
  border-radius: 999px;
  background: #fff;
  color: #6e5440;
  font-size: 12px;
  font-weight: 700;
  padding: 7px 12px;
  cursor: pointer;
}
.tab-btn.active { background: #f2e5d8; border-color: #cfa984; color: #6f4a2f; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
table { width: 100%; border-collapse: collapse; min-width: 980px; }
th, td { padding: 10px 12px; border-bottom: 1px solid #efe3d7; text-align: left; font-size: 13px; }
th { background: #f9f2ea; font-size: 11px; text-transform: uppercase; letter-spacing: .11em; color: #7d6857; }
tr:nth-child(even) td { background: #fffaf4; }
.amount, .retro { text-align: right; font-weight: 700; white-space: nowrap; }
.retro { color: #8f2f2f; }
.modified-flag { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #d08e44; margin-left: 6px; }

.notice { border-radius: 12px; padding: 11px 12px; font-size: 13px; margin-bottom: 10px; }
.notice.info { background: #f6eee5; border: 1px solid #e3d0bc; color: #6a4f39; }
.notice.warn { background: #fff5e9; border: 1px solid #edd0ac; color: #85561f; }
.notice.ok { background: #edf5ef; border: 1px solid #cbdcce; color: #355a43; }
.notice.error { background: #fdeeee; border: 1px solid #f3c9c9; color: #983131; }

.history-list { display: grid; gap: 8px; max-height: 280px; overflow: auto; }
.history-item {
  border: 1px solid #e2d6c9;
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}
.history-meta { font-size: 12px; color: #667687; }

.status-chip {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.status-en_cours { background: #f3e7db; color: #6b4d35; }
.status-brouillon { background: #fff3e4; color: #87551d; }
.status-finalise { background: #eaf3ed; color: #2d5a40; }

.month-list { display: grid; gap: 8px; }
.month-row {
  border: 1px solid #e2d6c9;
  border-radius: 12px;
  background: #fff;
  padding: 10px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.month-info { font-size: 13px; }
.month-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.loader {
  width: 16px;
  height: 16px;
  border: 2px solid #bed3e5;
  border-top-color: #28587d;
  border-radius: 50%;
  display: inline-block;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1040px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .menu-btn { display: inline-block; }
  .app-sidebar { position: fixed; inset: 0 auto 0 0; z-index: 12; transform: translateX(-100%); transition: transform .2s ease; }
  .app-sidebar.open { transform: translateX(0); }
  .app-header { padding: 16px; }
  .app-header h1 { font-size: 28px; }
  .app-content { padding: 0 16px 16px; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
}
@media print {
  .app-sidebar, .menu-btn, .toolbar, .tabs, .no-print { display: none !important; }
  .app-content, .app-header { padding: 0 !important; }
  body { background: #fff; }
}
