/* ===== FileDrop styles =====
   Tokens first (light default, dark via prefers-color-scheme), then base,
   then components. The app uses the system font stack on purpose: no
   third-party font requests, which the privacy page promises. */
:root {
  --bg: #EEF1F6;
  --bg-elevated: #FFFFFF;
  --bg-soft: #F6F8FB;
  --text: #111827;
  --text-muted: #5B6474;
  --border: #DCE1EA;
  --border-soft: #EAEEF4;
  --primary: #1F4FD8;
  --primary-dark: #183FB0;
  --primary-contrast: #FFFFFF;
  --primary-soft: #E6EDFF;
  --danger: #C81E1E;
  --danger-soft: #FDECEC;
  --success: #15803D;
  --success-soft: #E4F5EA;
  --warning: #A16207;
  --warning-soft: #FFF4D6;
  --qr-bg: #FFFFFF;
  --radius: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --shadow-hero: 0 8px 28px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
  --focus-ring: 0 0 0 3px rgba(31, 79, 216, 0.35);
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1116;
    --bg-elevated: #171B22;
    --bg-soft: #11151C;
    --text: #E8ECF3;
    --text-muted: #98A2B3;
    --border: #262C36;
    --border-soft: #1F252E;
    --primary: #6D8DFF;
    --primary-dark: #8AA4FF;
    --primary-contrast: #0B1020;
    --primary-soft: #1B2540;
    --danger: #FF7B7B;
    --danger-soft: #3A1A1A;
    --success: #4ADE80;
    --success-soft: #14301F;
    --warning: #F5C451;
    --warning-soft: #3A2E10;
    --shadow-hero: 0 8px 28px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.4);
    --focus-ring: 0 0 0 3px rgba(109, 141, 255, 0.45);
  }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
svg { display: block; }

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px 56px;
}

a { color: var(--primary); }
a.plain-link { color: inherit; text-decoration: none; }

h1, h2, h3 { line-height: 1.15; margin: 0 0 8px; letter-spacing: -0.01em; text-wrap: balance; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0 0 12px; color: var(--text-muted); }

.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* ---------- Layout building blocks ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0 14px; gap: 12px; min-height: 48px;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 1rem; letter-spacing: -0.01em; text-decoration: none; color: var(--text);
}
.brand img { width: 26px; height: 26px; }

.lede { font-size: 1rem; color: var(--text-muted); margin: 0 0 18px; max-width: 34ch; }

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.card h1 { font-size: 1.35rem; }
.card h2 { font-size: 1.15rem; font-weight: 600; margin-bottom: 12px; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.row-center { justify-content: center; }
.spacer { flex: 1 1 auto; }

.section { margin-top: 22px; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin: 0 2px 8px;
}
.section-label {
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-muted);
}
.section-count { font-family: var(--mono); color: var(--text); margin-left: 6px; font-weight: 600; letter-spacing: 0; }
.section-note { font-size: 0.82rem; color: var(--text-muted); text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 8px; }

.or-rule {
  display: flex; align-items: center; gap: 12px;
  color: var(--text-muted); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase;
  margin: 20px 0 12px;
}
.or-rule::before, .or-rule::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- Buttons & inputs ---------- */
button, .btn {
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius-md);
  min-height: 46px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 0.95rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  transition: transform .05s ease, opacity .15s ease, background .15s ease;
  text-decoration: none;
  white-space: nowrap;
}
button:active, .btn:active { transform: scale(0.98); }
button:disabled, .btn[aria-disabled=true] { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: var(--primary-contrast); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-secondary, .btn-outline { background: var(--bg-elevated); color: var(--text); }
.btn-danger { background: var(--bg-elevated); color: var(--danger); border-color: var(--border); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost, .btn-quiet { background: transparent; border-color: transparent; color: var(--primary); padding-left: 8px; padding-right: 8px; }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 0.85rem; border-radius: var(--radius-sm); }
.btn-icon {
  width: 36px; height: 36px; min-height: 0; padding: 0;
  border-radius: var(--radius-sm); color: var(--text);
}
.btn-icon svg { width: 16px; height: 16px; }
.btn-icon.muted { color: var(--text-muted); }
.btn-icon.muted:hover { color: var(--danger); border-color: var(--danger); }

input[type=text], input[type=email], input[type=password], input[type=search], select {
  font: inherit;
  font-size: 16px; /* keeps iOS from zooming the page on focus */
  min-height: 46px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  width: 100%;
}
label { font-size: 0.82rem; color: var(--text-muted); display: block; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.help-text { font-size: 0.82rem; color: var(--text-muted); margin-top: 4px; }
.error-text { font-size: 0.88rem; color: var(--danger); margin-top: 6px; }
.form-note { font-size: 0.85rem; color: var(--text-muted); margin-top: 10px; text-align: center; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1 1 auto; min-width: 0; }

/* ---------- Pills / badges ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.72rem; font-weight: 600; line-height: 1.2;
  padding: 3px 8px; border-radius: 999px;
  background: var(--border-soft); color: var(--text-muted);
  white-space: nowrap;
}
.pill-ok { background: var(--success-soft); color: var(--success); }
.pill-warn { background: var(--warning-soft); color: var(--warning); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-primary { background: var(--primary-soft); color: var(--primary); }
.pill-mono { font-family: var(--mono); letter-spacing: 0.04em; }
.badge {
  display: inline-block; font-size: 0.72rem; font-weight: 600;
  padding: 3px 8px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary);
}
.pill-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 5px; }

/* ---------- Code entry (six cells) ---------- */
.code-entry { max-width: 430px; margin: 0 auto; }
.code-cells {
  display: flex; gap: 6px; margin: 4px 0 10px;
}
.code-cells input {
  flex: 1 1 0; min-width: 0; width: auto;
  aspect-ratio: 0.82;
  min-height: 52px;
  padding: 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 1.45rem;
  font-weight: 700;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  caret-color: var(--primary);
}
.code-cells input:nth-child(3) { margin-right: 8px; }
.code-cells input:focus-visible { border-color: var(--primary); }

/* ---------- Share page header ---------- */
.share-header {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px;
  margin: 0 0 14px; min-height: 40px;
}
.share-header .back { justify-self: start; }
.share-header .right { justify-self: end; }
.title-edit {
  display: flex; align-items: center; gap: 6px; min-width: 0;
}
.title-edit input {
  min-height: 40px;
  border-color: transparent;
  background: transparent;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  padding: 4px 8px;
  text-align: center;
}
.title-edit input:hover { border-color: var(--border); }
.title-edit input:focus { border-color: var(--primary); background: var(--bg-elevated); }
.share-title { font-size: 1.1rem; font-weight: 700; text-align: center; margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Pairing hero ---------- */
.hero {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow-hero);
}
.pair-grid {
  display: grid; grid-template-columns: 118px minmax(0, 1fr); gap: 14px; align-items: center;
}
.qr-box {
  width: 118px; height: 118px;
  background: var(--qr-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 7px;
}
.qr-box img { width: 100%; height: 100%; }
.code-display {
  font-family: var(--mono);
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  line-height: 1;
  margin: 4px 0 6px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.code-display .code-accent { color: var(--primary); }
.hero-hint { font-size: 0.8rem; color: var(--text-muted); line-height: 1.4; }
.hero-hint b { color: var(--text); font-weight: 600; }
.hero-actions { display: flex; gap: 8px; margin-top: 14px; }
.hero-actions .btn { flex: 1 1 0; min-height: 40px; font-size: 0.9rem; }
.live-line {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.85rem; color: var(--text-muted);
  min-height: 20px;
}
.live-line b { color: var(--text); font-weight: 600; }
.hero .live-line { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border-soft); }
.dot {
  flex: none; width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted); opacity: .5;
}
.dot.ok { background: var(--success); opacity: 1; box-shadow: 0 0 0 3px var(--success-soft); }
.dot.pending { background: var(--warning); opacity: 1; }
.dot.error { background: var(--danger); opacity: 1; }
.nag {
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
  font-size: 0.8rem; color: var(--text-muted); margin: 10px 2px 0;
}
.nag a { font-weight: 600; text-decoration: none; white-space: nowrap; }

/* ---------- Lists ---------- */
.list {
  display: flex; flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.list:empty { display: none; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  border-top: 1px solid var(--border-soft);
  color: inherit;
}
.list-item:first-child { border-top: 0; }
a.list-item { text-decoration: none; }
a.list-item:hover { background: var(--bg-soft); }
.list-icon {
  flex: none;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono);
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.02em;
  border-radius: 9px;
  background: var(--primary-soft);
  color: var(--primary);
}
.list-icon.neutral { background: var(--border-soft); color: var(--text-muted); }
.list-main { flex: 1 1 auto; min-width: 0; }
.list-title {
  font-weight: 600; font-size: 0.95rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.list-title .pill { margin-left: 6px; vertical-align: middle; }
.list-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.list-actions { flex: none; display: flex; gap: 6px; align-items: center; }
.list-chevron { flex: none; width: 8px; height: 8px; border-right: 1.5px solid var(--text-muted); border-bottom: 1.5px solid var(--text-muted); transform: rotate(-45deg); margin-right: 4px; }
.list-item-wrap { display: block; border-top: 1px solid var(--border-soft); }
.list-item-wrap:first-child { border-top: 0; }
.list-item-wrap .list-item { border-top: 0; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 18px 12px;
  font-size: 0.9rem;
}
.upload-pct { flex: none; color: var(--text-muted); font-size: 0.82rem; }

.guest-details {
  padding: 8px 14px 12px 62px;
  font-size: 0.82rem;
  color: var(--text-muted);
  border-top: 1px dashed var(--border-soft);
}
.guest-details ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- Drop strip / upload ---------- */
.drop-strip {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  padding: 10px 10px 10px 14px;
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 0.85rem;
  background: var(--bg-elevated);
  transition: background .15s ease, border-color .15s ease;
}
.drop-strip span { min-width: 0; }
.drop-strip.drag-over, .page-drag .drop-strip {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--text);
}

.progress-track {
  height: 4px;
  border-radius: 2px;
  background: var(--border-soft);
  overflow: hidden;
  margin-top: 6px;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width .12s ease;
}
.progress-fill.error { background: var(--danger); }
.progress-fill.done { background: var(--success); }

/* ---------- Disclosures (Guests / Settings) ---------- */
details.disclosure {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-top: 8px;
}
details.disclosure > summary {
  list-style: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 14px;
  font-weight: 600; font-size: 0.95rem;
  min-height: 48px;
}
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary small {
  font-weight: 400; color: var(--text-muted); font-size: 0.8rem; margin-left: 8px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
details.disclosure > summary .summary-main { display: flex; align-items: baseline; min-width: 0; }
details.disclosure > summary .list-chevron { transform: rotate(45deg); transition: transform .15s ease; }
details.disclosure[open] > summary .list-chevron { transform: rotate(-135deg); }
details.disclosure[open] > summary { border-bottom: 1px solid var(--border-soft); }
.disclosure-body { padding: 4px 14px 14px; }
.disclosure-body .list { border-radius: var(--radius-md); }
.disclosure-body .row-between { margin: 8px 0; }

/* ---------- Settings ---------- */
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border-soft);
}
.setting-row:first-child { border-top: 0; }
.setting-row label { margin: 0; color: var(--text); font-size: 0.95rem; }
.setting-row .field { margin: 0; flex: 1 1 auto; }
.setting-row select { min-height: 40px; }
.switch { position: relative; flex: none; width: 40px; height: 24px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; }
.switch .track {
  position: absolute; inset: 0; border-radius: 12px; background: var(--border);
  transition: background .15s ease;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3);
  transition: transform .15s ease;
}
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: var(--focus-ring); }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--primary); }

.danger-zone { display: flex; gap: 8px; margin-top: 22px; }
.danger-zone .btn { flex: 1 1 0; min-height: 42px; font-size: 0.9rem; }
.danger-note { font-size: 0.8rem; color: var(--text-muted); margin: 8px 2px 0; }

/* ---------- Home steps ---------- */
.steps {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px;
  margin-top: 26px;
}
.steps div { font-size: 0.8rem; color: var(--text-muted); line-height: 1.35; }
.steps i { display: block; font: 700 0.7rem/1 var(--mono); color: var(--primary); font-style: normal; margin-bottom: 6px; }
.steps b { display: block; color: var(--text); font-weight: 600; font-size: 0.85rem; margin-bottom: 2px; }
@media (max-width: 360px) { .steps { grid-template-columns: 1fr; } }

/* ---------- Admin stat tiles ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stat {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.stat b { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat span { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }
.stat small { font-size: 0.78rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (min-width: 600px) { .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* ---------- Toasts ---------- */
#toasts {
  position: fixed;
  left: 0; right: 0; bottom: 16px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
  z-index: 1000;
  padding: 0 16px;
}
.toast {
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  box-shadow: var(--shadow-hero);
  max-width: 90vw;
  text-align: center;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--success); color: #fff; }

/* ---------- Banner (verification notice, download-once) ---------- */
.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--warning-soft);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: .88rem;
}
.banner b { font-weight: 600; }

/* ---------- Misc ---------- */
.center { text-align: center; }
.muted { color: var(--text-muted); }
.auth-links { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 14px 0; color: var(--text-muted); }

footer.page-footer {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  color: var(--text-muted);
  font-size: .78rem;
  padding: 28px 2px 8px;
}
footer.page-footer a { color: var(--text-muted); }

/* ---------- Share page grid ---------- */
.share-container { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; }
.share-container > .section:first-child { margin-top: 0; }
.sec-devices.hidden + .sec-guests { margin-top: 22px; }
.sec-pairing { order: 0; }
.sec-files { order: 1; }
.sec-devices { order: 2; }
.sec-guests { order: 3; }
.sec-settings { order: 4; }
.sec-danger { order: 5; }
.sec-settings.section { margin-top: 0; }
.sec-guests.section { margin-top: 22px; }

@media (min-width: 900px) {
  #app.wide { max-width: 1040px; }
  .share-container {
    grid-template-columns: 360px minmax(0, 1fr);
    grid-template-areas:
      "pairing files"
      "devices files"
      "guests files"
      "settings files"
      "danger files";
    column-gap: 24px;
    align-items: start;
  }
  .sec-pairing { grid-area: pairing; }
  .sec-files { grid-area: files; }
  .sec-devices { grid-area: devices; }
  .sec-guests { grid-area: guests; }
  .sec-settings { grid-area: settings; }
  .sec-danger { grid-area: danger; }
  .sec-files .section-head { margin-top: 0; }
  .sec-files.section { margin-top: 0; }
  .share-container .drop-strip {
    flex-direction: column; justify-content: center; text-align: center;
    padding: 24px 16px; gap: 8px;
  }
}

@media (max-width: 380px) {
  .code-display { font-size: 1.6rem; letter-spacing: 0.08em; }
  .pair-grid { grid-template-columns: 100px minmax(0, 1fr); }
  .qr-box { width: 100px; height: 100px; }
}

/* ---------- Direct transfer rows ---------- */
.transfer-row .list-main { display: flex; flex-direction: column; gap: 2px; }
.transfer-status { font-size: 0.82rem; color: var(--text-muted); }
.transfer-row .pill { align-self: flex-start; margin-top: 4px; }
.transfer-actions { display: flex; gap: 6px; flex: none; }
.received-list { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; font-size: 0.82rem; }
.received-list button { min-height: 28px; padding: 0 8px; font-size: 0.78rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
