:root {
  --color-bg: #f4f6f8;
  --color-surface: #ffffff;
  --color-border: #e2e5ea;
  --color-text: #1a1f27;
  --color-text-muted: #6b7280;
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-success: #16a34a;
  --color-warning: #d97706;
  --color-danger: #dc2626;
  --color-info: #7c3aed;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--color-bg); color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif; }
h1, h2, h3 { margin: 0 0 8px; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 15px; }

.hidden { display: none !important; }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--color-surface); border-radius: var(--radius); padding: 32px 24px; width: 100%; max-width: 380px;
  box-shadow: 0 4px 24px rgba(0,0,0,.08); }
.login-card h1 { text-align: center; font-size: 22px; margin-bottom: 24px; }
.login-card .demo-accounts { margin-top: 20px; font-size: 12px; color: var(--color-text-muted); line-height: 1.6; }

/* ---- Layout ---- */
header.topbar { background: var(--color-surface); border-bottom: 1px solid var(--color-border);
  padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 20; }
header.topbar .who { font-size: 13px; color: var(--color-text-muted); }
header.topbar .brand { font-weight: 700; font-size: 17px; }
header.topbar button.logout { background: none; border: none; color: var(--color-danger); font-size: 13px; }

/* En-tete + navigation principale, colles ensemble en haut de page. */
.app-header-wrap { position: sticky; top: 0; z-index: 30; background: var(--color-surface);
  box-shadow: 0 1px 3px rgba(15,23,42,.06); }
header.topbar { position: static; box-shadow: none; }

nav.tabs { display: flex; gap: 8px; background: var(--color-surface); border-bottom: 1px solid var(--color-border);
  padding: 8px 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
nav.tabs button { display: inline-flex; align-items: center; gap: 10px; white-space: nowrap; flex: 0 0 auto;
  padding: 11px 18px; border-radius: 10px; border: 1px solid transparent; background: none;
  font-size: 15px; font-weight: 600; color: var(--color-text-muted); }
nav.tabs button .ic { font-size: 22px; line-height: 1; }
nav.tabs button:hover { background: var(--color-bg); }
nav.tabs button.active { background: #eef2ff; border-color: #c7d2fe; color: var(--color-primary); }
nav.tabs .tab-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 23px; height: 23px;
  padding: 0 7px; border-radius: 999px; background: var(--color-danger); color: #fff; font-size: 12px; font-weight: 700; }
nav.tabs .tab-badge[hidden] { display: none; }

main.content { max-width: 900px; margin: 0 auto; padding: 16px; }

@media (min-width: 720px) {
  nav.tabs { justify-content: center; overflow-x: visible; }
}
@media (max-width: 719px) {
  header.topbar { padding: 8px 12px; gap: 8px; }
  header.topbar .brand { font-size: 15px; white-space: nowrap; }
  header.topbar .who { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
  nav.tabs { padding: 6px 10px; gap: 6px; }
  nav.tabs button { padding: 9px 14px; font-size: 14px; }
}

/* ---- Cards / lists ---- */
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; }
.card-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; cursor: pointer; }
.card-row:hover { opacity: .85; }
.note-main { flex: 1; min-width: 0; }
.note-main .cat { font-weight: 600; }
.note-main .meta { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; }
.note-amount { font-weight: 700; white-space: nowrap; text-align: right; }
.note-amount .sub { display: block; font-size: 11px; font-weight: 400; color: var(--color-text-muted); }

.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; margin-top: 6px; }
.badge.st-DRAFT { background: #eef0f3; color: #4b5563; }
.badge.st-SUBMITTED { background: #dbeafe; color: #1d4ed8; }
.badge.st-MANAGER_ON_HOLD, .badge.st-ACCOUNTING_ON_HOLD { background: #fef3c7; color: #b45309; }
.badge.st-MANAGER_REJECTED, .badge.st-ACCOUNTING_REJECTED { background: #fee2e2; color: #b91c1c; }
.badge.st-ACCOUNTING_REVIEW { background: #ede9fe; color: #6d28d9; }
.badge.st-ACCOUNTING_VALIDATED { background: #dcfce7; color: #15803d; }
.badge.cap-exceeded { background: #fee2e2; color: #b91c1c; }
.badge.paid { background: #dcfce7; color: #15803d; }
.badge.reconciled { background: #ccfbf1; color: #0f766e; }

.empty-state { text-align: center; color: var(--color-text-muted); padding: 40px 16px; }

/* ---- Filters ---- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters select, .filters input { padding: 7px 9px; border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-surface); }

/* ---- Buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 8px;
  border: 1px solid transparent; font-size: 14px; font-weight: 600; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-outline { background: var(--color-surface); border-color: var(--color-border); color: var(--color-text); }
.btn-success { background: var(--color-success); color: #fff; }
.btn-warning { background: var(--color-warning); color: #fff; }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-lg { padding: 18px 16px; font-size: 17px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
/* Decisions de validation : les trois boutons ont exactement la meme largeur. */
.actions-row.equal { flex-wrap: nowrap; }
.actions-row.equal .btn { flex: 1 1 0; min-width: 0; padding-left: 8px; padding-right: 8px; text-align: center; }

.cap-warning { border: 1px solid #fcd34d; background: #fffbeb; color: #92400e; border-radius: 8px;
  padding: 9px 11px; font-size: 13px; margin-top: 8px; }
.cap-warning strong { color: #b45309; }
.cap-applied { border: 1px solid #fca5a5; background: #fef2f2; color: #991b1b; border-radius: 8px;
  padding: 9px 11px; font-size: 13px; margin-top: 8px; }
.cap-accepted { border: 1px solid #86efac; background: #f0fdf4; color: #166534; border-radius: 8px;
  padding: 9px 11px; font-size: 13px; margin-top: 8px; }

.add-item-highlight { border: 2px dashed var(--color-primary); border-radius: var(--radius);
  padding: 6px; margin: 14px 0; background: #eef2ff; }
.add-item-highlight .btn { box-shadow: 0 4px 14px rgba(37,99,235,.35); }

/* ---- Status menu (sidebar on desktop, horizontal pills on mobile) ---- */
.scope-layout { display: flex; flex-direction: column; gap: 14px; }
.scope-main { min-width: 0; }

.status-menu { display: flex; flex-direction: row; gap: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch;
  padding: 2px 0 8px; }
.status-menu .menu-group-title { display: none; }
.status-menu button { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  padding: 8px 13px; border-radius: 999px; border: 1px solid var(--color-border); background: var(--color-surface);
  color: var(--color-text); font-size: 13px; font-weight: 600; }
.status-menu .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: var(--color-text-muted); }
.status-menu .dot.st-DRAFT { background: #9ca3af; }
.status-menu .dot.st-SUBMITTED { background: #2563eb; }
.status-menu .dot.st-MANAGER_ON_HOLD, .status-menu .dot.st-ACCOUNTING_ON_HOLD { background: #d97706; }
.status-menu .dot.st-MANAGER_REJECTED, .status-menu .dot.st-ACCOUNTING_REJECTED { background: #dc2626; }
.status-menu .dot.st-ACCOUNTING_REVIEW { background: #7c3aed; }
.status-menu .dot.st-ACCOUNTING_VALIDATED { background: #16a34a; }
.status-menu .dot.st-RECONCILED { background: #0d9488; }
.status-menu .count { font-size: 11px; font-weight: 700; color: var(--color-text-muted); background: var(--color-bg);
  border-radius: 999px; padding: 1px 7px; min-width: 22px; text-align: center; }
.status-menu button.active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.status-menu button.active .dot { background: #fff; }
.status-menu button.active .count { background: rgba(255,255,255,.25); color: #fff; }

@media (min-width: 720px) {
  .scope-layout { flex-direction: row; align-items: flex-start; }
  .status-menu { flex-direction: column; gap: 2px; overflow: visible; width: 234px; flex-shrink: 0;
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius);
    padding: 10px 8px; position: sticky; top: calc(var(--sticky-header-height, 110px) + 12px); }
  .status-menu .menu-group-title { display: block; font-size: 10px; font-weight: 700; letter-spacing: .06em;
    text-transform: uppercase; color: var(--color-text-muted); padding: 13px 10px 5px; }
  .status-menu .menu-group-title:first-child { padding-top: 4px; }
  .status-menu button { width: 100%; flex: none; white-space: normal; text-align: left; align-items: flex-start;
    border: none; border-radius: 8px; background: none; padding: 8px 10px; font-weight: 500; line-height: 1.35; }
  .status-menu button .label { flex: 1; min-width: 0; }
  .status-menu .qualifier { display: none; } /* le titre de groupe suffit sur grand ecran */
  .status-menu .dot { margin-top: 5px; }
  .status-menu button:hover { background: var(--color-bg); }
  .status-menu button.active { background: var(--color-primary); color: #fff; font-weight: 600; }
  .status-menu button.active:hover { background: var(--color-primary-dark); }
  .scope-main { flex: 1; }
}
.fab { position: fixed; right: 18px; bottom: 78px; z-index: 25; border-radius: 999px; width: 56px; height: 56px;
  font-size: 26px; box-shadow: 0 4px 14px rgba(37,99,235,.4); }
@media (min-width: 720px) { .fab { bottom: 24px; } }

/* ---- Form ---- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--color-text-muted); }
.field input, .field select, .field textarea { width: 100%; padding: 10px; border: 1px solid var(--color-border);
  border-radius: 8px; background: var(--color-surface); color: var(--color-text); }
.field textarea { resize: vertical; min-height: 60px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.help-text { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; }

.photo-box { border: 2px dashed var(--color-border); border-radius: var(--radius); padding: 14px; text-align: center; margin-bottom: 14px; }
.photo-box img { max-width: 100%; max-height: 240px; border-radius: 8px; display: block; margin: 0 auto 10px; }
.ocr-status { font-size: 12px; color: var(--color-primary); margin-top: 8px; min-height: 16px; }

/* ---- Modal ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: flex-end;
  justify-content: center; z-index: 50; }
.modal-box { background: var(--color-surface); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 20px; }
@media (min-width: 720px) {
  .modal-overlay { align-items: center; }
  .modal-box { border-radius: 16px; }
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-header button.close { background: none; border: none; font-size: 22px; color: var(--color-text-muted); }

/* ---- Timeline / comments ---- */
.timeline { border-left: 2px solid var(--color-border); margin: 14px 0; padding-left: 14px; }
.timeline .event { margin-bottom: 12px; font-size: 13px; }
.timeline .event .who { font-weight: 600; }
.timeline .event .when { color: var(--color-text-muted); font-size: 11px; }
.timeline .event .comment { margin-top: 4px; background: var(--color-bg); border-radius: 8px; padding: 8px 10px; }

/* ---- KPI ---- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi-tile { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 12px; }
.kpi-tile .v { font-size: 20px; font-weight: 700; }
.kpi-tile .l { font-size: 11px; color: var(--color-text-muted); }

.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; }
.bar-row .label { width: 130px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .track { flex: 1; background: var(--color-bg); border-radius: 6px; height: 18px; overflow: hidden; }
.bar-row .fill { background: var(--color-primary); height: 100%; border-radius: 6px; }
.bar-row .value { width: 90px; flex-shrink: 0; text-align: right; font-weight: 600; }

table.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.admin-table th, table.admin-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--color-border); }
table.admin-table input, table.admin-table select { padding: 5px 6px; font-size: 12px; }

.section-title { display: flex; align-items: center; justify-content: space-between; margin: 20px 0 10px; }
.section-title h3 { font-size: 15px; }

.toast { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); background: #1a1f27; color: #fff;
  padding: 10px 18px; border-radius: 8px; font-size: 13px; z-index: 100; opacity: 0; pointer-events: none;
  transition: opacity .2s; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; }
.toast.error { background: var(--color-danger); }
