@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700&display=swap');

:root {
  color-scheme: light;
  --bg: #f7f5f0;
  --panel: #ffffff;
  --ink: #172b3a;
  --muted: #52616b;
  --navy: #29485e;
  --deep: #1d3547;
  --deep-2: #26405a;
  --deep-3: #2f4d66;
  --gold: #826638;
  --gold-soft: #d8c29a;
  --line: #dcdedc;
  --line-soft: #ece9e2;
  --soft: #e9eef1;
  --side-ink: #c5cdda;
  --side-muted: #a9b3c4;
  --good-bg: #e3f4ea; --good: #0e5e3a; --good-dot: #127a4b;
  --warn-bg: #fff4e3; --warn: #6b3e00; --warn-dot: #c77700;
  --bad: #b42318;
  --radius: 12px;
  --font: 'Outfit', Arial, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--navy); }
a:hover { color: var(--deep); }
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; min-width: 0 !important; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Mise en page ---------- */
.layout { min-height: 100vh; display: flex; flex-wrap: wrap; }
.side {
  flex: 1 1 250px; max-width: 100%;
  background: var(--deep); color: #fff;
  padding: 26px 18px; display: flex; flex-direction: column; gap: 26px;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; text-decoration: none; color: #fff; }
.brand img { width: 40px; height: 40px; object-fit: contain; filter: brightness(0) invert(1); }
.brand strong { display: block; font-weight: 600; font-size: 15px; line-height: 1.2; }
.brand span { display: block; font-size: 12px; color: var(--side-muted); }
.company { padding: 12px; border-radius: 10px; background: var(--deep-2); display: flex; flex-direction: column; gap: 4px; }
.company label, .company .lbl { font-size: 12px; color: var(--side-muted); }
.company .name { font-size: 15px; font-weight: 600; }
.company select {
  width: 100%; height: 40px; border-radius: 8px; border: 1px solid var(--deep-3);
  background: var(--deep); color: #fff; padding: 0 10px; font-weight: 600;
}
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px; height: 44px; padding: 0 12px;
  border-radius: 8px; color: var(--side-ink); text-decoration: none;
}
.nav a:hover { background: var(--deep-2); color: #fff; }
.nav a[aria-current="page"] { background: var(--deep-3); color: #fff; font-weight: 500; }
.nav svg { flex: none; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 0 8px; font-size: 13px; color: var(--side-muted); }
.side-foot a { color: var(--gold-soft); }
.side-foot .who { color: var(--side-ink); word-break: break-all; }
.side-foot .acct { color: #fff; font-weight: 500; }
.side-foot .mail { color: var(--side-ink); word-break: break-all; }

.main { flex: 999 1 560px; min-width: 0; padding: 34px 40px 56px; display: flex; flex-direction: column; gap: 26px; }
@media (max-width: 640px) {
  .main { padding: 24px 16px 48px; }
  .side { padding: 18px 16px; gap: 16px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .side-foot { margin-top: 0; }
}

.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 16px; }
.page-head h1 { margin: 0; font-size: 32px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.15; }
.hello { font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.sub { margin: 6px 0 0; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 500; background: var(--line-soft); color: var(--muted); }
.chip.good { background: var(--good-bg); color: var(--good); }
.chip.good::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--good-dot); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; min-width: 0; }
.card h2 { margin: 0 0 16px; font-size: 17px; font-weight: 600; }
.row { display: flex; flex-wrap: wrap; gap: 16px; }
.row > .wide { flex: 2 1 460px; }
.row > .narrow { flex: 1 1 300px; }
.row > .half { flex: 1 1 360px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; text-decoration: none; color: var(--ink); font-weight: 500;
}
.btn:hover { border-color: var(--navy); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--deep); }
.btn.small { height: 36px; padding: 0 12px; font-size: 14px; }

/* ---------- Tableau de bord ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.kpi { display: flex; flex-direction: column; gap: 8px; }
.kpi .lbl { font-size: 14px; color: var(--muted); }
.kpi .val { font-size: 28px; font-weight: 600; letter-spacing: -0.01em; }
.kpi .delta { font-size: 13px; color: var(--muted); }
.kpi .delta b { font-weight: 600; }
.kpi .delta b.hausse { color: var(--good); }
.kpi .delta b.baisse { color: var(--bad); }

.bars-wrap { overflow-x: auto; position: relative; }
.bars { min-width: 520px; height: 230px; display: flex; align-items: flex-end; gap: 8px; border-bottom: 1px solid var(--line); position: relative; }
.bar-col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; position: relative; }
.bar { width: 100%; max-width: 34px; border-radius: 4px 4px 0 0; background: #c5d0d8; transition: background .15s; }
.bar-col.current .bar { background: var(--navy); }
.bar-col:hover .bar { background: var(--deep); }
.bar-col .v { font-size: 12px; color: var(--muted); visibility: hidden; }
.bar-col.current .v { visibility: visible; color: var(--ink); font-weight: 600; }
.bar-col:hover .v { visibility: visible; color: var(--ink); }
.bar-labels { min-width: 520px; display: flex; gap: 8px; padding-top: 8px; }
.bar-labels span { flex: 1; text-align: center; font-size: 12px; color: var(--muted); }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.chart-head h2 { margin: 0; }
.chart-head span { font-size: 13px; color: var(--muted); }

.hbars { display: flex; flex-direction: column; gap: 14px; }
.hbar .top { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.hbar .top b { font-weight: 600; }
.hbar .track { height: 8px; border-radius: 999px; background: var(--line-soft); margin-top: 6px; }
.hbar .fill { height: 8px; border-radius: 999px; background: var(--navy); }

.list { display: flex; flex-direction: column; }
.deadline { display: flex; align-items: center; gap: 14px; padding: 10px 0; border-top: 1px solid var(--line-soft); }
.deadline:first-child { border-top: 0; }
.cal { flex: none; width: 52px; height: 52px; border-radius: 10px; background: var(--soft); color: var(--deep); display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05; }
.cal b { font-size: 18px; }
.cal small { font-size: 11px; text-transform: uppercase; }
.deadline .txt { flex: 1; min-width: 0; }
.deadline .txt div:first-child { font-weight: 500; }
.deadline .txt div:last-child, .muted { font-size: 13px; color: var(--muted); }
.deadline .amt { font-weight: 600; }
.todo { width: 100%; text-align: left; border: 0; cursor: pointer; font: inherit; display: flex; gap: 12px; align-items: flex-start; padding: 14px; border-radius: 10px; background: var(--warn-bg); color: #4a2c00; text-decoration: none; margin-bottom: 10px; }
.todo:hover { color: #4a2c00; outline: 1px solid var(--warn-dot); }
.todo::before { content: ''; flex: none; width: 8px; height: 8px; margin-top: 7px; border-radius: 50%; background: var(--warn-dot); }
.todo b { display: block; }
.todo span { font-size: 13px; }

.dash-frame { width: 100%; min-height: 900px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }

.empty { text-align: center; padding: 56px 24px; color: var(--muted); }
.empty h2 { color: var(--ink); margin-bottom: 8px; }

.tooltip {
  position: fixed; pointer-events: none; z-index: 10; background: var(--ink); color: #fff;
  padding: 6px 10px; border-radius: 8px; font-size: 13px; white-space: nowrap;
}

/* ---------- Documents ---------- */
.drop {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  min-height: 210px; padding: 28px; text-align: center; cursor: pointer;
  border: 2px dashed #9fb0bd; border-radius: 16px; background: #fbfaf7; transition: background .15s, border-color .15s;
}
.drop:hover, .drop.over { background: var(--soft); border-color: var(--navy); }
.drop .ic { width: 56px; height: 56px; border-radius: 14px; background: var(--soft); display: flex; align-items: center; justify-content: center; }
.drop strong { font-size: 18px; font-weight: 600; }
.drop .link { color: var(--navy); font-weight: 600; text-decoration: underline; }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }

.queue { display: flex; flex-direction: column; gap: 10px; }
.queue:empty { display: none; }
.qitem { display: block; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff; min-width: 0; }
.qitem .meta { flex: 1; min-width: 0; }
.qitem .nm { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qitem .st { font-size: 13px; color: var(--muted); }
.qitem.ok .st { color: var(--good); font-weight: 500; }
.qitem.err .st { color: var(--bad); font-weight: 500; }
.progress { height: 6px; border-radius: 999px; background: var(--line-soft); margin-top: 8px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--navy); transition: width .2s; }
.qitem.ok .progress div { background: var(--good-dot); }
.qitem.err .progress div { background: var(--bad); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.toolbar h2 { margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.filters button { height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 500; }
.filters button[aria-pressed="true"] { background: var(--deep); border-color: var(--deep); color: #fff; }
.search { height: 42px; width: 260px; max-width: 100%; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

.table-wrap { overflow-x: auto; position: relative; }
table { width: 100%; min-width: 640px; border-collapse: collapse; }
th { text-align: left; font-size: 13px; font-weight: 500; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); }
td { padding: 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
td .nm { font-weight: 500; word-break: break-word; }
td .fd { font-size: 13px; color: var(--muted); }
td.num { white-space: nowrap; color: var(--muted); }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 500; white-space: nowrap; }
.badge.recu { background: var(--soft); color: var(--deep); }
.badge.cours { background: var(--warn-bg); color: var(--warn); }
.badge.fait { background: var(--good-bg); color: var(--good); }
.badge.cab { background: var(--line-soft); color: #353d4a; }

.notice { padding: 14px 16px; border-radius: 10px; background: var(--soft); color: var(--deep); font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.error-box { padding: 16px; border-radius: 10px; background: #fdecea; color: #7a1a12; }

/* ---------- Écran de connexion (démo / session expirée) ---------- */
.gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.gate .card { max-width: 440px; width: 100%; display: flex; flex-direction: column; gap: 14px; }
.gate img { width: 48px; height: 48px; object-fit: contain; }

/* ---------- Explorateur de documents ---------- */
.upload-card { display: flex; flex-direction: column; gap: 12px; }
.upload-card h2 { margin: 0; }
.drop .dest { font-size: 13px; color: var(--muted); }
.drop .dest code { font-family: inherit; background: var(--line-soft); padding: 1px 6px; border-radius: 6px; color: var(--ink); word-break: break-word; }
#explorer.over { outline: 2px dashed var(--navy); outline-offset: 4px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; padding: 3px; background: var(--bg); }
.seg button { height: 36px; padding: 0 14px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; font-weight: 500; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(23,43,58,.12); }
.tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn svg { flex: none; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }
.btn.danger:hover { background: #8f1c13; }

.crumbs ol { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 14px; }
.crumbs li { display: flex; align-items: center; gap: 4px; min-width: 0; }
.crumbs li + li::before { content: '›'; color: var(--muted); padding: 0 2px; }
.crumbs .crumb { border: 0; background: none; padding: 6px 8px; border-radius: 6px; color: var(--navy); cursor: pointer; font-weight: 500; }
.crumbs .crumb:hover { background: var(--soft); }
.crumbs [aria-current] { padding: 6px 8px; font-weight: 600; }

.explorer tr.is-dir td { background: transparent; }
.ename { display: flex; align-items: center; gap: 12px; min-width: 0; }
.ename > div { min-width: 0; }
.eic { flex: none; width: 36px; height: 36px; border-radius: 9px; display: flex; align-items: center; justify-content: center; background: var(--line-soft); color: var(--muted); }
.eic.dir { background: var(--soft); color: var(--navy); }
.open { border: 0; background: none; padding: 0; font-weight: 600; color: var(--ink); cursor: pointer; text-align: left; font-size: 15px; word-break: break-word; }
.open:hover { color: var(--navy); text-decoration: underline; }
td.acts { white-space: nowrap; text-align: right; }
td.acts > * + * { margin-left: 6px; }
.icon-btn { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); cursor: pointer; color: var(--ink); vertical-align: middle; }
.icon-btn:hover { border-color: var(--navy); }
tr[draggable="true"] { cursor: grab; }
tr.dragging { opacity: .45; }
tr.drop-on td, .crumb.drop-on { background: var(--soft) !important; box-shadow: inset 0 0 0 2px var(--navy); }
.empty-folder { padding: 36px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 12px; }
.tip { margin: 12px 0 0; }
.loc { border: 0; background: none; padding: 0; color: var(--muted); cursor: pointer; font-size: 13px; text-align: left; }
.loc:hover { color: var(--navy); text-decoration: underline; }
.filters .n { font-weight: 400; opacity: .7; margin-left: 2px; }
.notice { margin-bottom: 14px; }

.menu { position: fixed; z-index: 30; min-width: 190px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(23,43,58,.16); padding: 6px; display: flex; flex-direction: column; }
.menu button { text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 7px; cursor: pointer; font-size: 14px; }
.menu button:hover, .menu button:focus-visible { background: var(--soft); }
.menu button.danger { color: var(--bad); }

.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(23,43,58,.45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.dialog { width: 100%; max-width: 460px; max-height: calc(100vh - 32px); overflow: auto; background: var(--panel); border-radius: 16px; padding: 24px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dialog h2 { margin: 0; font-size: 20px; font-weight: 600; word-break: break-word; }
.dlg-body { display: flex; flex-direction: column; gap: 10px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; font-weight: 500; }
.field input { height: 46px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font-size: 16px; }
.field input:focus { border-color: var(--navy); outline: 2px solid var(--navy); outline-offset: 0; }
.err { color: var(--bad); font-size: 14px; }
.picker { border: 1px solid var(--line); border-radius: 12px; margin: 0; padding: 6px 0; max-height: 300px; overflow: auto; }
.pick { display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer; font-size: 14px; }
.pick:hover { background: var(--soft); }
.pick input { margin: 0; }
.pick svg { color: var(--navy); flex: none; }
.pick em { color: var(--muted); font-style: normal; }
.pick:has(input:disabled) { cursor: default; color: var(--muted); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100% - 32px); z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.err { background: var(--bad); }
@media (max-width: 640px) {
  .toolbar { flex-direction: column; align-items: stretch; }
  .search { width: 100%; }
}

/* ---------- Aperçu ---------- */
.open-file { border: 0; background: none; padding: 0; font-weight: 500; color: var(--ink); cursor: pointer; text-align: left; font-size: 15px; word-break: break-word; }
.open-file:hover { color: var(--navy); text-decoration: underline; }
.viewer-overlay { padding: 16px; }
.viewer { width: 100%; max-width: 1100px; height: calc(100vh - 32px); background: var(--panel); border-radius: 16px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.viewer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.viewer-head h2 { margin: 0; font-size: 17px; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.viewer-acts { display: flex; gap: 8px; }
.viewer-body { flex: 1; min-height: 0; background: var(--bg); display: flex; }
.viewer-frame { flex: 1; width: 100%; border: 0; background: #fff; }
.viewer-img { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 16px; }
.viewer-img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-text { flex: 1; margin: 0; padding: 18px; overflow: auto; font-size: 13px; white-space: pre-wrap; }
.viewer-empty { margin: auto; max-width: 460px; text-align: center; color: var(--muted); padding: 32px 20px; line-height: 1.6; }
.viewer-empty b { color: var(--ink); }
.viewer-body > .muted { margin: auto; }

/* ---------- Accès cabinet ---------- */
.staff-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding: 10px 14px; border-radius: 12px; background: #f3ede2; border: 1px solid #e2d6bf; color: #4d3c1e; font-size: 14px; }
.staff-bar b { font-weight: 600; }
.view { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.staff-chip { display: inline-block; margin-bottom: 4px; padding: 2px 8px; border-radius: 999px; background: var(--gold); color: #fff; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.btn.primary-lite { background: var(--soft); border-color: var(--soft); color: var(--deep); font-weight: 600; }
.btn.primary-lite:hover { border-color: var(--navy); }
.clients-table td { vertical-align: middle; }
