:root {
  /* Palette - identique à Conductor / RadioTools */
  --bg-page: #101014;
  --bg-sidebar: #18181c;
  --bg-header: #1c1c22;
  --bg-surface: #25252b;
  --bg-input: #2f2f36;
  --bg-card: #1e1e24;

  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;

  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --border: #3f3f46;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -2px rgb(0 0 0 / 0.05);

  --font-family: 'Inter', system-ui, -apple-system, sans-serif;
  --radius: 8px;
}

/* Global */
html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg-page);
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

* {
  box-sizing: border-box;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-page);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #52525b;
}

/* Header */
header {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 1.2rem;
  color: #ffffff;
  white-space: nowrap;
}

.brand .by {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.85rem;
}

.logo {
  height: 40px;
  width: auto;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

.ico {
  font-size: 0.95rem;
}

/* Connection status */
.conn-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--warning);
  display: inline-block;
  transition: background-color 0.3s;
}

.status-dot.connected {
  background-color: var(--success);
  box-shadow: 0 0 6px var(--success);
}

.status-dot.disconnected {
  background-color: var(--danger);
}

/* Buttons */
.btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.2s;
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #4b5563;
  color: #fff;
  border: 1px solid #6b7280;
}

.btn-secondary:hover {
  background: #6b7280;
}

.btn-danger {
  background: var(--danger);
}

.btn-danger:hover {
  background: var(--danger-hover);
}

#toggle-peers-btn {
  display: none;
  /* visible en mobile */
}

/* Modal / Popup */
.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  inset: 0;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
}

.modal-content {
  background-color: var(--bg-surface);
  margin: 12% auto;
  padding: 24px;
  border: 1px solid var(--border);
  width: 90%;
  max-width: 400px;
  border-radius: var(--radius);
  text-align: center;
  position: relative;
  box-shadow: var(--shadow-lg);
}

.modal-content h2 {
  margin: 0 0 6px;
}

.modal-sub {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0 0 4px;
}

.close-modal {
  color: #aaa;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  position: absolute;
  right: 16px;
  top: 10px;
}

.close-modal:hover {
  color: #fff;
}

.qr-container {
  margin: 20px 0;
  background: white;
  padding: 10px;
  border-radius: var(--radius);
  display: inline-block;
}

.qr-container img {
  width: 160px;
  height: 160px;
  display: block;
}

.link-container {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

#share-link-input {
  flex: 1;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-main);
  font-family: monospace;
  min-width: 0;
}

/* Main Layout */
.main-container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar : profil + participants */
#peers-sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.profile-box {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.profile-label {
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.profile-edit {
  display: flex;
  gap: 8px;
}

#my-name-input {
  flex: 1;
  min-width: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text-main);
  font-weight: 600;
}

#my-name-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

#save-name-btn {
  padding: 8px 12px;
}

.peers-header {
  padding: 14px 16px 8px;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.peer-count {
  background: var(--primary);
  color: #fff;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 0.72rem;
  font-weight: 700;
}

#peers-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.peer-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  background: var(--bg-surface);
  border: 1px solid transparent;
}

.peer-item.local {
  border-color: var(--primary);
  box-shadow: 0 0 6px rgba(99, 102, 241, 0.2);
}

.peer-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.peer-meta {
  flex: 1;
  min-width: 0;
}

.peer-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.peer-tag {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.peer-tag .host-badge {
  color: var(--primary);
  font-weight: 700;
}

/* Chat panel */
#chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Messages */
.message {
  font-size: 1.05rem;
  line-height: 1.5;
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  align-self: flex-start;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.message.self {
  align-self: flex-end;
  background: var(--primary);
  border-color: var(--primary);
}

.message .msg-head {
  display: flex;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 3px;
}

.message .author {
  font-weight: 700;
  color: var(--primary);
  font-size: 0.82rem;
}

.message.self .author {
  color: #e0e7ff;
}

.message .time {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.message.self .time {
  color: #c7d2fe;
}

.message .msg-body {
  white-space: pre-wrap;
}

.message.system {
  align-self: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  font-size: 0.8rem;
  padding: 2px 0;
  max-width: 90%;
}

/* File message */
.file-msg {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 220px;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.file-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
}

.file-info {
  flex: 1;
  min-width: 0;
}

.file-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-size {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.message.self .file-size {
  color: #c7d2fe;
}

.file-progress {
  height: 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
}

.file-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--success);
  transition: width 0.15s linear;
}

.file-download {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--success);
  color: #fff;
  padding: 7px 12px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.85rem;
  justify-content: center;
}

.file-download:hover {
  filter: brightness(1.1);
}

.file-actions {
  display: flex;
  gap: 8px;
}

.file-actions:empty {
  display: none;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
}

.file-status {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.message.self .file-status {
  color: #e0e7ff;
}

/* Chat input */
.chat-input-area {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  background: var(--bg-header);
}

#chat-input {
  flex: 1;
  min-width: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-main);
  font-size: 0.95rem;
}

#chat-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

#file-btn {
  font-size: 1.1rem;
  padding: 8px 12px;
}

/* Drag & drop overlay */
.drop-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 50;
  background: rgba(16, 16, 20, 0.85);
  backdrop-filter: blur(3px);
  border: 3px dashed var(--primary);
  border-radius: var(--radius);
  margin: 8px;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.drop-overlay.active {
  display: flex;
}

.drop-inner {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
}

/* Mobile */
@media (max-width: 768px) {
  .brand span:not(.by) {
    font-size: 1rem;
  }

  .brand .by {
    display: none;
  }

  #toggle-peers-btn {
    display: inline-flex;
  }

  #peers-sidebar {
    position: fixed;
    top: 60px;
    left: -100%;
    bottom: 0;
    width: 80%;
    max-width: 300px;
    z-index: 1000;
    transition: left 0.3s ease-in-out;
    box-shadow: 5px 0 15px rgba(0, 0, 0, 0.5);
  }

  #peers-sidebar.open {
    left: 0;
  }

  .message {
    max-width: 88%;
  }

  #share-btn .label {
    display: none;
  }
}
