/* Panel Rivox — même direction que le site public : ciel crème, orange du logo.
   « --red » garde son nom d'origine mais porte désormais l'orange profond d'accent. */
:root {
  --bg: #fdf3e2; --panel: #fffaf1; --panel-2: #fbe9d6; --line: #f0d3b5; --text: #3a1b0d; --muted: #8a5a3c;
  --red: #c2451a; --sun: #f0721e; --green: #1f7a3d; --amber: #9a5b00; --blue: #1d5fbf; --violet: #7a3fb8;
  --lift: 0 1px 0 #fff inset, 0 10px 30px -18px rgba(194, 69, 26, .45);
  --rim: 0 0 0 1.5px #fff, 0 0 0 2.5px rgba(240, 114, 30, .28), 0 0 30px rgba(247, 160, 75, .35);
  --radius: 12px; --display: 'Bebas Neue', Impact, sans-serif; --body: 'Inter', system-ui, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--body); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem;
  background: url('/img/palms-haze.svg') center bottom / auto 34% repeat-x, radial-gradient(circle at 80% 100%, rgba(247,160,75,.45), transparent 55%), var(--bg); }
.auth-card { width: min(400px, 100%); background: var(--panel); border: 0; box-shadow: var(--rim); border-radius: 16px; padding: 2rem; display: grid; gap: 1rem; }
.auth-card h1 { font: 2.2rem/1 var(--display); letter-spacing: .03em; }
.logo { display: flex; align-items: center; gap: .6rem; font: 22px/1 var(--display); letter-spacing: .08em; text-decoration: none; }
/* Le « R » d'origine est remplacé par le portrait du logo. */
.logo b { width: 36px; height: 36px; border-radius: 50%; background: url('/img/rivox-avatar.webp') center / cover; box-shadow: var(--rim); color: transparent; overflow: hidden; flex: none; }

/* Layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 1.2rem .8rem; display: flex; flex-direction: column; gap: 1.4rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side nav { display: grid; gap: 2px; }
.side nav a { display: flex; align-items: center; gap: .7rem; padding: .6rem .8rem; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500; transition: background .15s, color .15s; }
.side nav a:hover { background: var(--panel-2); color: var(--text); }
.side nav a.active { background: rgba(240,114,30,.16); color: var(--text); font-weight: 600; }
.side nav a.active .ico { color: var(--red); }
.side .sep { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: #b98f72; padding: .9rem .8rem .3rem; }
.ico { width: 18px; text-align: center; }
.count { margin-left: auto; background: var(--sun); color: #fff; box-shadow: 0 0 12px rgba(240,114,30,.7); border-radius: 99px; font-size: 11px; padding: 0 .45rem; font-weight: 700; }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 1rem; display: grid; gap: .6rem; }
.me { display: flex; align-items: center; gap: .6rem; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--line); color: var(--red); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.main { padding: clamp(1rem, 3vw, 2rem); min-width: 0; }
.topbar { display: none; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.page-head h1 { font: 2.2rem/1 var(--display); letter-spacing: .03em; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.back { color: var(--muted); text-decoration: none; font-size: 13px; display: inline-block; margin-bottom: .3rem; }
.back:hover { color: var(--red); }

/* Controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; transition: border-color .15s, background .15s; }
.btn:hover { border-color: #e8b78c; background: #f8dcc2; }
.btn-primary { background: linear-gradient(180deg, #dd5a1c, var(--red)); border-color: var(--red); color: #fff; box-shadow: 0 0 22px -4px rgba(240,114,30,.6); }
.btn-primary:hover { background: #a83a14; border-color: #a83a14; }
.btn-danger { color: #b3261e; }
.btn-danger:hover { border-color: #b3261e; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--panel-2); color: var(--text); }
.btn-sm { padding: .3rem .6rem; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
label.field { display: grid; gap: .35rem; font-size: 12px; font-weight: 600; color: var(--muted); }
input, select, textarea { width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; font-size: 14px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--sun); box-shadow: 0 0 0 3px rgba(240,114,30,.2); }
input[type=checkbox] { width: auto; accent-color: var(--red); }
textarea { resize: vertical; min-height: 70px; }
input:disabled, select:disabled, textarea:disabled { opacity: .7; }
.check { display: flex; align-items: center; gap: .5rem; font-size: 13px; color: var(--text); font-weight: 500; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: .9rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .9rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: .9rem; }
.span-2 { grid-column: span 2; }
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: 1rem; }
.toolbar input { max-width: 300px; }
.toolbar select { width: auto; }

/* Cards & tables */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; box-shadow: var(--lift); }
.card h2 { font-size: 15px; margin-bottom: 1rem; display: flex; justify-content: space-between; align-items: center; }
.card + .card { margin-top: 1rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; text-decoration: none; display: block; box-shadow: var(--lift); }
a.kpi:hover { border-color: var(--sun); }
.kpi span { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.kpi strong { display: block; font: 2.1rem/1.1 var(--display); letter-spacing: .02em; margin-top: .3rem; }
.kpi small { color: var(--muted); }
.kpi.alert strong { color: var(--red); }
.dash-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 1rem; }
.dash-grid .card + .card { margin-top: 0; }
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--lift); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .7rem .9rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; background: var(--panel-2); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover { background: var(--panel-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }
.mini-list { display: grid; }
.mini-list a { display: flex; justify-content: space-between; gap: 1rem; padding: .6rem 0; border-bottom: 1px solid var(--line); text-decoration: none; align-items: center; }
.mini-list a:last-child { border: 0; }
.mini-list a:hover strong { color: var(--red); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: .35rem; padding: .15rem .55rem; border-radius: 99px; font-size: 11px; font-weight: 700; letter-spacing: .02em; border: 1px solid; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-grey { color: #6f6258; border-color: #d9c9b8; background: rgba(111,98,88,.08); }
.b-blue { color: #1d5fbf; border-color: rgba(29,95,191,.35); background: rgba(29,95,191,.08); }
.b-green { color: #1f7a3d; border-color: rgba(31,122,61,.35); background: rgba(31,122,61,.08); }
.b-red { color: #b3261e; border-color: rgba(179,38,30,.35); background: rgba(179,38,30,.07); }
.b-amber { color: #9a5b00; border-color: rgba(154,91,0,.35); background: rgba(251,191,36,.14); }
.b-violet { color: #7a3fb8; border-color: rgba(122,63,184,.35); background: rgba(122,63,184,.08); }

/* Chart */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 200px; padding-top: 1rem; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar i { display: block; width: 100%; max-width: 38px; background: linear-gradient(180deg, #f7a04b, var(--red)); box-shadow: 0 0 14px -2px rgba(247,160,75,.7); border-radius: 5px 5px 2px 2px; min-height: 2px; position: relative; }
.bar i:hover::after { content: attr(data-v); position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; border: 0; padding: 2px 6px; border-radius: 4px; font-size: 11px; font-style: normal; white-space: nowrap; }
.bar span { font-size: 10px; color: var(--muted); text-transform: uppercase; }

/* Doc editor */
.editor { display: grid; grid-template-columns: 1fr 320px; gap: 1rem; align-items: start; }
.items { width: 100%; }
.items th, .items td { padding: .45rem .4rem; white-space: normal; }
.items td input { padding: .45rem .55rem; }
.items .c-qty { width: 80px; } .items .c-price { width: 120px; } .items .c-total { width: 110px; } .items .c-del { width: 36px; }
.items textarea { min-height: 38px; height: 38px; padding: .45rem .55rem; }
.items-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .8rem; }
.totals { display: grid; gap: .5rem; }
.totals div { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
.totals .grand { font-size: 18px; font-weight: 700; border-top: 1px solid var(--line); padding-top: .7rem; margin-top: .3rem; }
.sticky { position: sticky; top: 1rem; display: grid; gap: 1rem; }
.sticky .card + .card { margin-top: 0; }
.stack { display: grid; gap: .9rem; }
.btn-col { display: grid; gap: .5rem; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.btn-send { background: var(--text); color: #fdf3e2; border-color: var(--text); }
.btn-send:hover { background: #5a2c17; border-color: #5a2c17; }
.share-actions { display: flex; flex-wrap: wrap; gap: .5rem; padding-top: .3rem; }
.note { background: rgba(251,191,36,.18); border: 1px solid rgba(154,91,0,.3); color: #6b4000; border-radius: 8px; padding: .6rem .8rem; font-size: 13px; }
.note a { color: var(--red); }

/* Leads */
.leads { display: grid; gap: .8rem; }
.lead { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; display: grid; gap: .6rem; box-shadow: var(--lift); }
.lead.is-new { border-left: 3px solid var(--sun); }
.lead-head { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; justify-content: space-between; }
.lead-head h3 { font-size: 15px; }
.lead-meta { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; font-size: 12px; color: var(--muted); }
.lead-meta b { color: var(--text); font-weight: 600; }
.lead p { white-space: pre-wrap; }
.lead-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.lead-actions select { width: auto; padding: .3rem .5rem; font-size: 12px; }

/* Portfolio */
.pf-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.pf { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--lift); }
.pf.hidden-item { opacity: .5; }
.pf img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; }
.pf-body { padding: .8rem 1rem 1rem; display: grid; gap: .4rem; }
.pf-body h3 { font-size: 14px; }
.pf-actions { display: flex; gap: .4rem; margin-top: .3rem; }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(43,20,11,.55); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 1rem; z-index: 100; animation: fade .15s; }
.modal { width: min(560px, 100%); max-height: calc(100vh - 2rem); overflow-y: auto; background: var(--panel); border: 0; box-shadow: var(--rim); border-radius: 14px; }
.modal header { padding: 1.1rem 1.3rem; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal header h2 { font-size: 16px; }
.modal .body { padding: 1.3rem; display: grid; gap: .9rem; }
.modal footer { padding: 1rem 1.3rem; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: .5rem; }
.modal .err { color: #b3261e; font-size: 13px; }
@keyframes fade { from { opacity: 0; } }

/* Toasts */
#toasts { position: fixed; bottom: 1rem; right: 1rem; display: grid; gap: .5rem; z-index: 200; }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--green); padding: .7rem 1rem; border-radius: 8px; box-shadow: 0 10px 30px -8px rgba(58,27,13,.35); animation: fade .2s; max-width: 340px; }
.toast.err { border-left-color: var(--red); }

/* Responsive */
@media (max-width: 1100px) { .editor, .dash-grid { grid-template-columns: 1fr; } .sticky { position: static; } }
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 90; transform: translateX(-100%); transition: transform .25s; }
  .side.open { transform: none; box-shadow: 20px 0 60px rgba(58,27,13,.3); }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: .7rem 1rem; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 80; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .items thead { display: none; }
  .items tr { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: .4rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
  .items td { border: 0; padding: 0; }
  .items td:first-child { grid-column: 1 / -1; }
  .items .c-qty, .items .c-price, .items .c-total { width: auto; }
}

/* ───────── Thème clair / sombre ───────── */
:root { --err: #b3261e; }
[data-theme-toggle]::before { content: '☾ Sombre'; }
[data-theme="dark"] [data-theme-toggle]::before { content: '☀ Clair'; }
[data-theme="dark"] {
  --bg: #1a0e08; --panel: #24130b; --panel-2: #2f1a0f; --line: #4a2a18; --text: #fdebd6; --muted: #c9a183;
  --red: #f0803a; --sun: #ff8a3d; --green: #6fd08c; --amber: #f2b84b; --blue: #7fb2ff; --violet: #c79bff; --err: #ff8f85;
  --lift: 0 1px 0 rgba(255, 220, 180, .06) inset, 0 12px 30px -18px #000;
  --rim: 0 0 0 1.5px rgba(255, 214, 170, .5), 0 0 30px rgba(240, 114, 30, .3);
  color-scheme: dark;
}
[data-theme="dark"] .auth { background: url('/img/palms-haze.svg') center bottom / auto 34% repeat-x, radial-gradient(circle at 80% 100%, rgba(240,114,30,.35), transparent 55%), var(--bg); }
[data-theme="dark"] .side .sep { color: #8f6a4f; }
[data-theme="dark"] .btn:hover { border-color: #6b3a1e; background: #3a2012; }
[data-theme="dark"] .btn-primary, [data-theme="dark"] .btn-primary:hover { background: linear-gradient(180deg, #d4521a, #b03d14); border-color: #d4521a; color: #fff; }
[data-theme="dark"] .btn-danger { color: var(--err); }
[data-theme="dark"] .btn-danger:hover { border-color: var(--err); }
[data-theme="dark"] .btn-send { background: var(--text); color: var(--bg); border-color: var(--text); }
[data-theme="dark"] .btn-send:hover { background: #e8cdb3; border-color: #e8cdb3; }
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea { background: #1f1009; }
[data-theme="dark"] .b-grey { color: #c4b5a6; border-color: #5a4636; background: rgba(196,181,166,.08); }
[data-theme="dark"] .b-blue { color: #7fb2ff; border-color: rgba(127,178,255,.35); background: rgba(127,178,255,.08); }
[data-theme="dark"] .b-green { color: #6fd08c; border-color: rgba(111,208,140,.35); background: rgba(111,208,140,.08); }
[data-theme="dark"] .b-red { color: #ff8f85; border-color: rgba(255,143,133,.35); background: rgba(255,143,133,.08); }
[data-theme="dark"] .b-amber { color: #f2b84b; border-color: rgba(242,184,75,.35); background: rgba(242,184,75,.08); }
[data-theme="dark"] .b-violet { color: #c79bff; border-color: rgba(199,155,255,.35); background: rgba(199,155,255,.08); }
[data-theme="dark"] .bar i:hover::after { background: var(--text); color: var(--bg); }
[data-theme="dark"] .note { background: rgba(242,184,75,.1); border-color: rgba(242,184,75,.3); color: #f6d98f; }
[data-theme="dark"] .modal .err { color: var(--err); }
[data-theme="dark"] .modal-back { background: rgba(0,0,0,.7); }
