/* DM Mono */
@font-face {
  font-family: 'DM Mono';
  src: url('./fonts/DMMono-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'DM Mono';
  src: url('./fonts/DMMono-Medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
/* Syne */
@font-face {
  font-family: 'Syne';
  src: url('./fonts/Syne-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Syne';
  src: url('./fonts/Syne-SemiBold.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Syne';
  src: url('./fonts/Syne-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

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

/* ─── Dark theme (default) ───────────────────────────────── */
:root,
[data-theme="dark"] {
  --bg:        #0d0d0d;
  --surface:   #141414;
  --surface2:  #1a1a1a;
  --border:    #242424;
  --border2:   #303030;
  --text:      #e8e4dc;
  --muted:     #5a5a5a;
  --accent:    #c8f23a;
  --accent2:   #3af2b8;
  --danger:    #f23a3a;
  --shadow:    rgba(0,0,0,0.5);
  --sel-bg:    #1a2200;
  --dir-send-bg:  #0d1f1a;
  --dir-send-bd:  #1a3d30;
  --dir-recv-bg:  #1a1a00;
  --dir-recv-bd:  #333300;
  --log-time:  #333;
  --mono:     'DM Mono', monospace;
  --sans:     'Syne', sans-serif;
}

/* ─── Light theme ────────────────────────────────────────── */
[data-theme="light"] {
  --bg:        #f4f3ef;
  --surface:   #ffffff;
  --surface2:  #f9f8f5;
  --border:    #e2e0d8;
  --border2:   #d0cec4;
  --text:      #1a1a1a;
  --muted:     #9a9890;
  --accent:    #5a8a00;
  --accent2:   #007a5a;
  --danger:    #cc2200;
  --shadow:    rgba(0,0,0,0.12);
  --sel-bg:    #eef5d0;
  --dir-send-bg:  #e8f5f0;
  --dir-send-bd:  #b0ddd0;
  --dir-recv-bg:  #f5f5e0;
  --dir-recv-bd:  #d0d0a0;
  --log-time:  #bbb;
}

/* ─── Base ───────────────────────────────────────────────── */
html { height: 100%; }

body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background 0.2s, color 0.2s;
}

/* ─── Noise ──────────────────────────────────────────────── */
.noise {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 999;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px 200px;
}

/* ─── Header ─────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
}

.logo {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.5px;
  color: var(--text);
}

.logo a { color: inherit; text-decoration: none; }

.dot { color: var(--accent); }

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ─── Theme toggle ───────────────────────────────────────── */
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
  flex-shrink: 0;
}

.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* Hiện/ẩn icon theo theme */
[data-theme="dark"]  .theme-icon-dark  { display: none; }
[data-theme="dark"]  .theme-icon-light { display: flex; }
[data-theme="light"] .theme-icon-light { display: none; }
[data-theme="light"] .theme-icon-dark  { display: flex; }

.theme-icon { align-items: center; justify-content: center; }

/* ─── Device badge ───────────────────────────────────────── */
.device-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: border-color 0.2s, color 0.2s;
  white-space: nowrap;
  overflow: hidden;
  max-width: 160px;
}

.device-badge:hover { border-color: var(--border2); color: var(--text); }

.device-badge span#my-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  transition: background 0.3s;
}

.status-dot.online { background: var(--accent); box-shadow: 0 0 6px var(--accent); }

/* ─── Mobile tabs ────────────────────────────────────────── */
.mobile-tabs { display: none; }
/* Ẩn mặc định — chỉ hiện trong media query mobile */
.mobile-peers-bar { display: none; }

/* ─── Main layout ────────────────────────────────────────── */
main {
  display: grid;
  grid-template-columns: 220px 1fr 220px;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.panel {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background 0.2s, border-color 0.2s;
}

.panel:last-child { border-right: none; }

.panel-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--muted);
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* ─── Peers panel ────────────────────────────────────────── */
.peers-panel { background: var(--surface); }

#peer-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 8px;
}

.peer-empty {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  padding: 16px;
  text-align: center;
}

.peer-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid transparent;
}

.peer-item:hover { background: var(--border); }

.peer-item.selected {
  background: var(--sel-bg);
  border-color: var(--accent);
}

.peer-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--border2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
  font-family: var(--mono);
}

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

.peer-status {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
}

.peer-self { cursor: default; opacity: 0.55; }
.peer-self:hover { background: transparent; }
.avatar-self { color: var(--muted); border: 1px dashed var(--border2); }

.badge-self {
  display: inline-block;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--bg);
  background: var(--muted);
  border-radius: 3px;
  padding: 1px 5px;
  vertical-align: middle;
  margin-left: 4px;
  text-transform: uppercase;
}

/* ─── Drop panel ─────────────────────────────────────────── */
.drop-panel {
  background: var(--bg);
  align-items: stretch;
  justify-content: center;
  padding: 32px;
  gap: 24px;
  overflow-y: auto;
}

.drop-zone {
  flex: 1;
  border: 1.5px dashed var(--border2);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 24px;
  transition: border-color 0.2s, background 0.2s;
  cursor: default;
  min-height: 260px;
}

.drop-zone.dragover {
  border-color: var(--accent);
  background: var(--sel-bg);
}

.drop-icon {
  color: var(--muted);
  transition: color 0.2s, transform 0.2s;
}

.drop-zone.dragover .drop-icon { color: var(--accent); transform: translateY(-4px); }

.drop-text { font-weight: 600; font-size: 16px; color: var(--text); }
.drop-sub  { font-size: 13px; color: var(--muted); }

.btn-browse {
  display: inline-block;
  padding: 9px 20px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 6px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.btn-browse:hover {
  border-color: var(--accent);
  background: var(--sel-bg);
  color: var(--accent);
}

.drop-hint {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  text-align: center;
}

.drop-hint.ready { color: var(--accent2); }

/* ─── Log panel ──────────────────────────────────────────── */
.log-panel { background: var(--surface); }

#log-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.log-item {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  line-height: 1.5;
  animation: fadeIn 0.2s ease;
}

.log-item .log-time { color: var(--log-time); margin-right: 6px; }
.log-item.info  .log-msg { color: var(--text); }
.log-item.ok    .log-msg { color: var(--accent); }
.log-item.warn  .log-msg { color: #f2a63a; }
.log-item.err   .log-msg { color: var(--danger); }

/* ─── Transfer section ───────────────────────────────────── */
.transfer-section {
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  max-height: 240px;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
}

.transfer-section.hidden { display: none; }

.transfer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.btn-clear {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.btn-clear:hover { color: var(--danger); border-color: var(--danger); }

.transfer-section .queue {
  overflow-y: auto;
  padding: 12px 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
  align-content: start;
}

/* ─── Queue item ─────────────────────────────────────────── */
.queue-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  transition: background 0.2s, border-color 0.2s;
}

.queue-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.queue-file-name {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.queue-file-size {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
}

.queue-direction {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.queue-direction.sending  { background: var(--dir-send-bg); color: var(--accent2); border: 1px solid var(--dir-send-bd); }
.queue-direction.receiving { background: var(--dir-recv-bg); color: var(--accent);  border: 1px solid var(--dir-recv-bd); }

.progress-bar {
  height: 3px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 99px;
  width: 0%;
  transition: width 0.1s linear;
}

.progress-fill.sending   { background: var(--accent2); }
.progress-fill.receiving { background: var(--accent); }

.queue-status {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
}

.queue-status.sending   { color: var(--accent2); }
.queue-status.receiving { color: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.queue-status.done      { color: var(--accent); }
.queue-status.rejected  { color: var(--danger); }
.queue-status.waiting   { color: var(--muted); }

/* ─── Modals ─────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
  animation: fadeIn 0.15s ease;
}

.modal.hidden { display: none; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 16px;
  padding: 32px 28px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: 0 24px 64px var(--shadow);
  transition: background 0.2s;
}

.modal-icon { font-size: 36px; }
.modal-title { font-size: 18px; font-weight: 700; }

.modal-sub {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

#modal-info {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  text-align: left;
  max-height: 180px;
  overflow-y: auto;
  width: 100%;
  padding: 0 4px;
}

.modal-actions { display: flex; gap: 10px; margin-top: 4px; flex-wrap: wrap; justify-content: center; }

.btn-accept {
  padding: 10px 24px;
  background: var(--accent);
  color: #0d0d0d;
  border: none;
  border-radius: 6px;
  font-family: var(--sans);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-accept:hover { opacity: 0.85; }

.btn-reject {
  padding: 10px 24px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border2);
  border-radius: 6px;
  font-family: var(--sans);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.btn-reject:hover { border-color: var(--danger); color: var(--danger); }

.name-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.name-input:focus { border-color: var(--accent); }

/* ─── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 99px; }

/* ─── Animations ─────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ─── Mobile responsive ──────────────────────────────────── */
@media (max-width: 640px) {
  body { overflow: hidden; }

  header { padding: 12px 16px; }
  .logo { font-size: 17px; }
  .device-badge { max-width: 120px; font-size: 12px; padding: 5px 10px; }

  /* Tab bar — chỉ 2 tab: Gửi & Log */
  .mobile-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
  }

  /* Ẩn tab "Thiết bị" — đã gộp vào tab Gửi */
  .tab-btn[data-tab="peers"] { display: none; }

  .tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 10px 8px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    font-family: var(--sans);
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
  }

  .tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
  }

  /* Main: flex column, tab send chiếm toàn bộ */
  main {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    min-height: 0;
  }

  /* Ẩn tất cả panel theo tab */
  .panel {
    border-right: none;
    display: none;
    flex: 1;
    min-height: 0;
  }

  .panel.active { display: flex; }

  /* Tab "send": hiện peers phía trên + drop zone phía dưới */
  #panel-send {
    flex-direction: column;
    overflow: hidden;
  }

  /* Peers list dạng horizontal scroll trên mobile */
  .mobile-peers-bar {
    display: flex;
    flex-shrink: 0;
    overflow-x: auto;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    scrollbar-width: none;
  }

  .mobile-peers-bar::-webkit-scrollbar { display: none; }

  .mobile-peer-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 10px;
    border: 1px solid transparent;
    transition: background 0.15s, border-color 0.15s;
    min-width: 60px;
  }

  .mobile-peer-chip:hover { background: var(--border); }

  .mobile-peer-chip.selected {
    background: var(--sel-bg);
    border-color: var(--accent);
  }

  .mobile-peer-chip.self-chip { opacity: 0.5; cursor: default; }
  .mobile-peer-chip.self-chip:hover { background: transparent; }

  .chip-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--border2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mono);
    font-size: 15px;
    font-weight: 600;
    color: var(--accent);
    position: relative;
  }

  .chip-avatar.self-avatar { color: var(--muted); border: 1px dashed var(--border2); }

  .chip-name {
    font-size: 10px;
    font-weight: 600;
    color: var(--text);
    max-width: 64px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
  }

  .chip-you {
    font-family: var(--mono);
    font-size: 8px;
    color: var(--muted);
  }

  .mobile-peers-empty {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--muted);
    padding: 4px 0;
    align-self: center;
  }

  /* Ẩn peers panel riêng trên mobile */
  #panel-peers { display: none !important; }

  /* Drop zone trong tab send */
  .drop-panel {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    min-height: 0;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    border-right: none;
  }

  .drop-zone {
    flex: 1;
    padding: 24px 16px;
    min-height: 160px;
  }

  /* Transfer section mobile */
  .transfer-section { max-height: 180px; }

  .transfer-section .queue {
    grid-template-columns: 1fr;
    padding: 10px 14px;
  }
}

@media (max-width: 900px) and (min-width: 641px) {
  main { grid-template-columns: 200px 1fr; }
  .log-panel { display: none; }
}

.about-panel {
  grid-column: span 3;
}
.about-container {
  padding: 14px 16px 10px;
}
.about-container ul {
  list-style: none;
}