/* ---------- Tokens ---------- */

:root {
  --bg: #f4f5fb;
  --glow-1: rgba(109, 74, 255, 0.20);
  --glow-2: rgba(0, 184, 217, 0.16);
  --grid: rgba(20, 22, 40, 0.045);
  --surface: rgba(255, 255, 255, 0.78);
  --surface-solid: #ffffff;
  --surface-hover: rgba(109, 74, 255, 0.05);
  --border: rgba(20, 22, 40, 0.08);
  --border-strong: rgba(20, 22, 40, 0.16);
  --text: #12142a;
  --muted: #5b6080;
  --faint: #8b90aa;
  --accent: #6d4aff;
  --accent-2: #00b4d8;
  --accent-soft: rgba(109, 74, 255, 0.12);
  --on-accent: #ffffff;
  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, 0.12);
  --success: #23a26d;
  --shadow-sm: 0 1px 2px rgba(20, 22, 40, 0.05);
  --shadow: 0 1px 2px rgba(20, 22, 40, 0.04), 0 12px 32px -8px rgba(20, 22, 40, 0.12);
  --shadow-lg: 0 24px 64px -12px rgba(20, 22, 40, 0.28);
  --radius: 18px;
  --radius-sm: 11px;
  --font: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #08090f;
    --glow-1: rgba(124, 92, 255, 0.26);
    --glow-2: rgba(34, 211, 238, 0.14);
    --grid: rgba(255, 255, 255, 0.035);
    --surface: rgba(20, 22, 36, 0.72);
    --surface-solid: #141625;
    --surface-hover: rgba(139, 114, 255, 0.08);
    --border: rgba(255, 255, 255, 0.07);
    --border-strong: rgba(255, 255, 255, 0.14);
    --text: #eceef9;
    --muted: #9ba1c0;
    --faint: #686d8e;
    --accent: #8f78ff;
    --accent-2: #2dd4f0;
    --accent-soft: rgba(143, 120, 255, 0.16);
    --danger: #ff6369;
    --danger-soft: rgba(255, 99, 105, 0.14);
    --success: #3dd68c;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 16px 40px -12px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 32px 80px -16px rgba(0, 0, 0, 0.8);
  }
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(60rem 40rem at 10% -10%, var(--glow-1), transparent 60%),
    radial-gradient(50rem 36rem at 100% 0%, var(--glow-2), transparent 60%),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: auto, auto, 32px 32px, 32px 32px;
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

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

svg { width: 1em; height: 1em; flex: none; }

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

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

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.shell {
  max-width: 920px;
  margin: 0 auto;
  padding: 0 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; }

/* ---------- Header & footer ---------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 22px 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.brand:hover { text-decoration: none; }
.brand-name span { color: var(--muted); font-weight: 500; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 11px;
  color: var(--on-accent);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 20px -6px var(--accent);
  font-size: 24px;
  transition: transform 0.4s var(--ease);
}
.brand:hover .brand-mark { transform: rotate(-8deg) scale(1.06); }

.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  backdrop-filter: blur(8px);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.mode-local { color: var(--success); border-color: color-mix(in srgb, var(--success) 35%, transparent); }

.pulse {
  position: relative;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.pulse::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2s var(--ease) infinite;
}

.site-footer {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 40px 0 28px;
  color: var(--faint);
  font-size: 0.82rem;
}

/* ---------- Hero ---------- */

.hero { padding: 28px 0 30px; animation: rise 0.7s var(--ease) both; }

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.2rem, 6.5vw, 3.6rem);
  line-height: 1.04;
  letter-spacing: -0.045em;
  font-weight: 700;
}

.gradient-text {
  background: linear-gradient(100deg, var(--accent) 10%, var(--accent-2) 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.stats {
  display: flex;
  gap: 12px;
  margin: 26px 0 0;
}
.stats div {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  backdrop-filter: blur(8px);
}
.stats dt { color: var(--faint); font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; }
.stats dd { margin: 0; font-family: var(--mono); font-size: 1.15rem; font-weight: 700; }

/* ---------- Panels ---------- */

.panel, .dropzone {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  animation: rise 0.7s var(--ease) 0.08s both;
}

/* ---------- Upload ---------- */

.dropzone { margin-bottom: 20px; padding: 8px; }

.dropzone-target {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 30px 20px;
  border-radius: calc(var(--radius) - 6px);
  text-align: center;
  cursor: pointer;
  background: radial-gradient(30rem 10rem at 50% 0%, var(--accent-soft), transparent 70%), var(--surface-solid);
  border: 2px dashed color-mix(in srgb, var(--accent) 40%, transparent);
  transition: transform 0.3s var(--ease), border-color 0.3s;
}
.dropzone-target:hover { transform: translateY(-1px); border-color: var(--accent); }
.dropzone-target:hover .dropzone-icon { transform: translateY(-4px); }

.dropzone-icon {
  display: grid;
  place-items: center;
  width: 56px; height: 56px;
  margin-bottom: 8px;
  border-radius: 16px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 30px;
  transition: transform 0.4s var(--ease);
}
.dropzone-title { font-weight: 600; font-size: 1.08rem; }
.dropzone-hint { color: var(--muted); font-size: 0.9rem; }
.dropzone-hint u { text-decoration-color: var(--accent); text-underline-offset: 3px; color: var(--accent); }

.dropzone.busy .dropzone-target { pointer-events: none; opacity: 0.6; }

.upload-queue { list-style: none; margin: 0; padding: 0; }
.upload-queue:not(:empty) { padding: 8px 8px 4px; }

.upload-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  padding: 10px 4px;
  font-size: 0.9rem;
  animation: rise 0.4s var(--ease) both;
}
.upload-item + .upload-item { border-top: 1px solid var(--border); }
.upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.upload-state { color: var(--muted); font-family: var(--mono); font-size: 0.8rem; }
.upload-item.is-done .upload-state { color: var(--success); }
.upload-item.is-failed .upload-state { color: var(--danger); }

.upload-bar {
  grid-column: 1 / -1;
  height: 6px;
  border-radius: 99px;
  background: var(--accent-soft);
  overflow: hidden;
}
.upload-bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2), var(--accent));
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  transition: width 0.2s ease-out;
}
/* Progress unknown (the browser can't report it): a segment sweeps across the bar. */
.upload-item.is-indeterminate .upload-bar span {
  width: 35% !important;
  animation: shimmer 1.4s linear infinite, sweep 1.3s ease-in-out infinite;
}
.upload-item.is-done .upload-bar span { background: var(--success); animation: none; }
.upload-item.is-failed .upload-bar span { background: var(--danger); animation: none; }

.drag-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(6px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  pointer-events: none;
}
.drag-overlay.show { opacity: 1; visibility: visible; }
.drag-overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(100%, 520px);
  padding: 64px 24px;
  border: 3px dashed var(--accent);
  border-radius: 28px;
  background: var(--surface-solid);
  box-shadow: var(--shadow-lg);
  color: var(--accent);
  font-size: 1.3rem;
  transform: scale(0.96);
  transition: transform 0.3s var(--ease);
}
.drag-overlay.show .drag-overlay-card { transform: scale(1); }
.drag-overlay-card svg { font-size: 64px; animation: bob 1.2s ease-in-out infinite; }

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-solid);
  color: var(--faint);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.search input {
  flex: 1;
  min-width: 0;
  height: 42px;
  border: 0;
  outline: 0;
  background: none;
  color: var(--text);
}
.search input::-webkit-search-cancel-button { display: none; }
.search kbd {
  padding: 1px 7px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.75rem;
}
.search:focus-within kbd { visibility: hidden; }

.sort select {
  height: 44px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-solid) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b90aa' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E") no-repeat right 10px center / 16px;
  cursor: pointer;
  appearance: none;
}
.sort select:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

/* ---------- File list ---------- */

.file-list { list-style: none; margin: 0; padding: 6px; }

.file {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px;
  border-radius: 13px;
  transition: background 0.2s;
  animation: rise 0.5s var(--ease) both;
  animation-delay: calc(0.12s + var(--i, 0) * 0.03s);
}
.file:hover { background: var(--surface-hover); }

/* A row an AI agent just acted on (WebMCP), so the change is visible to the person. */
.file.agent-highlight { animation: agent-pulse 2.2s var(--ease) both; }
.file[hidden] { display: none; }

.file-icon {
  --kind: #7c8098;
  position: relative;
  display: grid;
  place-items: end center;
  width: 42px; height: 50px;
  padding-bottom: 7px;
  border-radius: 8px;
  color: var(--kind);
  background: color-mix(in srgb, var(--kind) 15%, transparent);
  clip-path: polygon(0 0, 68% 0, 100% 26%, 100% 100%, 0 100%);
  font-family: var(--mono);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  transition: transform 0.3s var(--ease);
}
.file-icon::before {
  content: "";
  position: absolute;
  top: 0; right: 0;
  width: 32%; height: 26%;
  border-bottom-left-radius: 5px;
  background: color-mix(in srgb, var(--kind) 35%, transparent);
}
.file-icon:hover { text-decoration: none; }
.file:hover .file-icon { transform: rotate(-4deg) scale(1.05); }

.kind-image      { --kind: #ec4899; }
.kind-video      { --kind: #8b5cf6; }
.kind-audio      { --kind: #14b8a6; }
.kind-archive    { --kind: #f59e0b; }
.kind-document   { --kind: #3b82f6; }
.kind-code       { --kind: #22c55e; }
.kind-executable { --kind: #ef4444; }

.file-main { flex: 1; min-width: 0; }
.file-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-weight: 600;
}
.file-meta {
  display: flex;
  gap: 6px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.76rem;
}

.file-actions { display: flex; align-items: center; gap: 4px; }
.file-actions form { margin: 0; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.2s, background 0.2s, color 0.2s, transform 0.2s var(--ease);
}
.file:hover .icon-btn, .icon-btn:focus-visible { opacity: 1; }
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.icon-btn:active { transform: scale(0.9); }
.icon-btn.copied { opacity: 1; color: var(--success); background: color-mix(in srgb, var(--success) 14%, transparent); }
.icon-btn-danger:hover { background: var(--danger-soft); color: var(--danger); }

.btn-download {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-left: 4px;
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.88rem;
  font-weight: 600;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.2s var(--ease);
}
.btn-download svg { font-size: 16px; transition: transform 0.3s var(--ease); }
.btn-download:hover {
  text-decoration: none;
  color: var(--on-accent);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 20px -8px var(--accent);
}
.btn-download:hover svg { transform: translateY(2px); }
.btn-download:active { transform: scale(0.96); }

.no-match { margin: 0; padding: 28px 20px 34px; text-align: center; color: var(--muted); }

/* ---------- Empty & error states ---------- */

.empty { padding: 56px 24px 60px; text-align: center; }
.empty-art { width: 120px; height: 96px; color: var(--accent); animation: bob 3s ease-in-out infinite; }
.error-art { width: 72px; height: 72px; color: var(--danger); }
.empty h2 { margin: 12px 0 4px; font-size: 1.3rem; letter-spacing: -0.02em; }
.empty p { margin: 0 auto; max-width: 30rem; color: var(--muted); }
.request-id { margin-top: 16px !important; font-size: 0.8rem; }
.request-id code { font-family: var(--mono); }

/* ---------- Dialog ---------- */

.dialog {
  width: min(calc(100% - 32px), 400px);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface-solid);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.dialog[open] { animation: pop 0.3s var(--ease); }
.dialog::backdrop { background: rgba(8, 9, 15, 0.45); backdrop-filter: blur(4px); }
.dialog h2 { margin: 14px 0 6px; font-size: 1.25rem; letter-spacing: -0.02em; }
.dialog p { margin: 0; color: var(--muted); font-size: 0.95rem; }
.dialog-filename { color: var(--text); word-break: break-all; }
.dialog-icon {
  display: inline-grid;
  place-items: center;
  width: 52px; height: 52px;
  border-radius: 16px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 24px;
}
.dialog-actions { display: flex; gap: 10px; margin-top: 22px; }

.btn {
  flex: 1;
  height: 44px;
  border: 0;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s var(--ease), filter 0.2s, background 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn-ghost { background: var(--accent-soft); color: var(--text); }
.btn-ghost:hover { filter: brightness(1.08); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }

/* ---------- Toasts ---------- */

.toast-region {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 420px;
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 11px 16px 11px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--surface-solid);
  box-shadow: var(--shadow-lg);
  font-size: 0.92rem;
  font-weight: 500;
  opacity: 0;
  transform: translateY(12px) scale(0.96);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}
.toast.show { opacity: 1; transform: none; }
.toast-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast-icon {
  display: grid;
  place-items: center;
  width: 24px; height: 24px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--success);
  background: color-mix(in srgb, var(--success) 16%, transparent);
}
.toast-error .toast-icon { color: var(--danger); background: var(--danger-soft); }

/* ---------- Motion ---------- */

@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes pop { from { opacity: 0; transform: scale(0.94) translateY(8px); } }
@keyframes bob { 50% { transform: translateY(-6px); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes pulse { 0% { transform: scale(1); opacity: 0.6; } 100% { transform: scale(3); opacity: 0; } }
@keyframes sweep { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
@keyframes agent-pulse {
  0%, 30% { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
  100% { background: transparent; box-shadow: inset 0 0 0 2px transparent; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Small screens ---------- */

@media (max-width: 600px) {
  .shell { padding: 0 16px; }
  .site-header { padding: 16px 0; }
  .hero { padding: 16px 0 22px; }
  .toolbar { flex-wrap: wrap; padding: 10px; }
  .sort, .sort select { width: 100%; }
  .file { gap: 12px; padding: 10px 6px; }
  .icon-btn { opacity: 1; width: 34px; }
  .btn-download { padding: 9px; margin-left: 0; }
  .btn-download span { display: none; }
  .btn-download svg { font-size: 18px; }
}
