/* ========== Reset & Base ========== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #0f0f13;
  color: #e0e0e0;
  overflow: hidden;
}

/* ========== App Layout ========== */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ========== Header ========== */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: #1a1a24;
  border-bottom: 1px solid #2a2a3a;
  flex-shrink: 0;
}
.logo {
  font-size: 18px;
  font-weight: 600;
  color: #fff;
}
.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #888;
}
.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.dot.online { background: #34d399; box-shadow: 0 0 6px #34d39966; }
.dot.offline { background: #6b7280; }
.dot.connecting { background: #fbbf24; box-shadow: 0 0 6px #fbbf2466; }
#my-name-display {
  color: #888;
  margin-left: 4px;
}
#my-name-display::before { content: "· "; }

/* ========== Main ========== */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ========== Sidebar ========== */
#sidebar {
  width: 280px;
  background: #14141e;
  border-right: 1px solid #2a2a3a;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

/* ========== Identity Code ========== */
#my-code-section {
  padding: 12px 16px;
  border-bottom: 1px solid #2a2a3a;
  text-align: center;
}
.section-label {
  font-size: 11px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}
#my-code {
  font-size: 28px;
  font-weight: 700;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  color: #818cf8;
  letter-spacing: 6px;
  padding: 4px 0;
}
.section-hint {
  font-size: 11px;
  color: #555;
  margin-top: 4px;
  line-height: 1.4;
}

/* ========== Search ========== */
#search-section {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid #2a2a3a;
}
#search-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #333;
  border-radius: 6px;
  background: #1e1e2a;
  color: #e0e0e0;
  font-size: 14px;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  text-align: center;
  letter-spacing: 4px;
  outline: none;
}
#search-input:focus { border-color: #818cf8; }
#search-btn {
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background: #818cf8;
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
#search-btn:hover { background: #7379e8; }
#search-btn:disabled { background: #4a4a5a; cursor: not-allowed; }
#search-status {
  font-size: 12px;
  padding: 4px 16px 8px;
  text-align: center;
  min-height: 20px;
}
#search-status.search-error { color: #f87171; }
#search-status.search-success { color: #34d399; }

/* ========== Badges ========== */
.badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 4px;
  vertical-align: middle;
}
.badge.lan {
  background: #065f4622;
  color: #34d399;
  border: 1px solid #34d39933;
}
.badge.remote {
  background: #818cf822;
  color: #818cf8;
  border: 1px solid #818cf833;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid #2a2a3a;
}
.sidebar-header h3 { font-size: 14px; font-weight: 600; }
.sidebar-header span {
  font-size: 12px;
  background: #2a2a3a;
  color: #888;
  padding: 2px 10px;
  border-radius: 12px;
}

/* Nickname */
#nickname-section {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid #2a2a3a;
}
#nickname-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #333;
  border-radius: 6px;
  background: #1e1e2a;
  color: #e0e0e0;
  font-size: 13px;
  outline: none;
}
#nickname-input:focus { border-color: #6366f1; }
#nickname-btn {
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background: #6366f1;
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
#nickname-btn:hover { background: #5558e6; }

/* User List */
#user-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.user-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid #1e1e2a;
}
.user-item:hover { background: #1e1e2a; }
.user-item.selected { background: #1e1e2a; border-left: 3px solid #6366f1; }
.user-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 14px; font-weight: 500; }
.user-detail {
  font-size: 12px;
  color: #666;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-empty {
  text-align: center;
  color: #555;
  padding: 40px 20px;
  font-size: 13px;
}

/* ========== Content Area ========== */
#content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0f0f13;
  position: relative;
}

/* Placeholder */
#placeholder {
  text-align: center;
  color: #555;
}
.placeholder-icon { font-size: 64px; margin-bottom: 16px; }
#placeholder p { font-size: 14px; }

/* Chat Area */
#chat-area {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}
#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: #1a1a24;
  border-bottom: 1px solid #2a2a3a;
}
#chat-partner { font-size: 15px; font-weight: 600; }
#chat-mode {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 12px;
  background: #2a2a3a;
  color: #888;
}
#chat-mode.p2p { background: #065f4622; color: #34d399; }
#chat-mode.relay { background: #6366f122; color: #818cf8; }
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
}
.msg {
  margin-bottom: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  max-width: 70%;
  word-break: break-all;
}
.msg.sent {
  background: #6366f1;
  color: #fff;
  margin-left: auto;
}
.msg.received {
  background: #1e1e2a;
  color: #e0e0e0;
  margin-right: auto;
}
.msg.system {
  background: transparent;
  text-align: center;
  color: #666;
  font-size: 12px;
  max-width: 100%;
  margin: 8px 0;
}
.msg .file-info {
  display: flex;
  align-items: center;
  gap: 8px;
}
.msg .file-icon { font-size: 24px; }
.msg .file-name { font-size: 14px; font-weight: 500; }
.msg .file-size { font-size: 12px; opacity: 0.7; }
.file-progress {
  margin-top: 8px;
  height: 4px;
  background: #ffffff33;
  border-radius: 2px;
  overflow: hidden;
}
.file-progress-bar {
  height: 100%;
  background: #34d399;
  transition: width 0.3s;
}
.download-link {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 14px;
  background: #34d399;
  color: #000;
  border-radius: 6px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
}

/* Input Area */
#chat-input-area {
  padding: 16px 24px;
  border-top: 1px solid #2a2a3a;
  background: #14141e;
}
#drop-zone {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  border: 2px dashed #333;
  border-radius: 8px;
  color: #666;
  font-size: 13px;
}
#drop-zone.dragover { border-color: #6366f1; background: #6366f111; }
#file-input { display: none; }
.file-label {
  padding: 6px 16px;
  background: #6366f1;
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.file-label:hover { background: #5558e6; }

/* ========== Overlay ========== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.overlay-box {
  background: #1a1a24;
  border: 1px solid #2a2a3a;
  border-radius: 12px;
  padding: 32px;
  min-width: 360px;
  text-align: center;
}
.overlay-box h3 { font-size: 18px; margin-bottom: 12px; }
.overlay-box p { color: #aaa; margin-bottom: 20px; font-size: 14px; }
.btn-group { display: flex; gap: 12px; justify-content: center; }
.btn {
  padding: 10px 28px;
  border: 1px solid #333;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  background: #2a2a3a;
  color: #e0e0e0;
  transition: 0.15s;
}
.btn:hover { background: #35354a; }
.btn.primary { background: #6366f1; color: #fff; border-color: #6366f1; }
.btn.primary:hover { background: #5558e6; }

/* ========== Scrollbar ========== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }