:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #22263a;
  --border: #2e3148;
  --text: #e8eaf6;
  --text2: #8b90b8;
  --accent: #6c63ff;
  --accent2: #4ecca3;
  --danger: #e05c5c;
  --success: #4ecca3;
  --r: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
}

/* ── Topbar ── */
.topbar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.logo { font-size: 18px; font-weight: 700; color: var(--accent); }
.username-badge { font-size: 13px; color: var(--text2); }

/* ── Card ── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  max-width: 860px;
  margin: 24px auto;
  width: calc(100% - 32px);
}
.card h1 { font-size: 24px; margin-bottom: 4px; }
.card h2 { font-size: 20px; }
.card h3 { font-size: 16px; margin-bottom: 12px; color: var(--text2); font-weight: 600; }

/* ── Boutons ── */
button, .btn-small {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border-radius: var(--r);
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: opacity .15s, transform .1s;
  text-decoration: none;
  white-space: nowrap;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button:hover, .btn-small:hover { opacity: .85; transform: translateY(-1px); }
button:active { transform: translateY(0); opacity: .75; }
button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-small { padding: 6px 14px; font-size: 13px; }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
button.danger, .btn-small.danger { background: var(--danger); }
.btn-dl {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 12px; background: var(--success); color: var(--bg);
  border-radius: 6px; text-decoration: none; font-size: 12px; font-weight: 600;
  margin-left: 4px; white-space: nowrap; flex-shrink: 0;
}
.btn-preview {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 10px; background: var(--bg); color: var(--text2);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  white-space: nowrap; flex-shrink: 0;
}
.btn-preview:hover { border-color: var(--accent); color: var(--text); }

/* ── Formulaires ── */
.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 5px; font-size: 13px; color: var(--text2); font-weight: 500; }
input, select {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 13px;
  border-radius: var(--r);
  font-size: 14px;
  transition: border-color .15s;
  font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
.subtitle { color: var(--text2); font-size: 14px; margin-bottom: 22px; margin-top: 4px; }

/* ── Login ── */
body:has(#loginForm) .card { max-width: 380px; margin: 60px auto; }
.error-msg { background: rgba(224,92,92,.15); border: 1px solid var(--danger); color: var(--danger); padding: 9px 13px; border-radius: var(--r); font-size: 13px; margin-bottom: 14px; }

/* ── Actions row ── */
.actions-row { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 20px; }
.action-box { flex: 1; background: var(--bg3); border: 1px solid var(--border); border-radius: 12px; padding: 18px; }
.action-title { font-weight: 700; margin-bottom: 4px; font-size: 15px; }
.action-desc { color: var(--text2); font-size: 13px; margin-bottom: 14px; }
.separator { color: var(--text2); font-size: 13px; padding-top: 40px; flex-shrink: 0; }
.code-badge {
  font-family: monospace; font-size: 26px; font-weight: 700; letter-spacing: 6px;
  color: var(--accent2); background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--r); padding: 12px; text-align: center; cursor: pointer;
  margin-top: 12px; transition: border-color .2s; user-select: all;
}
.code-badge:hover { border-color: var(--accent2); }

/* ── Status ── */
.status-line {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: var(--bg3); border-radius: var(--r);
  margin-bottom: 18px; font-size: 14px; flex-wrap: wrap;
}
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dot.connected { background: var(--success); box-shadow: 0 0 6px var(--success); }
.dot.waiting { background: #ffc850; }
.dot.error { background: var(--danger); }

/* ── Transfer grid ── */
.transfer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── Drop zone ── */
.drop-zone {
  border: 2px dashed var(--border); border-radius: 12px; padding: 24px 16px;
  text-align: center; cursor: pointer; transition: all .2s;
  color: var(--text2); font-size: 14px;
}
.drop-zone:hover, .drop-zone.over { border-color: var(--accent); background: rgba(108,99,255,.05); }
.drop-zone svg { margin-bottom: 8px; opacity: .5; }
.drop-zone p { line-height: 1.5; }
.drop-zone small { font-size: 12px; opacity: .7; }

/* ── File items ── */
.file-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--bg3); border-radius: var(--r);
  border: 1px solid var(--border); margin-bottom: 6px; font-size: 13px;
  min-width: 0;
}
.fi-icon { font-size: 20px; flex-shrink: 0; }
.fi-info { flex: 1; overflow: hidden; min-width: 0; }
.fi-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fi-size { font-size: 12px; color: var(--text2); }
.fi-bar-wrap { height: 3px; background: var(--border); border-radius: 2px; margin-top: 5px; overflow: hidden; }
.fi-bar { height: 100%; background: var(--accent2); transition: width .15s; }
.fi-actions { display: flex; gap: 4px; flex-shrink: 0; align-items: center; }

/* ── Hint ── */
.hint { color: var(--text2); font-size: 13px; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 22px; right: 16px; z-index: 9999;
  padding: 11px 18px; border-radius: var(--r); font-size: 13px; font-weight: 600;
  opacity: 0; transform: translateY(20px); transition: all .25s; pointer-events: none;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--success); color: var(--bg); }
.toast.error { background: var(--danger); color: #fff; }
.toast.info { background: var(--accent); color: #fff; }

/* ── Admin ── */
.stats-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 24px; }
.stat-box { background: var(--bg3); border: 1px solid var(--border); border-radius: 10px; padding: 16px; text-align: center; }
.stat-val { font-size: 28px; font-weight: 700; color: var(--accent); }
.stat-lbl { font-size: 12px; color: var(--text2); margin-top: 2px; text-transform: uppercase; letter-spacing: .5px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { font-size: 12px; color: var(--text2); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.02); }
.role-badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.role-admin { background: rgba(108,99,255,.2); color: var(--accent); }
.role-user { background: rgba(78,204,163,.15); color: var(--accent2); }

/* ── Modal ── */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  z-index: 1000; display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 14px;
  padding: 24px; width: 360px; max-width: 100%;
}
.modal h3 { margin-bottom: 18px; font-size: 17px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ── Prévisualisation ── */
.preview-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.85);
  z-index: 2000; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 16px;
}
.preview-header {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; max-width: 900px; margin-bottom: 12px;
}
.preview-filename { font-size: 14px; color: var(--text2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-close {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 6px 14px; font-size: 13px; cursor: pointer; flex-shrink: 0;
}
.preview-body {
  width: 100%; max-width: 900px; max-height: calc(100vh - 100px);
  overflow: auto; border-radius: 10px; background: var(--bg2);
  display: flex; align-items: center; justify-content: center;
}
.preview-body img {
  max-width: 100%; max-height: calc(100vh - 110px);
  border-radius: 10px; object-fit: contain; display: block;
}
.preview-body iframe {
  width: 100%; height: calc(100vh - 110px);
  border: none; border-radius: 10px;
}
.preview-body pre {
  width: 100%; padding: 20px; font-family: monospace; font-size: 13px;
  color: var(--text); white-space: pre-wrap; word-break: break-all;
  line-height: 1.6; max-height: calc(100vh - 110px); overflow-y: auto;
}
.preview-unsupported {
  padding: 40px; text-align: center; color: var(--text2); font-size: 14px;
}
.preview-unsupported .big { font-size: 48px; margin-bottom: 12px; }

/* ── Responsive mobile ── */
@media (max-width: 620px) {
  .card { padding: 16px; margin: 12px auto; width: calc(100% - 24px); }

  /* Setup : colonne sur mobile */
  .actions-row { flex-direction: column; gap: 12px; }
  .separator { padding-top: 0; text-align: center; }

  /* Code badge plus petit */
  .code-badge { font-size: 20px; letter-spacing: 4px; }

  /* Transfer : colonne sur mobile */
  .transfer-grid { grid-template-columns: 1fr; gap: 16px; }

  /* Topbar : compacter */
  .topbar { padding: 10px 12px; }
  .logo { font-size: 16px; }
  .username-badge { display: none; }

  /* Boutons full width sur mobile dans actions-box */
  .action-box button { width: 100%; justify-content: center; }

  /* Join input + bouton */
  .join-row { flex-direction: column; }
  .join-row input { font-size: 20px; }

  /* Table admin : cacher colonne date */
  .hide-mobile { display: none; }

  /* File items : boutons en dessous si pas de place */
  .file-item { flex-wrap: wrap; }
  .fi-actions { margin-top: 4px; width: 100%; justify-content: flex-end; }

  /* Toast en bas au centre */
  .toast { right: 50%; transform: translateX(50%) translateY(20px); }
  .toast.show { transform: translateX(50%) translateY(0); }

  /* Stats admin */
  .stats-row { grid-template-columns: 1fr 1fr; }

  /* Modal plein écran sur petit mobile */
  .modal { width: 100%; }

  /* Preview plein écran */
  .preview-bg { padding: 8px; }
}

@media (max-width: 400px) {
  .code-badge { font-size: 18px; letter-spacing: 3px; }
  .card h2 { font-size: 17px; }
}