/* Same palette as temp/ and todo/ — the subdomains should look like one family. */
:root {
  /* Lets native controls and the scrollbar follow the theme instead of staying
     light-mode bright against a dark page. */
  color-scheme: light dark;

  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #e3e6ea;
  --text: #1c1f23;
  --muted: #7a828c;
  --accent: #2f6fed;
  --danger: #d1443c;
  --ok: #2c9c62;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel: #1c1f24;
    --border: #2b3038;
    --text: #e7eaee;
    --muted: #949ca7;
    --accent: #6f9dff;
    --danger: #f0736a;
    --ok: #5ac48b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

html {
  -webkit-text-size-adjust: 100%; /* iOS otherwise inflates text in landscape */
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}

/* No 300ms double-tap-to-zoom wait on anything meant to be tapped. */
.btn,
.tile__open,
.tile__action,
.queue__action {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

.muted,
.dot {
  color: var(--muted);
  font-size: 12px;
}

/* Layout — wider than todo/: a grid of tiles needs the room a list does not. */
.app {
  --gutter: 20px;

  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh; /* follows the mobile toolbars as they hide and reappear */
  margin: 0 auto;
  max-width: 1100px;
  padding: var(--gutter);
  padding-top: calc(var(--gutter) + env(safe-area-inset-top, 0px));
  padding-right: calc(var(--gutter) + env(safe-area-inset-right, 0px));
  padding-bottom: calc(var(--gutter) + env(safe-area-inset-bottom, 0px));
  padding-left: calc(var(--gutter) + env(safe-area-inset-left, 0px));
}

/* Topbar */
.topbar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding-bottom: 12px;
}

.topbar__title {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.topbar__meta {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-right: auto;
}

/* Status */
.status {
  color: var(--muted);
  font-size: 12px;
}

.status--live {
  color: var(--ok);
}

/* Pulsing dot: shows at a glance that the realtime stream is connected. */
.status--live::before {
  animation: pulse 2s ease-in-out infinite;
  background: var(--ok);
  border-radius: 50%;
  content: '';
  display: inline-block;
  height: 7px;
  margin-right: 5px;
  width: 7px;
}

.status--error {
  color: var(--danger);
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

@media (prefers-reduced-motion: reduce) {
  .status--live::before {
    animation: none;
  }
}

.search {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  /* 16px is a floor, not a preference: iOS zooms the page in on focus for
     anything smaller, and never zooms back out. */
  font-size: 16px;
  min-height: 36px;
  outline: none;
  padding: 6px 12px;
  width: 180px;
}

.search:focus {
  border-color: var(--accent);
}

/* Storage bar */
.storage {
  align-items: center;
  display: flex;
  gap: 10px;
  padding-bottom: 14px;
}

.storage__track {
  background: var(--border);
  border-radius: 999px;
  flex: 1;
  height: 4px;
  overflow: hidden;
}

.storage__fill {
  background: var(--accent);
  height: 100%;
  transition: width 0.3s ease;
  width: 0;
}

/* Nearly full is worth noticing before the next upload is refused. */
.storage__fill--full {
  background: var(--danger);
}

/* Upload queue — above the grid, because it is the thing currently happening. */
.queue {
  display: flex;
  flex-direction: column;
  gap: 6px;
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
}

.queue__item {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: grid;
  gap: 4px 12px;
  grid-template-columns: minmax(0, 1fr) auto auto;
  padding: 10px 14px;
}

.queue__item--error {
  border-color: var(--danger);
}

.queue__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue__note {
  color: var(--muted);
  font-size: 12px;
}

.queue__item--error .queue__note {
  color: var(--danger);
}

/* Spans the full width under the name, so the bar is as long as it can be. */
.queue__track {
  background: var(--border);
  border-radius: 999px;
  grid-column: 1 / -1;
  height: 3px;
  order: 3;
  overflow: hidden;
}

.queue__fill {
  background: var(--accent);
  height: 100%;
  transition: width 0.15s linear;
  width: 0;
}

.queue__item--error .queue__fill {
  background: var(--danger);
}

.queue__actions {
  display: flex;
  gap: 2px;
}

.queue__action {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  padding: 4px 6px;
}

.queue__action:hover {
  color: var(--text);
}

/* File grid — scrolls on its own so the topbar stays put. */
.files {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 6px;
}

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

.tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.tile:hover {
  border-color: var(--muted);
}

/* The preview area is the tile's main tap target — the whole square, not a link
   somewhere inside it. */
.tile__open {
  align-items: center;
  aspect-ratio: 4 / 3;
  background: var(--bg);
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  justify-content: center;
  overflow: hidden;
  padding: 0;
  width: 100%;
}

.tile__image {
  height: 100%;
  object-fit: cover;
  width: 100%;
}

/* Where there is no picture: the extension, large enough to read at a glance. */
.tile__badge {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.tile__badge--pdf,
.tile__badge--text {
  color: var(--danger);
}

.tile__badge--video,
.tile__badge--audio {
  color: var(--accent);
}

.tile__meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 10px 12px 12px;
}

.tile__name {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile__sub {
  color: var(--muted);
  font-size: 11px;
}

/* Floating over the thumbnail, so the actions cost the tile no height. */
.tile__actions {
  backdrop-filter: blur(6px);
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  gap: 2px;
  opacity: 0;
  padding: 2px;
  position: absolute;
  right: 6px;
  top: 6px;
  transition: opacity 0.12s ease;
}

.tile:hover .tile__actions,
.tile:focus-within .tile__actions {
  opacity: 1;
}

/* Touch screens have no hover, so the controls have to stay visible. */
@media (hover: none) {
  .tile__actions {
    opacity: 1;
  }
}

.tile__action {
  align-items: center;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  font-size: 14px;
  height: 28px;
  justify-content: center;
  line-height: 1;
  padding: 0;
  text-decoration: none;
  width: 28px;
}

.tile__action:hover {
  background: var(--bg);
  color: var(--text);
}

.tile__action--danger:hover {
  color: var(--danger);
}

.empty {
  color: var(--muted);
  font-size: 13px;
  padding: 40px 4px;
  text-align: center;
}

/* Buttons */
.btn {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  min-height: 36px;
  padding: 6px 14px;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover,
.btn:active {
  border-color: var(--muted);
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn--primary:hover {
  filter: brightness(1.08);
}

/* Drop overlay — the target is the whole window, so the cue has to be too. */
.drop {
  align-items: center;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  display: flex;
  inset: 0;
  justify-content: center;
  opacity: 0;
  pointer-events: none; /* never intercepts the drop it is announcing */
  position: fixed;
  transition: opacity 0.12s ease;
  z-index: 40;
}

.drop--active {
  opacity: 1;
}

.drop__label {
  border: 2px dashed var(--accent);
  border-radius: 16px;
  color: var(--accent);
  font-size: 16px;
  font-weight: 600;
  padding: 40px 60px;
}

/* Preview */
.preview {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  color: var(--text);
  max-height: 90dvh;
  max-width: min(900px, 92vw);
  padding: 0;
  width: 100%;
}

.preview::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.preview__bar {
  align-items: center;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 10px;
  padding: 12px 14px;
}

.preview__name {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview__body {
  align-items: center;
  display: flex;
  justify-content: center;
  max-height: calc(90dvh - 62px);
  overflow: auto;
  padding: 14px;
}

.preview__body img,
.preview__body video {
  max-height: calc(90dvh - 90px);
  max-width: 100%;
  object-fit: contain;
}

.preview__body audio {
  width: 100%;
}

/* A PDF has no intrinsic height to size to, so it is given one. */
.preview__body iframe {
  background: #fff;
  border: none;
  height: calc(90dvh - 90px);
  width: 100%;
}

/* Toast */
.toast {
  background: var(--text);
  border-radius: 8px;
  color: var(--panel);
  font-size: 13px;
  left: 50%;
  max-width: calc(100% - 32px);
  opacity: 0;
  padding: 8px 16px;
  pointer-events: none;
  position: fixed;
  text-align: center;
  top: calc(12px + env(safe-area-inset-top, 0px));
  transform: translate(-50%, -8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 50;
}

.toast--show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 600px) {
  .app {
    --gutter: 12px;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }

  /* The search box drops to its own row rather than squeezing the title out. */
  .search {
    order: 1;
    width: 100%;
  }
}

/* A tap has no cursor to aim with, so the controls get a little more room. */
@media (hover: none) {
  .btn,
  .search {
    min-height: 40px;
  }

  .tile__action {
    height: 34px;
    width: 34px;
  }
}
