/* Hermes Uploader — mobile-first, terminal aesthetic */

@font-face {
  font-family: 'JetBrains Mono';
  src: url('/static/fonts/JetBrainsMono-Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/static/fonts/JetBrainsMono-Medium.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/static/fonts/JetBrainsMono-Bold.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #0b0d10;
  --bg-1: #11151a;
  --bg-2: #171c23;
  --bg-3: #1f262f;
  --line: #262e39;
  --line-2: #333d4a;
  --fg: #e4e8ee;
  --fg-dim: #8b97a8;
  --fg-faint: #5c6878;
  --acc: #5eead4;
  --acc-dim: #2dd4bf;
  --acc-glow: rgba(94, 234, 212, 0.14);
  --warn: #fbbf24;
  --err: #f87171;
  --r: 10px;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.55;
  overscroll-behavior-y: none;
}

body { -webkit-font-smoothing: antialiased; }

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button { cursor: pointer; border: 0; background: none; }

::selection { background: var(--acc-glow); }

/* scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }

/* ── Login ───────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px calc(24px + var(--safe-b));
}

.login-card { width: 100%; max-width: 360px; }

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.4px;
}
.brand .caret {
  color: var(--acc);
  animation: blink 1.1s steps(2, start) infinite;
}
@keyframes blink { to { opacity: 0; } }

.login-sub {
  color: var(--fg-faint);
  font-size: 12px;
  margin: 0 0 28px;
}

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--fg-faint);
  margin-bottom: 7px;
}

.input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--r);
  outline: none;
  /* ≥16px so iOS Safari doesn't auto-zoom on focus */
  font-size: 16px;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus {
  border-color: var(--acc-dim);
  box-shadow: 0 0 0 3px var(--acc-glow);
}
.input::placeholder { color: var(--fg-faint); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: var(--r);
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--fg);
  font-weight: 500;
  transition: background .15s, border-color .15s, transform .08s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-primary {
  background: var(--acc);
  border-color: var(--acc);
  color: #05201c;
  font-weight: 700;
}
.btn-primary:active { background: var(--acc-dim); }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--err); border-color: rgba(248,113,113,.3); }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: 12px; }

.msg {
  margin-top: 14px;
  font-size: 12px;
  min-height: 18px;
  color: var(--err);
}
.msg.ok { color: var(--acc); }

.login-note {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--fg-faint);
  font-size: 11px;
  line-height: 1.7;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: rgba(11, 13, 16, .88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { font-size: 15px; margin: 0; flex: 1; min-width: 0; }
.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-right: -6px;   /* visual size stays compact, hit area is 44px */
  border-radius: 11px;
  color: var(--fg-dim);
  border: 1px solid transparent;
}
.icon-btn:active { background: var(--bg-2); }

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 14px 0;
  position: sticky;
  top: calc(59px + var(--safe-t));
  z-index: 19;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.tab {
  flex: 1;
  min-height: 42px;
  padding: 0 10px;
  color: var(--fg-faint);
  font-size: 12px;
  letter-spacing: .5px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.on { color: var(--acc); border-bottom-color: var(--acc); font-weight: 700; }

main {
  flex: 1;
  padding: 16px 14px calc(120px + var(--safe-b));
}

.view { display: none; }
.view.on { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.sec-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--fg-faint);
  margin: 0 0 12px;
}
.sec-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--fg-faint);
  font-size: 12px;
  line-height: 1.8;
  border: 1px dashed var(--line);
  border-radius: var(--r);
}

/* ── Drop zone ───────────────────────────────────────────── */
.drop {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 30px 18px;
  margin-bottom: 16px;
  border: 1.5px dashed var(--line-2);
  border-radius: 14px;
  background: var(--bg-1);
  text-align: center;
  transition: border-color .15s, background .15s;
}
.drop.hot { border-color: var(--acc); background: var(--acc-glow); }
.drop .big { font-size: 26px; color: var(--acc); line-height: 1; }
.drop .t { font-weight: 500; }
.drop .s { font-size: 11px; color: var(--fg-faint); }
.drop input[type=file] { display: none; }

.dest {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  margin-bottom: 12px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--r);
  font-size: 12px;
}
.dest .lbl { color: var(--fg-faint); flex-shrink: 0; }
.dest .val {
  flex: 1;
  min-width: 0;
  color: var(--acc);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Folder list ─────────────────────────────────────────── */
.folders { display: flex; flex-direction: column; gap: 8px; }

.folder {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 60px;
  padding: 11px 13px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--r);
  text-align: left;
  transition: border-color .15s, background .15s;
}
.folder:active { background: var(--bg-2); }
.folder.on { border-color: var(--acc); background: var(--acc-glow); }
.folder .ic { font-size: 18px; color: var(--fg-dim); flex-shrink: 0; }
.folder.on .ic { color: var(--acc); }
.folder .body { flex: 1; min-width: 0; }
.folder .nm {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folder .mt { font-size: 11px; color: var(--fg-faint); margin-top: 1px; }
.folder .go { color: var(--fg-faint); flex-shrink: 0; }

/* rows built by JS: tappable label + separate ⋯ button */
.row-open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 4px 0;
  text-align: left;
}
.row-open .nm {
  max-width: 100%;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-open .mt { font-size: 11px; color: var(--fg-faint); }
.row-more {
  flex-shrink: 0;
  width: 44px;
  min-height: 44px;
  margin-right: -6px;   /* visual compactness without shrinking the tap target */
  border-radius: 8px;
  color: var(--fg-dim);
  font-size: 16px;
}
.row-more:active { background: var(--bg-3); }

/* ── Library scope chips (active folder filter) ──────────── */
.scopes {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.scope-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 22px;
  background: var(--acc-glow);
  border: 1px solid var(--acc-dim);
  color: var(--acc);
  font-size: 12px;
  font-weight: 500;
  max-width: 100%;
}
.scope-chip .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scope-chip .x { font-weight: 700; }

/* ── Queue (files staged before upload) ──────────────────── */
.queue { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.qrow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
}
.qrow .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qrow .sz { color: var(--fg-faint); flex-shrink: 0; font-size: 11px; }
.qrow .x {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  margin-right: -8px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--fg-faint);
  font-size: 14px;
}
.qrow .x:active { background: var(--bg-3); }
.qrow.done { border-color: rgba(94,234,212,.35); }
.qrow.fail { border-color: rgba(248,113,113,.4); }
.qrow.fail .sz { color: var(--err); }

.bar {
  height: 3px;
  background: var(--bg-3);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 14px;
}
.bar > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--acc);
  transition: width .2s;
}

/* ── Library grid ────────────────────────────────────────── */
.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.toolbar .input { height: 42px; }

.chips { display: flex; gap: 6px; margin-bottom: 14px; overflow-x: auto; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  min-height: 44px;
  padding: 0 15px;
  border-radius: 22px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  color: var(--fg-dim);
  font-size: 12px;
}
.chip.on { background: var(--acc-glow); border-color: var(--acc-dim); color: var(--acc); font-weight: 500; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-2);
  border: 1px solid var(--line);
  padding: 0;
}
.cell.on { border-color: var(--acc); box-shadow: 0 0 0 2px var(--acc-glow); }
.cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cell .ext {
  display: grid;
  place-items: center;
  height: 100%;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .5px;
  color: var(--fg-dim);
}
.cell .cap {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 14px 6px 5px;
  background: linear-gradient(transparent, rgba(0,0,0,.85));
  font-size: 9.5px;
  color: #fff;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cell .tick {
  position: absolute;
  top: 5px; right: 5px;
  width: 20px; height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  background: rgba(0,0,0,.55);
  border: 1px solid rgba(255,255,255,.28);
  color: transparent;
}
.cell.on .tick { background: var(--acc); border-color: var(--acc); color: #05201c; font-weight: 700; }

/* ── Action bar (thumb reach) ─────────────────────────────── */
.actionbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 12px 14px calc(12px + var(--safe-b));
  background: rgba(11, 13, 16, .93);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  transform: translateY(120%);
  transition: transform .22s cubic-bezier(.2,.9,.3,1);
}
.actionbar.on { transform: none; }
.actionbar .count {
  font-size: 12px;
  color: var(--fg-dim);
  flex-shrink: 0;
  white-space: nowrap;
}
.actionbar .btn { flex: 1; }

/* ── Sheet / modal ───────────────────────────────────────── */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0,0,0,.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.scrim.on { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 41;
  max-height: 86vh;
  overflow-y: auto;
  padding: 8px 16px calc(20px + var(--safe-b));
  background: var(--bg-1);
  border-top: 1px solid var(--line-2);
  border-radius: 18px 18px 0 0;
  transform: translateY(100%);
  /* hidden from the accessibility tree + keyboard focus when closed */
  visibility: hidden;
  transition: transform .26s cubic-bezier(.2,.9,.3,1), visibility 0s .26s;
}
.sheet.on {
  transform: none;
  visibility: visible;
  transition: transform .26s cubic-bezier(.2,.9,.3,1);
}
.sheet .grab {
  width: 38px; height: 4px;
  margin: 6px auto 14px;
  border-radius: 2px;
  background: var(--line-2);
}
.sheet h3 { margin: 0 0 4px; font-size: 15px; }
.sheet .hint { margin: 0 0 16px; font-size: 11.5px; color: var(--fg-faint); line-height: 1.7; }

.refbox {
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 11.5px;
  color: var(--acc);
  word-break: break-all;
  white-space: pre-wrap;
  line-height: 1.7;
  max-height: 34vh;
  overflow-y: auto;
}

.sheet-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.sheet-actions .btn { width: 100%; }
@media (min-width: 480px) {
  .sheet-actions { flex-direction: row; }
  .sheet-actions .btn { flex: 1; width: auto; }
}

/* ── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-b));
  z-index: 60;
  transform: translate(-50%, 14px);
  max-width: calc(100vw - 32px);
  padding: 11px 16px;
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  border-radius: 22px;
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: rgba(248,113,113,.5); color: #fecaca; }

/* ── Tablet / desktop ────────────────────────────────────── */
@media (min-width: 720px) {
  main { max-width: 780px; margin: 0 auto; padding-bottom: 120px; }
  .topbar, .tabs { padding-left: 20px; padding-right: 20px; }
  .tabs { max-width: 780px; margin: 0 auto; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); }
  .actionbar { justify-content: center; }
  .actionbar .btn { flex: 0 0 auto; min-width: 160px; }
  .sheet { left: 50%; right: auto; transform: translate(-50%, 100%); width: 560px; border-radius: 18px 18px 0 0; }
  .sheet.on { transform: translate(-50%, 0); }
}





