/* fileman UI. No inline styles anywhere (CSP), so everything lives here. */

:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #1a1d23;
  --muted: #545d6b;
  --border: #d3d8e0;
  --accent: #0a5cd1;
  --accent-text: #ffffff;
  --accent-soft: #e4eefc;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --focus: #0a5cd1;
  --shadow: 0 1px 2px rgb(20 30 50 / 8%), 0 2px 8px rgb(20 30 50 / 6%);

  --k-folder: #9a5b00;
  --k-audio: #7233d6;
  --k-video: #b9400c;
  --k-image: #067050;
  --k-archive: #8a6100;
  --k-text: #4a5568;
  --k-code: #04649b;
  --k-other: #4a5568;

  --font: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", "Noto Sans CJK JP", "Yu Gothic UI", "Meiryo", sans-serif;
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #20252d;
    --text: #e9ecf1;
    --muted: #a5afbd;
    --border: #353c47;
    --accent: #7db2ff;
    --accent-text: #07111f;
    --accent-soft: #1b2a41;
    --danger: #ff9a92;
    --danger-soft: #3a1f1d;
    --focus: #8fbcff;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);

    --k-folder: #fbbf24;
    --k-audio: #c8b6ff;
    --k-video: #ffb98a;
    --k-image: #6ee7b7;
    --k-archive: #f5d85a;
    --k-text: #cbd5e1;
    --k-code: #7dd3fc;
    --k-other: #cbd5e1;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--font);
  overflow-x: hidden;
}

a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }

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

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

svg.i {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- buttons & fields ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  min-height: var(--tap);
  padding: 0 1.1em;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.small { min-height: 36px; padding: 0 0.8em; font-size: 0.9rem; }
.btn.block { width: 100%; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger-bg { background: var(--danger); border-color: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) {
  .btn.danger-bg { color: #2a0a08; }
}
.btn.discord { background: #4752c4; border-color: #4752c4; color: #fff; width: 100%; }
.btn.discord:hover { background: #3c45a5; }

input:not([type="file"]) {
  width: 100%;
  min-height: var(--tap);
  padding: 0 0.85em;
  border: 1px solid var(--muted);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input::placeholder { color: var(--muted); opacity: 1; }
input:focus-visible { outline-offset: 0; }

.error { color: var(--danger); margin: 0.5rem 0; min-height: 1.6em; }
.error:empty { min-height: 0; margin: 0; }
.notice {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger);
}

/* ---------- login ---------- */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 28px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.brand-lg { margin: 0 0 0.25rem; font-size: 1.75rem; letter-spacing: 0.02em; }
.login-lead { margin: 0 0 1.25rem; color: var(--muted); }
.field { display: block; margin-bottom: 1rem; font-weight: 600; }
.field input { margin-top: 0.35rem; font-weight: 400; }
.or {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.25rem 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--border); }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.topbar-in {
  max-width: 1000px;
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
}
.brand {
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--text);
  text-decoration: none;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
}
.user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.whoami { min-width: 0; overflow-wrap: anywhere; font-weight: 600; }
.badge {
  display: inline-block;
  margin-left: 0.4em;
  padding: 0 0.5em;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  vertical-align: 0.1em;
}
.crumbs {
  flex: 1 0 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 2px;
  min-width: 0;
}
.crumbs a, .crumbs .cur {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  min-height: 36px;
  padding: 0 6px;
  border-radius: 6px;
  overflow-wrap: anywhere;
  max-width: 100%;
}
.crumbs a { text-decoration: none; font-weight: 600; }
.crumbs a:hover { background: var(--accent-soft); }
.crumbs .cur { font-weight: 800; color: var(--text); }
.crumbs .sep { color: var(--muted); }

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

.page { max-width: 1000px; margin: 0 auto; padding: 16px 16px 64px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  margin-bottom: 12px;
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.filter { flex: 1 1 220px; max-width: 420px; margin-left: auto; }

.summary { margin: 4px 2px 8px; color: var(--muted); font-size: 0.9rem; }

.list-head {
  position: sticky;
  top: var(--topbar-h, 0px);
  z-index: 5;
  display: flex;
  gap: 4px;
  padding: 0 4px;
  background: var(--bg);
}
.sortbtn {
  min-height: var(--tap);
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}
.sortbtn:hover { background: var(--surface-2); color: var(--text); }
.sortbtn[aria-pressed="true"] { color: var(--accent); }
.sortbtn[aria-pressed="true"]::after { content: " ↑"; }
.sortbtn[aria-pressed="true"].desc::after { content: " ↓"; }

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

.list, .cards { list-style: none; margin: 0; padding: 0; }
.list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.row {
  position: relative;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 96px 150px 88px;
  align-items: center;
  gap: 0 12px;
  min-height: 64px;
  padding: 8px 8px 8px 12px;
  border-top: 1px solid var(--border);
}
.row:first-child { border-top: 0; }
.row:hover { background: var(--surface-2); }
.row:focus-within { background: var(--accent-soft); }

.ico {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  color: var(--k, var(--k-other));
  background: color-mix(in srgb, var(--k, var(--k-other)) 14%, transparent);
  font-size: 1.15rem;
}
.ico svg.i { width: 24px; height: 24px; }
.kind-folder { --k: var(--k-folder); }
.kind-audio { --k: var(--k-audio); }
.kind-video { --k: var(--k-video); }
.kind-image { --k: var(--k-image); }
.kind-archive { --k: var(--k-archive); }
.kind-text { --k: var(--k-text); }
.kind-code { --k: var(--k-code); }
.kind-up { --k: var(--muted); }

.main { min-width: 0; }
.nm {
  display: block;
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  overflow-wrap: anywhere;
  line-height: 1.4;
}
.row .nm::after { content: ""; position: absolute; inset: 0; }
.nm:focus-visible { outline: none; }
.row:has(.nm:focus-visible) { outline: 3px solid var(--focus); outline-offset: -3px; }
.is-dir .nm { font-weight: 700; }
.meta { display: none; color: var(--muted); font-size: 0.875rem; }

.size, .mod { color: var(--muted); font-size: 0.9rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.size { text-align: right; }

.acts { position: relative; z-index: 1; display: flex; gap: 2px; min-width: 0; }
.iconbtn {
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.iconbtn:hover { background: var(--border); color: var(--text); }
.iconbtn.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* shares at "/" */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 84px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.card:hover { border-color: var(--accent); }
.card .ico { width: 52px; height: 52px; }
.card .ico svg.i { width: 28px; height: 28px; }
.card .nm { font-size: 1.1rem; font-weight: 700; }
.card .nm::after { content: ""; position: absolute; inset: 0; border-radius: 14px; }
.card:has(.nm:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.card .meta { display: block; }

.empty {
  padding: 48px 16px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 14px;
}
.empty-title { margin: 0; font-size: 1.1rem; font-weight: 700; overflow-wrap: anywhere; }
.empty-sub { margin: 0.4rem 0 0; color: var(--muted); }

/* ---------- uploads ---------- */

.uploads { display: grid; gap: 8px; margin-bottom: 12px; }
.uploads:empty { display: none; }
.up {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 12px;
  align-items: center;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.up.err { border-color: var(--danger); }
.up-name { overflow-wrap: anywhere; font-weight: 600; }
.up-right { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 0.9rem; }
.up.err .up-status { color: var(--danger); }
.up progress { grid-column: 1 / -1; width: 100%; height: 8px; accent-color: var(--accent); }

/* ---------- dialog & drop overlay ---------- */

dialog {
  width: min(92vw, 440px);
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 40px rgb(0 0 0 / 35%);
}
dialog::backdrop { background: rgb(0 0 0 / 55%); }
.dlg-msg { margin: 0 0 1rem; overflow-wrap: anywhere; white-space: pre-line; }
.dlg-buttons { display: flex; justify-content: flex-end; gap: 10px; margin-top: 1.1rem; }
#dlg-input[hidden] + .dlg-buttons { margin-top: 0; }

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--accent) 22%, rgb(0 0 0 / 55%));
  pointer-events: none;
}
.drop-overlay span {
  padding: 22px 34px;
  border: 3px dashed var(--accent-text);
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 1.3rem;
  font-weight: 800;
}

/* ---------- desktop: header row aligns with columns ---------- */

@media (min-width: 701px) {
  .list-head { display: grid; grid-template-columns: 44px minmax(0, 1fr) 96px 150px 88px; gap: 0 12px; padding: 0 8px 0 12px; }
  .list-head .col-name { grid-column: 1 / 3; text-align: left; margin-left: -12px; }
  .list-head .col-size { text-align: right; }
  .list-head .col-mod { text-align: left; }
}

/* share cards at "/": plain row of sort buttons, not table columns */
.list-head.for-cards { display: flex; padding: 0 4px; }
.list-head.for-cards .sortbtn { margin-left: 0; }

/* ---------- mobile ---------- */

@media (max-width: 700px) {
  .row {
    grid-template-columns: 44px minmax(0, 1fr) auto;
    grid-template-areas: "ico main acts";
    min-height: 68px;
  }
  .row .size, .row .mod { display: none; }
  .row .meta { display: block; }
  .page { padding: 12px 12px 56px; }
  .topbar-in { padding: 6px 12px; }
  .actions { width: 100%; flex-wrap: nowrap; }
  .actions .btn { flex: 1 1 0; min-width: 0; padding: 0 0.6em; gap: 0.35em; white-space: nowrap; }
  #refresh-btn { flex: none; width: var(--tap); padding: 0; }
  #refresh-btn .lbl { display: none; }
  .filter { flex-basis: 100%; max-width: none; margin-left: 0; }
  .login-card { padding: 22px 18px; }
}

@media (max-width: 700px), (pointer: coarse) {
  .nm { font-size: 1.02rem; }
}

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