:root {
  --bg: #0f0d16;
  --bg-2: #16131f;
  --card: #1c1828;
  --card-2: #241f33;
  --line: #2f2942;
  --text: #f3f0fa;
  --muted: #a39cb8;
  --faint: #6f6887;
  --violet: #8b5cf6;
  --violet-2: #a78bfa;
  --red: #e5363d;
  --green: #34d399;
  --amber: #fbbf24;
  --blue: #60a5fa;
  --grad: linear-gradient(90deg, #f5c16c, #f472b6 50%, #a78bfa);
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: Poppins, system-ui, sans-serif; font-size: 15px; line-height: 1.5; }
body { min-height: 100vh; background: radial-gradient(1200px 600px at 80% -10%, rgba(139,92,246,.18), transparent 60%), radial-gradient(900px 500px at -10% 110%, rgba(244,114,182,.10), transparent 60%), var(--bg); background-attachment: fixed; }
a { color: var(--violet-2); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.hidden { display: none !important; }

/* Logo */
.logo { display: inline-flex; align-items: baseline; gap: 6px; font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.logo .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); display: inline-block; box-shadow: 0 0 12px rgba(229,54,61,.8); }
.logo .grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* Buttons & inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--card-2); color: var(--text); padding: 9px 16px; border-radius: 10px; cursor: pointer; font-weight: 500; font-size: 14px; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, opacity .15s; }
.btn:hover { border-color: #4a4163; background: #2c2640; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--violet); border-color: var(--violet); color: #fff; }
.btn.primary:hover { background: #7c4dee; }
.btn.light { background: #f3f0fa; color: #15111f; border-color: #f3f0fa; }
.btn.light:hover { background: #fff; }
.btn.danger { color: #fca5a5; }
.btn.danger:hover { border-color: #7f1d1d; background: #3a1820; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--card-2); }
.btn.small { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; padding: 12px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=file], select, textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--violet); }
textarea { resize: vertical; min-height: 90px; line-height: 1.55; }
textarea.script-body { min-height: 300px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13.5px; }
input[type=date] { color-scheme: dark; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .row, .row3 { grid-template-columns: 1fr; gap: 0; } }
.error { background: rgba(229,54,61,.12); border: 1px solid rgba(229,54,61,.35); color: #fecaca; padding: 10px 12px; border-radius: 10px; font-size: 13.5px; margin-bottom: 14px; }
.hint { font-size: 12.5px; color: var(--faint); }

/* Auth */
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth { width: 100%; max-width: 410px; }
.auth .logo { margin-bottom: 26px; justify-content: center; display: flex; }
.auth h1 { font-size: 30px; text-align: center; margin-bottom: 8px; }
.auth p.lead { text-align: center; color: var(--muted); margin: 0 0 24px; font-size: 14px; }
.auth .card { padding: 24px; }
.tabs { display: flex; gap: 4px; background: var(--bg-2); border: 1px solid var(--line); padding: 4px; border-radius: 12px; margin-bottom: 20px; }
.tabs button { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 8px 10px; border-radius: 9px; cursor: pointer; font-weight: 500; font-size: 13.5px; }
.tabs button.on { background: var(--card-2); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.04) inset; }
.tabs .count { font-size: 11.5px; background: rgba(139,92,246,.25); color: var(--violet-2); border-radius: 20px; padding: 1px 7px; margin-left: 4px; }
.auth-foot { text-align: center; margin-top: 18px; }
.loader { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--violet); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.card { background: rgba(28,24,40,.85); border: 1px solid var(--line); border-radius: var(--radius); backdrop-filter: blur(8px); }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 24px; background: rgba(15,13,22,.85); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar .right { display: flex; align-items: center; gap: 8px; }
.topbar .who { color: var(--muted); font-size: 13.5px; }
.layout { display: grid; grid-template-columns: 270px 1fr; min-height: calc(100vh - 63px); }
.sidebar { border-right: 1px solid var(--line); padding: 18px 14px; background: rgba(22,19,31,.6); }
.sidebar h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); margin: 4px 8px 10px; font-weight: 600; }
.client-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; text-align: left; background: transparent; border: 1px solid transparent; padding: 9px 10px; border-radius: 10px; cursor: pointer; color: var(--text); }
.client-item:hover { background: var(--card); }
.client-item.on { background: var(--card-2); border-color: var(--line); }
.client-item .meta { font-size: 12px; color: var(--faint); }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 20px; font-weight: 600; white-space: nowrap; }
.pill.red { background: rgba(229,54,61,.18); color: #fca5a5; }
.pill.gray { background: rgba(163,156,184,.14); color: var(--muted); }
.main { padding: 26px 30px 60px; max-width: 1050px; width: 100%; }
.main-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.main-head h1 { font-size: 26px; }
.main-head .sub { color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.mobile-clients { display: none; margin-bottom: 16px; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .mobile-clients { display: flex; gap: 8px; }
  .main { padding: 20px 16px 60px; }
  .topbar { padding: 12px 16px; }
  .topbar .who { display: none; }
}

.invite { padding: 16px 18px; margin-bottom: 20px; border-color: rgba(251,191,36,.35); background: rgba(251,191,36,.06); }
.invite .code { font-family: ui-monospace, Menlo, monospace; font-size: 20px; letter-spacing: .12em; font-weight: 700; color: var(--amber); }
.invite .top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* Script & invoice lists */
.list { display: grid; gap: 10px; }
.item { padding: 14px 16px; display: flex; align-items: center; gap: 14px; cursor: pointer; transition: border-color .15s, transform .15s; }
.item:hover { border-color: #4a4163; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; display: flex; gap: 10px; flex-wrap: wrap; }
.status { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 20px; white-space: nowrap; }
.status.brouillon { background: rgba(163,156,184,.14); color: var(--muted); }
.status.a_valider { background: rgba(251,191,36,.15); color: var(--amber); }
.status.valide { background: rgba(52,211,153,.14); color: var(--green); }
.status.tourne { background: rgba(96,165,250,.15); color: var(--blue); }
.status.a_payer { background: rgba(251,191,36,.15); color: var(--amber); }
.status.payee { background: rgba(52,211,153,.14); color: var(--green); }
.badge-new { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px; background: var(--red); color: #fff; margin-left: 8px; vertical-align: 2px; }
.badge-upd { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px; background: var(--violet); color: #fff; margin-left: 8px; vertical-align: 2px; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; border: 1px dashed var(--line); border-radius: var(--radius); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 6px 0 14px; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.stat { padding: 14px 16px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 2px; }
@media (max-width: 640px) { .stats { grid-template-columns: 1fr; } }

.inv-row { padding: 14px 16px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.inv-row .amount { font-weight: 700; font-size: 16px; min-width: 90px; text-align: right; }
.inv-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--card-2); display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--violet-2); border: 1px solid var(--line); flex-shrink: 0; }

.upload { padding: 18px; margin-bottom: 18px; }
.drop { border: 1.5px dashed #4a4163; border-radius: 12px; padding: 22px; text-align: center; color: var(--muted); cursor: pointer; margin-bottom: 14px; transition: border-color .15s, background .15s; }
.drop.over, .drop:hover { border-color: var(--violet); background: rgba(139,92,246,.06); }
.drop strong { color: var(--text); }

/* Script reading view */
.script-view { padding: 0; overflow: hidden; }
.script-view .head { padding: 20px 22px; border-bottom: 1px solid var(--line); }
.script-view .head h2 { font-size: 21px; }
.facts { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.facts b { color: var(--text); font-weight: 500; }
.script-text { padding: 20px 22px; white-space: pre-wrap; font-size: 15.5px; line-height: 1.75; }
.script-text .dir { display: block; color: var(--violet-2); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin: 14px 0 4px; }
.script-text .dir-inline { color: var(--violet-2); font-size: 13px; font-weight: 600; }
.prepare { margin: 0 22px 20px; padding: 14px 16px; background: var(--bg-2); border-radius: 12px; border: 1px solid var(--line); }
.prepare h4 { margin: 0 0 6px; font-size: 13px; color: var(--amber); }
.prepare div { white-space: pre-wrap; font-size: 14px; }
.feedback { margin: 0 22px 20px; }
.fb { font-size: 13.5px; padding: 10px 12px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); margin-bottom: 8px; }
.fb.valide { border-color: rgba(52,211,153,.35); }
.fb.modif { border-color: rgba(251,191,36,.35); }
.fb .when { font-size: 12px; color: var(--faint); }
.script-foot { display: flex; gap: 8px; flex-wrap: wrap; padding: 16px 22px; border-top: 1px solid var(--line); background: rgba(22,19,31,.6); }

.live { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); }
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); display: inline-block; }
.live.off i { background: var(--faint); box-shadow: none; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(5,4,10,.7); backdrop-filter: blur(4px); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal { width: 100%; max-width: 760px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; }
.modal.narrow { max-width: 440px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line); gap: 12px; }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 20px 22px; }
.modal-foot { display: flex; justify-content: space-between; gap: 8px; padding: 16px 22px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.modal-foot .r { display: flex; gap: 8px; margin-left: auto; }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: #f3f0fa; color: #15111f; padding: 10px 18px; border-radius: 12px; font-weight: 500; font-size: 14px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 100; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: #fecaca; }

/* Print: only the open script */
@media print {
  body { background: #fff !important; color: #000; }
  body.printing > *:not(#modal-root) { display: none !important; }
  body.printing .modal-bg { position: static; background: none; padding: 0; backdrop-filter: none; }
  body.printing .modal { border: 0; background: #fff; max-width: none; }
  body.printing .modal-head, body.printing .script-foot, body.printing .no-print { display: none !important; }
  body.printing .script-view, body.printing .card { background: #fff; border: 0; }
  body.printing .script-text, body.printing .facts, body.printing .facts b { color: #000; }
  body.printing .script-text .dir, body.printing .script-text .dir-inline { color: #555; }
  body.printing .prepare { background: #f4f4f4; border-color: #ddd; }
  body.printing .prepare h4 { color: #000; }
}
