/* A thin layer over Tailwind: only things utilities express badly. */

:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --bg-sunk: #eef0f4;
  --line: #e2e5ea;
  --text: #14161a;
  --text-dim: #656c78;
  --accent: #5b5bd6;
  --accent-soft: #eeeefc;
  --danger: #d64545;
  --ok: #2f9e63;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14151a;
    --bg-soft: #1b1d24;
    --bg-sunk: #23262f;
    --line: #2c303a;
    --text: #eceef2;
    --text-dim: #949cab;
    --accent: #8b8bf0;
    --accent-soft: #24243a;
    --danger: #f07171;
    --ok: #56c98a;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---- primitives ---- */

.card {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 13px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover:not(:disabled) { background: var(--bg-sunk); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn-danger { color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--bg-sunk); }
.btn-sm { padding: 5px 9px; font-size: 13px; }

.input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
label.field { display: block; margin-bottom: 14px; }
label.field > span {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-sunk);
  color: var(--text-dim);
}
.chip-live { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.chip-dead { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.chip-accent { background: var(--accent-soft); color: var(--accent); }

.muted { color: var(--text-dim); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

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

.shell { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  background: var(--bg-soft);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-dim);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.nav-item:hover { background: var(--bg-sunk); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

.topbar {
  height: 58px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
}

.content { flex: 1; overflow-y: auto; padding: 20px; }

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

.row {
  display: grid;
  grid-template-columns: 34px 1fr 96px 132px auto;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 9px;
  cursor: pointer;
}
.row:hover { background: var(--bg-soft); }
.row.selected { background: var(--accent-soft); }
.row-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.row:hover .row-actions, .row.selected .row-actions { opacity: 1; }

.grid-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 12px;
}
.tile {
  border: 1px solid var(--line);
  border-radius: 11px;
  overflow: hidden;
  cursor: pointer;
  background: var(--bg-soft);
}
.tile:hover { border-color: var(--accent); }
.tile.selected { border-color: var(--accent); background: var(--accent-soft); }
.tile-media {
  height: 108px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-sunk);
  overflow: hidden;
}
.tile-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-label {
  padding: 8px 10px 2px;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px 4px;
  font-size: 11px;
  white-space: nowrap;
}
/* Actions get their own row: alongside the size they were cramped enough at
   tile width that the last button was pushed out of the card. */
.tile-actions {
  display: flex;
  justify-content: center;
  padding: 0 4px 5px;
  border-top: 1px solid var(--line);
  margin-top: 2px;
  padding-top: 4px;
}
.tile-actions .row-actions { opacity: 1; gap: 0; }

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

.dropzone {
  border: 2px dashed var(--line);
  border-radius: 12px;
  padding: 30px 20px;
  text-align: center;
  color: var(--text-dim);
  transition: border-color .15s, background .15s;
}
.dropzone.hot { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

#drag-veil {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
#drag-veil.on { display: flex; }
#drag-veil > div {
  border: 3px dashed var(--accent);
  border-radius: 18px;
  padding: 40px 60px;
  background: var(--bg);
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
}

/* ---- upload tray ---- */

#tray {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 330px;
  max-width: calc(100vw - 32px);
  max-height: 55vh;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 12px 32px rgb(0 0 0 / .18);
}
.bar { height: 5px; border-radius: 999px; background: var(--bg-sunk); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); transition: width .18s; }

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

.overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgb(0 0 0 / .5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  width: 100%;
  max-width: 470px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgb(0 0 0 / .3);
}
.modal-wide { max-width: 940px; }
.modal-head {
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-body { padding: 18px; }
.modal-foot {
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 9px;
}

/* ---- toasts ---- */

#toasts {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 24px);
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 15px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgb(0 0 0 / .22);
  animation: drop .18s ease-out;
}
.toast.err { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@keyframes drop { from { opacity: 0; transform: translateY(-8px); } }

/* ---- stats ---- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 12px;
}
.stat { padding: 15px; }
.stat b { display: block; font-size: 25px; font-weight: 650; letter-spacing: -.02em; }
.stat span { font-size: 12.5px; color: var(--text-dim); }

table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.data td { padding: 10px; border-bottom: 1px solid var(--line); }
table.data tr:last-child td { border-bottom: none; }

.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

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

.only-mobile { display: none; }

@media (max-width: 820px) {
  .only-mobile { display: inline-flex; }
  .no-mobile { display: none !important; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 80;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  /* Shadow only while open — on a translated-off panel it bleeds a grey
     gradient down the left edge of the page. */
  .sidebar.open {
    transform: none;
    box-shadow: 0 0 40px rgb(0 0 0 / .3);
  }

  .content { padding: 14px; }
  .topbar { padding: 0 12px; }

  /* Size and date go away before the name does. */
  .row { grid-template-columns: 30px 1fr auto; gap: 10px; padding: 11px 8px; }
  .row .col-size, .row .col-date { display: none; }
  /* Touch has no hover, so actions are always visible. */
  .row-actions { opacity: 1; }

  .grid-tiles { grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 10px; }
  .tile-media { height: 92px; }

  #tray { right: 8px; left: 8px; bottom: 8px; width: auto; }
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; justify-content: center; }
  .stat b { font-size: 22px; }
}

/* Comfortable tap targets on touch devices regardless of width. */
@media (hover: none) {
  .btn { padding: 10px 14px; }
  .btn-sm { padding: 8px 10px; }
  .row-actions { opacity: 1; }
}
