/* ==========================================================================
   bigshare - dashboard + public page
   Vanilla CSS. No framework, no CDN, no build step.
   ========================================================================== */

:root {
  --bg:            #f6f7f9;
  --surface:       #ffffff;
  --surface-2:     #f1f3f5;
  --surface-3:     #e6e9ed;
  --border:        #dfe3e8;
  --border-strong: #c6ccd4;
  --text:          #14181d;
  --text-2:        #4a5361;
  --text-3:        #77818f;
  --accent:        #1a6ef5;
  --accent-dark:   #1457c4;
  --accent-soft:   #e8f0fe;
  --green:         #0f8a4f;
  --green-soft:    #e6f5ec;
  --amber:         #a86400;
  --amber-soft:    #fdf3e0;
  --red:           #c0392b;
  --red-soft:      #fdecea;
  --purple:        #6b3fc4;
  --radius:        12px;
  --radius-sm:     8px;
  --shadow:        0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --shadow-lg:     0 10px 30px rgba(16, 24, 40, .12), 0 2px 8px rgba(16, 24, 40, .06);
  --header-h:      62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #0e1116;
    --surface:       #161b22;
    --surface-2:     #1d232c;
    --surface-3:     #262d38;
    --border:        #2a323d;
    --border-strong: #3a4450;
    --text:          #e8edf4;
    --text-2:        #a9b4c2;
    --text-3:        #7b8695;
    --accent:        #4b8dff;
    --accent-dark:   #6ba1ff;
    --accent-soft:   #16243d;
    --green:         #46c07d;
    --green-soft:    #12291d;
    --amber:         #e0a63a;
    --amber-soft:    #2b2213;
    --red:           #f0736a;
    --red-soft:      #2d1614;
    --purple:        #a084f5;
    --shadow:        0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg:     0 12px 34px rgba(0, 0, 0, .55);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* Touch: no grey flash over rows/buttons; the controls carry their own
     :active state. Keeps Apple's double-tap zoom from swallowing fast taps. */
  -webkit-tap-highlight-color: transparent;
}

/* iOS Safari force-zooms the viewport when focusing any form control whose
   font is under 16px. Full-size controls keep finger taps comfortable too. */
button, a, input, select, textarea, [role="button"] {
  touch-action: manipulation;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.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;
}

/* ---------------------------------------------------------------- header */

.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-h);
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -.01em; font-size: 17px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  color: #fff; flex: none;
}
.brand-mark svg { width: 17px; height: 17px; }

.topbar-spacer { flex: 1 1 auto; }

.search-wrap { position: relative; flex: 0 1 420px; }
.search-wrap svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--text-3); pointer-events: none;
}
#search {
  width: 100%; height: 38px;
  padding: 0 12px 0 34px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 10px;
}
#search:focus { background: var(--surface); border-color: var(--accent); outline: none; }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 15px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-weight: 550; font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex: none; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }

.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }

.btn-danger { color: var(--red); border-color: var(--border); }
.btn-danger:hover:not(:disabled) { background: var(--red-soft); border-color: var(--red); }

.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: 9px; }
.btn-sm { height: 31px; padding: 0 11px; font-size: 13px; border-radius: 8px; }
.btn-sm svg { width: 14px; height: 14px; }

/* ---------------------------------------------------------------- layout */

.page { max-width: 1180px; margin: 0 auto; padding: 22px 20px 90px; padding-bottom: calc(90px + env(safe-area-inset-bottom)); }

.provider-strip {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 13px 15px; margin-bottom: 18px;
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius); background: var(--surface);
}
.provider-strip.is-dev  { border-left-color: var(--amber); }
.provider-strip.is-full { border-left-color: var(--red); }
.provider-strip .ps-body { flex: 1 1 auto; min-width: 0; }
.provider-strip .ps-title { font-weight: 650; margin: 0 0 2px; font-size: 14px; }
.provider-strip .ps-head { font-weight: 600; color: var(--accent); font-size: 13px; }
.provider-strip.is-dev .ps-head { color: var(--amber); }
.provider-strip .ps-text { margin: 4px 0 0; font-size: 13px; color: var(--text-2); }
.provider-strip .ps-limits {
  margin: 8px 0 0; padding: 0; list-style: none;
  display: flex; flex-wrap: wrap; gap: 6px;
}
.provider-strip .ps-limits li {
  font-size: 11.5px; font-weight: 600; padding: 3px 9px;
  border-radius: 999px; background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border);
}
.provider-strip .ps-close {
  background: none; border: 0; cursor: pointer; color: var(--text-3);
  padding: 4px; border-radius: 6px; flex: none;
}
.provider-strip .ps-close:hover { background: var(--surface-2); color: var(--text); }

/* ---------------------------------------------------------------- dropzone */

.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: 16px;
  background: var(--surface);
  padding: 34px 22px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.is-over {
  border-color: var(--accent); background: var(--accent-soft);
  box-shadow: inset 0 0 0 3px var(--accent-soft);
}
.dropzone-icon {
  width: 54px; height: 54px; margin: 0 auto 12px;
  border-radius: 15px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.dropzone-icon svg { width: 27px; height: 27px; }
.dropzone h2 { margin: 0 0 5px; font-size: 17px; letter-spacing: -.01em; }
.dropzone p { margin: 0; color: var(--text-2); font-size: 13.5px; }
.dropzone .dz-max { margin-top: 9px; font-size: 12.5px; color: var(--text-3); }

/* ---------------------------------------------------------------- upload queue */

.queue { margin-top: 18px; display: flex; flex-direction: column; gap: 9px; }

.q-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 12px;
  align-items: center;
}
.q-item.is-error { border-color: var(--red); background: var(--red-soft); }
.q-item.is-done { border-color: var(--green); }

.q-icon {
  width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center; background: var(--surface-2);
  color: var(--text-2);
}
.q-icon svg { width: 19px; height: 19px; }

.q-main { min-width: 0; }
.q-name {
  font-weight: 600; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.q-meta {
  font-size: 12.5px; color: var(--text-2); margin-top: 2px;
  display: flex; flex-wrap: wrap; gap: 4px 10px;
  font-variant-numeric: tabular-nums;
}
.q-meta .sep { color: var(--border-strong); }
.q-error { color: var(--red); font-size: 12.5px; margin-top: 4px; }

.q-actions { display: flex; gap: 5px; align-items: center; }

.bar {
  height: 6px; border-radius: 99px; background: var(--surface-3);
  overflow: hidden; margin-top: 7px;
}
.bar > i {
  display: block; height: 100%; width: 0%;
  background: var(--accent); border-radius: 99px;
  transition: width .25s ease;
}
.q-item.is-done .bar > i { background: var(--green); }
.q-item.is-error .bar > i { background: var(--red); }
.q-item.is-paused .bar > i { background: var(--text-3); }

/* ---------------------------------------------------------------- toolbar */

.toolbar {
  display: flex; align-items: center; gap: 10px;
  margin: 26px 0 12px; flex-wrap: wrap;
}
.toolbar h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.toolbar .count { color: var(--text-3); font-weight: 500; font-size: 14px; }
.toolbar-spacer { flex: 1 1 auto; }

.sortbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sortbar label { font-size: 13px; color: var(--text-2); }
select.control {
  height: 34px; padding: 0 9px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; cursor: pointer;
}

/* ---------------------------------------------------------------- file list */

.files { display: flex; flex-direction: column; gap: 7px; }

.file-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.file-row:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }

.f-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center;
  font-size: 10px; font-weight: 700; letter-spacing: .02em;
  color: #fff; text-transform: uppercase;
}
.f-icon svg { width: 20px; height: 20px; }

.f-main { min-width: 0; }
.f-name {
  font-weight: 600; font-size: 14px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.f-sub {
  display: flex; flex-wrap: wrap; gap: 3px 9px;
  font-size: 12.5px; color: var(--text-2); margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.f-sub .sep { color: var(--border-strong); }
.f-sub .pill {
  font-size: 11px; font-weight: 650; padding: 1px 7px; border-radius: 99px;
}
.f-sub .pill.shared  { background: var(--green-soft); color: var(--green); }
.f-sub .pill.private { background: var(--surface-2); color: var(--text-3); }

.f-actions { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

/* ---------------------------------------------------------------- share box */

.share-box { display: flex; align-items: center; gap: 7px; min-width: 0; flex: 1 1 auto; }
.share-box input {
  flex: 1 1 auto; min-width: 0; height: 32px;
  padding: 0 10px; font-size: 12.5px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------------------------------------------------------------- empty / loading */

.empty {
  text-align: center; padding: 48px 20px; color: var(--text-3);
  border: 1px dashed var(--border); border-radius: var(--radius);
  background: var(--surface);
}
.empty svg { width: 40px; height: 40px; opacity: .5; margin-bottom: 8px; }
.empty p { margin: 0 0 4px; font-size: 14px; color: var(--text-2); }
.empty .small { font-size: 12.5px; }

/* ---------------------------------------------------------------- modal */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(12, 16, 22, .55);
  display: grid; place-items: center; padding: 20px;
  animation: fade .14s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.modal {
  background: var(--surface); border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px;
  max-height: 86vh; overflow: auto;
  animation: pop .16s ease;
}
@keyframes pop { from { transform: translateY(8px) scale(.99); opacity: 0 } to { transform: none; opacity: 1 } }

.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 16px; flex: 1 1 auto; }
.modal-body { padding: 18px; }
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 14px 18px; border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 16px 16px;
}

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 650; color: var(--text-2); margin-bottom: 5px; }
.field input[type=text] {
  width: 100%; height: 38px; padding: 0 11px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
}
.field input[type=text]:focus { border-color: var(--accent); outline: none; }

.kv { display: grid; grid-template-columns: 128px 1fr; gap: 7px 14px; font-size: 13.5px; }
.kv dt { color: var(--text-2); font-weight: 600; }
.kv dd { margin: 0; word-break: break-word; }
.kv dd.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* ---------------------------------------------------------------- toast */

.toasts {
  position: fixed; z-index: 200;
  right: 16px; bottom: 16px;                       /* fallback: no env() support */
  right: max(16px, env(safe-area-inset-right));    /* iPhone notch / home bar */
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
  max-width: min(400px, calc(100vw - 32px));
}
.toast {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px; box-shadow: var(--shadow-lg);
  padding: 11px 13px; font-size: 13.5px;
  animation: slide .18s ease;
}
@keyframes slide { from { transform: translateX(14px); opacity: 0 } to { transform: none; opacity: 1 } }
.toast.is-error { border-left-color: var(--red); }
.toast.is-ok    { border-left-color: var(--green); }
.toast.is-warn  { border-left-color: var(--amber); }
.toast svg { width: 17px; height: 17px; flex: none; margin-top: 1px; }
.toast-body { flex: 1 1 auto; min-width: 0; }
.toast-body b { display: block; font-weight: 650; margin-bottom: 1px; }
.toast-body span { color: var(--text-2); word-break: break-word; }
.toast-x { background: none; border: 0; cursor: pointer; color: var(--text-3); padding: 0 2px; }

/* ---------------------------------------------------------------- auth gate */

.gate {
  max-width: 430px; margin: 60px auto; text-align: center;
}
.gate-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px 24px; box-shadow: var(--shadow);
}
.gate-card .brand { justify-content: center; margin-bottom: 6px; font-size: 19px; }
.gate-card p.lede { color: var(--text-2); font-size: 13.5px; margin: 0 0 20px; }
.gate-card .field { text-align: left; }

/* ---------------------------------------------------------------- public page */

.public-wrap {
  max-width: 780px; margin: 0 auto; padding: 28px 20px 60px;
  padding-bottom: calc(60px + env(safe-area-inset-bottom));
}

.public-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.public-head {
  display: flex; gap: 15px; align-items: flex-start;
  padding: 22px;
  border-bottom: 1px solid var(--border);
}
.public-head .f-icon { width: 52px; height: 52px; border-radius: 13px; font-size: 12px; flex: none; }
.public-title { flex: 1 1 auto; min-width: 0; }
.public-title h1 {
  margin: 0 0 4px; font-size: 19px; line-height: 1.3;
  word-break: break-word; letter-spacing: -.01em;
}
.public-facts {
  display: flex; flex-wrap: wrap; gap: 4px 10px;
  font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums;
}
.public-facts .sep { color: var(--border-strong); }

.public-actions {
  display: flex; gap: 9px; padding: 16px 22px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.public-actions .btn { height: 42px; padding: 0 20px; font-size: 15px; }
.public-actions .btn-primary { flex: 1 1 240px; }

.preview-area { padding: 0; background: var(--surface-2); }
.preview-area iframe, .preview-area embed {
  display: block; width: 100%; height: min(72vh, 760px); border: 0; background: #fff;
}
.preview-area img {
  display: block; max-width: 100%; height: auto; margin: 0 auto;
  max-height: 78vh; object-fit: contain;
}
.preview-cap {
  padding: 8px 22px; font-size: 12px; color: var(--text-3);
  border-top: 1px solid var(--border); background: var(--surface);
}

.no-preview {
  padding: 26px 22px; text-align: center; color: var(--text-2);
}
.no-preview .np-icon {
  width: 46px; height: 46px; margin: 0 auto 10px; border-radius: 13px;
  display: grid; place-items: center; background: var(--surface-2); color: var(--text-3);
}
.no-preview .np-icon svg { width: 23px; height: 23px; }
.no-preview p { margin: 0 auto 4px; max-width: 460px; font-size: 13.5px; }
.no-preview .small { font-size: 12.5px; color: var(--text-3); }

.public-foot {
  margin-top: 18px; text-align: center;
  font-size: 12.5px; color: var(--text-3);
}
.public-foot a { color: var(--text-2); }

.notice {
  padding: 14px 16px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  text-align: center; color: var(--text-2);
}
.notice.is-error { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.notice h2 { margin: 0 0 6px; font-size: 16px; color: var(--text); }
.notice p { margin: 0 0 12px; font-size: 13.5px; }

/* ---------------------------------------------------------------- creator footer */

.site-footer {
  margin-top: 46px;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.footer-inner {
  max-width: 1180px; margin: 0 auto;
}
.footer-inner-narrow { max-width: 780px; }

.creator-card {
  display: flex; gap: 14px; align-items: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.creator-avatar {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  color: #fff; font-weight: 700; font-size: 15px; letter-spacing: .02em;
}
.creator-card h2 { margin: 0 0 4px; font-size: 14.5px; letter-spacing: -.01em; }
.creator-card p { margin: 0; font-size: 13px; color: var(--text-2); }

.footer-credit {
  margin: 16px 0 0; text-align: center;
  font-size: 12.5px; color: var(--text-3);
}

/* ---------------------------------------------------------------- responsive */

@media (max-width: 820px) {
  .topbar { padding: 0 12px; gap: 9px; }
  .brand span { display: none; }
  .search-wrap { flex: 1 1 auto; }
  .search-wrap svg { left: 10px; }
  #search { height: 40px; }
  .page { padding: 16px 13px 80px; padding-bottom: calc(80px + env(safe-area-inset-bottom)); }

  .file-row { grid-template-columns: 38px 1fr; grid-template-areas: "icon main" "actions actions"; }
  .file-row .f-icon { grid-area: icon; width: 38px; height: 38px; }
  .file-row .f-main { grid-area: main; }
  .file-row .f-actions { grid-area: actions; justify-content: flex-start; margin-top: 9px; flex-wrap: wrap; }

  /* the share link gets a full row - on phones it was squeezed between
   * buttons; now the URL is scrollable/selected comfortably, then the buttons */
  .file-row .share-box { flex: 1 1 100%; }

  .q-item { grid-template-columns: 34px 1fr; }
  .q-item .q-actions { grid-column: 1 / -1; justify-content: flex-end; }

  .modal-foot { flex-wrap: wrap; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; }

  .site-footer { margin-top: 34px; padding: 18px 13px calc(18px + env(safe-area-inset-bottom)); }

  /* ----- touch targets: Apple HIG wants ~44px; every control gets bigger ----- */
  .btn { height: 42px; }
  .btn-sm { height: 38px; padding: 0 13px; }
  .btn-icon { width: 42px; height: 42px; }
  .btn-sm.btn-icon { width: 38px; height: 38px; }
  .f-actions { gap: 7px; }
  .q-actions { gap: 7px; }
  .modal-foot .btn { height: 44px; flex: 1 1 auto; }
  .ps-close { padding: 10px; }
  .toast-x { padding: 6px; }

  /* iOS auto-zoom workaround: every form control must be >= 16px on focus,
     or the whole iPhone viewport scales on every tap (search, gate token,
     rename modal, share-link input). */
  #search,
  .field input,
  .share-box input,
  select.control,
  #gateToken {
    font-size: 16px;
  }
  .search-wrap svg { width: 17px; height: 17px; }
}

@media (max-width: 520px) {
  .topbar .btn-primary span { display: none; }
  .topbar .btn-primary { width: 44px; padding: 0; }
  .public-actions { padding: 14px 16px; gap: 8px; }
  .public-actions .btn { flex: 1 1 100%; height: 46px; font-size: 15.5px; }
  .public-head { padding: 18px; }
  .public-head .f-icon { width: 46px; height: 46px; border-radius: 12px; }
  .public-title h1 { font-size: 17.5px; }
  .preview-cap, .public-foot { padding-left: 16px; padding-right: 16px; }
  .provider-strip { flex-wrap: wrap; }
  .gate { margin: 36px auto; padding: 0 14px; }
  .gate-card { padding: 24px 18px; }
  .creator-card { padding: 13px 14px; gap: 11px; }
  .creator-avatar { width: 38px; height: 38px; font-size: 13px; }
  .creator-card p { font-size: 12.5px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
