:root {
  color-scheme: light dark;
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #f8f9fe;
  --border: #e6e8f2;
  --text: #1c2130;
  --text-soft: #6b7280;
  --primary: #5b5bf0;
  --primary-strong: #4a4ad9;
  --green: #16a34a;
  --green-bg: #e7f7ee;
  --blue: #2563eb;
  --blue-bg: #e9f0fe;
  --red: #dc2626;
  --toast-bg: #1f2430;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 24, 50, .06), 0 8px 24px rgba(20, 24, 50, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1017;
    --surface: #171a23;
    --surface-2: #1e2230;
    --border: #2a3040;
    --text: #e8eaf3;
    --text-soft: #9aa2b8;
    --primary: #8f8ff5;
    --primary-strong: #7c7cf0;
    --green: #34d399;
    --green-bg: rgba(52, 211, 153, .14);
    --blue: #60a5fa;
    --blue-bg: rgba(96, 165, 250, .14);
    --red: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 10px 28px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(91, 91, 240, .18), transparent 60%),
    radial-gradient(900px 400px at 10% 110%, rgba(37, 99, 235, .14), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 40px 36px;
  text-align: center;
}

.logo-img {
  display: block;
  object-fit: cover;
}
.logo-img.login {
  width: 76px;
  height: 76px;
  margin: 0 auto 16px;
  border-radius: 20px;
  box-shadow: 0 10px 24px rgba(91, 91, 240, .35);
}
.logo-img.small {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  box-shadow: 0 6px 14px rgba(91, 91, 240, .3);
}

.login-card h1 { margin: 0 0 8px; font-size: 30px; font-weight: 800; letter-spacing: -.5px; }
.tagline { color: var(--text-soft); font-size: 15px; line-height: 1.55; margin: 0 0 22px; }

.features {
  list-style: none;
  margin: 0 0 26px;
  padding: 0;
  text-align: left;
  font-size: 14px;
  color: var(--text-soft);
}
.features li {
  padding: 8px 0 8px 30px;
  position: relative;
  line-height: 1.4;
}
.features li::before {
  content: '✓';
  position: absolute;
  left: 4px;
  top: 8px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--green-bg);
  color: var(--green);
  font-size: 11px;
  font-weight: 700;
}

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 15px;
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(20, 24, 50, .05);
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn-google:hover { transform: translateY(-1px); box-shadow: var(--shadow); }

.legal { margin: 16px 0 0; font-size: 12px; color: var(--text-soft); line-height: 1.5; }

/* ---------- App shell ---------- */
.app-view { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -.3px; }

.me { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
  border: 2px solid var(--border);
}
.initials {
  display: inline-grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  color: var(--primary);
  background: var(--blue-bg);
  border: 2px solid var(--border);
  border-radius: 50%;
  width: 38px; height: 38px;
  flex: none;
}
.person .initials { width: 36px; height: 36px; font-size: 12.5px; }
.me-text { text-align: right; }
.me-name { font-weight: 600; font-size: 14px; }
.me-email { font-size: 12px; color: var(--text-soft); }

.menu-wrap { position: relative; }
.menu-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 3px;
  border-radius: 12px;
}
.menu-btn:hover { background: var(--surface-2); }
.menu-btn .avatar,
.menu-btn .initials { width: 38px; height: 38px; }
.chev { color: var(--text-soft); font-size: 11px; }
.user-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 230px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(10, 14, 40, .22);
  padding: 6px;
  z-index: 60;
}
.user-menu.hidden { display: none; }
.menu-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.menu-header .avatar,
.menu-header .initials { width: 38px; height: 38px; }
.menu-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-email { font-size: 12px; color: var(--text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: 11px 12px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item.logout { color: var(--red); }
.menu-item.logout:hover { background: rgba(220, 38, 38, .12); }

.history-topbar { justify-content: flex-start; gap: 14px; }
.btn-back {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 11px;
  cursor: pointer;
  font-size: 16px;
  flex: none;
}
.btn-back:hover { background: var(--surface-2); }
.logo-img.small { width: 28px; height: 28px; border-radius: 8px; }
.history-sub-line { font-size: 12px; color: var(--text-soft); }

.history-page {
  flex: 1;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 22px 16px 40px;
}
.history-page .tabs { max-width: 420px; }
.history-page .history-list { max-width: none; }

.btn-ghost {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-soft);
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  padding: 16px;
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  min-height: 200px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -.2px; }
.hint { font-size: 11px; font-weight: 500; color: var(--text-soft); }

.icon-btn {
  border: none;
  background: var(--surface-2);
  width: 30px; height: 30px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 15px;
  color: var(--text-soft);
}
.icon-btn:hover { background: var(--border); color: var(--text); }
.icon-btn.spin { animation: spin .6s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

.legend { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
}
.badge.same { background: var(--green-bg); color: var(--green); }
.badge.server { background: var(--blue-bg); color: var(--blue); }

.search {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  background: var(--surface-2);
  outline: none;
  margin-bottom: 10px;
}
.search:focus { border-color: var(--primary); background: var(--surface); }

.people-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.people-list .person {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.people-list .person:hover { background: var(--surface-2); }
.people-list .person.selected { background: var(--blue-bg); border-color: rgba(37, 99, 235, .25); }
.person .avatar { width: 36px; height: 36px; flex: none; }
.person-info { min-width: 0; flex: 1; }
.person-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-sub { font-size: 11.5px; color: var(--text-soft); }

.empty {
  text-align: center;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.6;
  padding: 30px 10px;
}

/* ---------- Share panel ---------- */
.selected-peer {
  font-size: 13px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  max-width: 60%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.selected-peer.empty { color: var(--text-soft); font-weight: 500; background: transparent; padding: 0; }
.selected-peer.same { background: var(--green-bg); color: var(--green); }
.selected-peer.server { background: var(--blue-bg); color: var(--blue); }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 34px 20px;
  text-align: center;
  transition: border-color .15s ease, background .15s ease;
  margin-bottom: 14px;
}
.dropzone.drag { border-color: var(--primary); background: var(--blue-bg); }
.dz-icon {
  width: 46px; height: 46px;
  margin: 0 auto 10px;
  display: grid; place-items: center;
  border-radius: 14px;
  background: var(--blue-bg);
  color: var(--blue);
  font-size: 22px;
  font-weight: 700;
}
.dropzone p { margin: 0 0 4px; font-size: 14px; }
.dropzone p:first-of-type { font-weight: 600; }
.dz-sub { color: var(--text-soft); font-size: 12.5px; }
.link { color: var(--primary); cursor: pointer; font-weight: 600; }

.file-picker { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 14px; }
.picked-files { list-style: none; margin: 0 0 12px; padding: 0; max-height: 160px; overflow: auto; }
.picked-files li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  font-size: 13px;
  border-bottom: 1px dashed var(--border);
}
.picked-files li:last-child { border-bottom: none; }
.picked-files .fname { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.picked-files .fsize { color: var(--text-soft); font-size: 12px; flex: none; }
.picked-files .x { border: none; background: none; color: var(--text-soft); cursor: pointer; font-size: 15px; flex: none; }
.picked-files .x:hover { color: var(--red); }

.btn-primary {
  border: none;
  background: linear-gradient(135deg, #6d6df5, #4a4ad9);
  color: #fff;
  padding: 11px 22px;
  border-radius: 11px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(91, 91, 240, .3);
  transition: transform .12s ease, opacity .12s ease;
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

.transfers, .incoming { display: flex; flex-direction: column; gap: 10px; }

.t-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface);
}
.t-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; }
.t-head .who { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-head .stat { font-size: 12px; font-weight: 600; color: var(--text-soft); }
.t-head .stat.ok { color: var(--green); }
.t-head .stat.err { color: var(--red); }

.pbar {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.pbar > div {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #6d6df5, #4a4ad9);
  border-radius: 999px;
  transition: width .1s linear;
}
.t-meta { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-soft); margin-top: 6px; }

.incoming .t-card { background: var(--surface-2); }
.incoming .files { margin: 8px 0; list-style: none; padding: 0; }
.incoming .files li { display: flex; align-items: center; gap: 8px; font-size: 12.5px; padding: 4px 0; }
.incoming .files .fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.incoming .btn-dl {
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
  flex: none;
}

/* ---------- History ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 7px;
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-soft);
  cursor: pointer;
}
.tab.active { background: var(--text); color: var(--surface); border-color: var(--text); }

.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.h-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.h-icon {
  width: 34px; height: 34px;
  flex: none;
  display: grid; place-items: center;
  border-radius: 10px;
  font-size: 14px;
}
.h-item.sent .h-icon { background: var(--blue-bg); color: var(--blue); }
.h-item.received .h-icon { background: var(--green-bg); color: var(--green); }
.h-info { flex: 1; min-width: 0; }
.h-fname { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-sub { font-size: 11.5px; color: var(--text-soft); }
.h-date { font-size: 11px; color: var(--text-soft); flex: none; text-align: right; }
.h-dl {
  border: none;
  background: var(--surface-2);
  color: var(--text);
  width: 28px; height: 28px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  flex: none;
}
.h-dl:hover { background: var(--primary); color: #fff; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
}
.toast {
  background: var(--toast-bg);
  color: #fff;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  animation: slideIn .2s ease;
  line-height: 1.45;
}
.toast b { color: #c7c7ff; }
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
@keyframes slideIn { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 1150px) {
  .layout { grid-template-columns: 260px 1fr; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .me-text { display: none; }
}