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

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --accent: #0f3460;
  --highlight: #533483;
  --text: #e0e0e0;
  --muted: #888;
  --border: #2a2a4a;
  --success: #4caf50;
  --error: #f44336;
  --warn: #ff9800;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 480px;
}

h1 { font-size: 1.8rem; margin-bottom: 0.25rem; }
.subtitle { color: var(--muted); font-size: 0.9rem; margin-bottom: 2rem; }

.section-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  padding: 0.6rem 1.2rem;
  transition: opacity 0.15s;
}
button:hover { opacity: 0.85; }

.btn-primary { background: var(--highlight); color: #fff; width: 100%; padding: 0.75rem; font-size: 1rem; }
.btn-secondary { background: var(--accent); color: var(--text); }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.82rem; }

input[type="text"], input[type="password"] {
  background: var(--accent);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  padding: 0.6rem 0.8rem;
  width: 100%;
  outline: none;
}
input:focus { border-color: var(--highlight); }

.divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

.pass-row { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.75rem; }
.pass-row input { flex: 1; }

.join-row { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.join-row input { flex: 1; }

label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; cursor: pointer; }

/* Room page */
#status-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
#status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
#status-dot.connected { background: var(--success); }
#status-dot.reconnecting { background: var(--warn); }
#status-dot.error { background: var(--error); }
#peers { margin-left: auto; color: var(--muted); }

#editor {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
textarea {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: var(--bg);
  color: var(--text);
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.95rem;
  line-height: 1.6;
  padding: 1rem;
  tab-size: 2;
}

#toolbar {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.pass-prompt {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
}
.pass-prompt .card { max-width: 360px; }
.pass-prompt h2 { margin-bottom: 1rem; }
.hidden { display: none !important; }

/* Tab bar */
#tab-bar {
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  height: 36px;
  overflow-x: auto;
  scrollbar-width: none;
}
#tab-bar::-webkit-scrollbar { display: none; }

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px 0 13px;
  border-right: 1px solid var(--border);
  cursor: pointer;
  position: relative;
  min-width: 72px;
  max-width: 160px;
  font-size: 0.82rem;
  color: var(--muted);
  user-select: none;
  transition: color 0.12s, background 0.12s;
  flex-shrink: 0;
  white-space: nowrap;
}
.tab:hover { color: var(--text); background: rgba(255,255,255,0.03); }

.tab.active {
  color: var(--text);
  background: var(--surface);
  border-top: 2px solid #7c5cbf;
  border-bottom: 1px solid var(--surface);
  margin-top: -1px;
  margin-bottom: -1px;
}

.tab-name {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.tab-close {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--muted);
  opacity: 0;
  flex-shrink: 0;
  transition: opacity 0.1s, background 0.1s, color 0.1s;
}
.tab:hover .tab-close,
.tab.active .tab-close { opacity: 1; }
.tab-close:hover { background: rgba(244,67,54,0.2); color: var(--error); }

/* Ocultar × cuando es la única pestaña */
.tab:only-of-type .tab-close { opacity: 0 !important; pointer-events: none; }

.tab-name-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--highlight);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  width: 80px;
  outline: none;
  padding: 0;
}

#tab-add {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  min-width: 36px;
  cursor: pointer;
  color: var(--muted);
  font-size: 20px;
  font-weight: 300;
  border-right: 1px solid var(--border);
  transition: color 0.12s, background 0.12s;
  flex-shrink: 0;
}
#tab-add:hover { color: var(--text); background: rgba(255,255,255,0.04); }

#tab-spacer { flex: 1; }
