/* shelf — one stylesheet, mobile first.
 *
 * The listing is the whole app, so it gets the attention: a row is a tap
 * target first and a table row second. On a narrow screen the modified column
 * goes, then the size column shares the line with the name. */

:root {
  color-scheme: dark light;
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2129;
  --border: #30363d;
  --fg: #e6edf3;
  --dim: #8b949e;
  --accent: #58a6ff;
  --ok: #3fb950;
  --danger: #f85149;
  --radius: 10px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --panel: #f6f8fa;
    --panel-2: #eef1f4;
    --border: #d0d7de;
    --fg: #1f2328;
    --dim: #636c76;
    --accent: #0969da;
    --ok: #1a7f37;
    --danger: #cf222e;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  /* The home indicator on an iPhone sits over the last row otherwise. */
  padding-bottom: env(safe-area-inset-bottom);
}

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

main { max-width: 58rem; margin: 0 auto; padding: 0 .75rem 3rem; }

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

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .7rem .9rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: .5rem; font-weight: 600; letter-spacing: -0.01em; }
.logo {
  width: 1.1rem; height: 1.1rem; border-radius: 3px;
  background: var(--accent);
  /* A folder glyph, drawn rather than fetched: one less request, and it
   * inherits the accent colour for free. */
  clip-path: polygon(0 15%, 40% 15%, 50% 30%, 100% 30%, 100% 100%, 0 100%);
}

.who { display: flex; align-items: center; gap: .5rem; font-size: .82rem; color: var(--dim); min-width: 0; }
.who img { width: 26px; height: 26px; border-radius: 50%; flex: none; }
.who .addr { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 11rem; }
.who button {
  font: inherit; font-size: .8rem; color: var(--dim); background: none;
  border: 1px solid var(--border); border-radius: 6px; padding: .15rem .55rem; cursor: pointer;
}
.who button:hover { color: var(--fg); border-color: var(--dim); }

/* ---- breadcrumb ---- */

.crumbs {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem;
  padding: .9rem .15rem .7rem;
  font-size: .92rem;
}
.crumbs .sep { color: var(--dim); }
.crumbs .here { color: var(--dim); font-weight: 600; }

/* ---- listing ---- */

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

.row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  grid-template-areas: "name size acts";
  align-items: center;
  gap: .5rem;
  padding: .1rem .6rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--panel-2); }

.cell.name {
  grid-area: name;
  display: flex; align-items: center; gap: .55rem;
  min-width: 0;
  /* The tap target is the row's full height, not the text's. */
  padding: .7rem 0;
  color: inherit;
}
.cell.name:hover { text-decoration: none; color: var(--accent); }
.nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cell.size { grid-area: size; font-size: .8rem; color: var(--dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell.when { grid-area: when; font-size: .8rem; color: var(--dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell.acts { grid-area: acts; display: flex; gap: .2rem; }

@media (min-width: 42rem) {
  .row {
    grid-template-columns: 1fr 6rem 9rem auto;
    grid-template-areas: "name size when acts";
  }
}
@media (max-width: 42rem) {
  .cell.when { display: none; }
}

.act {
  font: inherit; font-size: .9rem; line-height: 1;
  color: var(--dim); background: none; border: 1px solid transparent;
  border-radius: 6px; padding: .4rem .5rem; cursor: pointer;
}
.act:hover { color: var(--fg); border-color: var(--border); background: var(--bg); text-decoration: none; }
.act.danger:hover { color: var(--danger); border-color: var(--danger); }

.row.up .cell.name { color: var(--dim); }
.empty { color: var(--dim); padding: 2rem .2rem; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }

/* Icons: a coloured square per kind. Cheap, legible at a glance, and no
 * sprite sheet to keep in step with the Go that names them. */
.ic { width: .85rem; height: .85rem; border-radius: 2px; flex: none; background: var(--dim); }
.ic-dir { background: var(--accent); clip-path: polygon(0 10%, 42% 10%, 52% 28%, 100% 28%, 100% 100%, 0 100%); }
.ic-up { background: var(--dim); clip-path: polygon(50% 0, 100% 55%, 70% 55%, 70% 100%, 30% 100%, 30% 55%, 0 55%); }
.ic-video { background: #d29922; }
.ic-image { background: #a371f7; }
.ic-audio { background: #db61a2; }
.ic-doc { background: #58a6ff; }
.ic-book { background: #3fb950; }
.ic-zip { background: #8b949e; }
.ic-file { background: #6e7681; }

/* ---- writer controls ---- */

.writer { margin: .3rem 0 1rem; }

.drop {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.3rem 1rem;
  text-align: center;
  cursor: pointer;
  display: flex; flex-direction: column; gap: .25rem;
  background: var(--panel);
}
.drop:hover, .drop:focus-visible { border-color: var(--accent); outline: none; }
.drop.over { border-color: var(--accent); background: var(--panel-2); }
.drop-main { font-weight: 600; font-size: .95rem; }
.drop-sub { font-size: .78rem; color: var(--dim); }

.tools { display: flex; gap: .5rem; margin-top: .6rem; }

.btn {
  font: inherit; font-size: .88rem;
  color: var(--fg); background: var(--panel);
  border: 1px solid var(--border); border-radius: 7px;
  padding: .45rem .9rem; cursor: pointer;
}
.btn:hover { border-color: var(--dim); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0d1117; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--danger); border-color: var(--border); }
.btn.danger:hover { border-color: var(--danger); }

/* ---- uploads in progress ---- */

.uploads { list-style: none; margin: .8rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .45rem; }
.up {
  border: 1px solid var(--border); border-radius: 8px; padding: .55rem .7rem;
  background: var(--panel); font-size: .85rem;
}
.up-head { display: flex; justify-content: space-between; gap: .8rem; align-items: baseline; }
.up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-stat { color: var(--dim); font-size: .78rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.up-bar { height: 4px; border-radius: 2px; background: var(--panel-2); margin-top: .45rem; overflow: hidden; }
.up-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s ease; }
.up.done .up-fill { background: var(--ok); }
.up.failed .up-fill { background: var(--danger); }
.up.failed .up-stat { color: var(--danger); }
.up-cancel {
  font: inherit; font-size: .78rem; color: var(--dim); background: none;
  border: 0; cursor: pointer; padding: 0 0 0 .5rem;
}
.up-cancel:hover { color: var(--danger); }

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

.file { padding-top: .3rem; }
.fname { font-size: 1.25rem; margin: .2rem 0 .4rem; word-break: break-word; line-height: 1.3; }
.meta { color: var(--dim); font-size: .84rem; display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 1rem; }
.dim { color: var(--dim); }
.filebar { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.2rem; }

.prev {
  display: block; width: 100%; max-height: 70vh;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: #000;
}
img.prev { object-fit: contain; }
audio.prev { background: transparent; max-height: none; }
.prev.tall { height: 75vh; max-height: none; background: var(--panel); }

/* ---- dialog ---- */

dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel); color: var(--fg);
  padding: 1.1rem; width: min(26rem, calc(100vw - 2rem));
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h2 { margin: 0 0 .5rem; font-size: 1rem; }
dialog p { margin: 0 0 .8rem; font-size: .87rem; color: var(--dim); line-height: 1.45; }
dialog p strong { color: var(--fg); word-break: break-word; }
dialog input {
  font: inherit; width: 100%; padding: .5rem .6rem; margin-bottom: .9rem;
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--border); border-radius: 7px;
}
dialog input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.dlg-acts { display: flex; justify-content: flex-end; gap: .5rem; }

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

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(1.2rem + env(safe-area-inset-bottom));
  background: var(--panel-2); color: var(--fg);
  border: 1px solid var(--border); border-radius: 8px;
  padding: .6rem 1rem; font-size: .85rem;
  max-width: calc(100vw - 2rem); z-index: 20;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
}
.toast.bad { border-color: var(--danger); color: var(--danger); }

/* ---- misc ---- */

.err { text-align: center; padding: 3rem 1rem; }
.err h1 { font-size: 3rem; margin: 0; color: var(--dim); }
.err p { color: var(--dim); }

.foot {
  margin-top: 2rem; padding-top: .9rem;
  border-top: 1px solid var(--border);
  font-size: .75rem; color: var(--dim);
  display: flex; gap: .4rem;
}

[hidden] { display: none !important; }
