:root {
  color-scheme: light dark;
  --bg: #fff; --fg: #1a1a1a; --muted: #666; --border: #ddd; --accent: #2563eb; --danger: #b91c1c;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #16181d; --fg: #e6e6e6; --muted: #9aa0a6; --border: #30333a; --accent: #6ea8fe; --danger: #f87171; }
}
* { box-sizing: border-box; }
body {
  font-family: -apple-system, system-ui, sans-serif;
  background: var(--bg); color: var(--fg); margin: 0;
}
header {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem;
  padding: 0.75rem 1.5rem; border-bottom: 1px solid var(--border);
}
header nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0 1rem; }
header nav a { color: var(--fg); text-decoration: none; }
header nav a:hover { color: var(--accent); }
main { max-width: 900px; margin: 0 auto; padding: 1.5rem; }
.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li { padding: 0.5rem 0.75rem; border-radius: 6px; margin-bottom: 0.5rem; background: var(--border); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--border); }
.table-scroll { overflow-x: auto; }
.tag { display: inline-block; background: var(--border); border-radius: 999px; padding: 0.1rem 0.6rem; font-size: 0.85em; margin-right: 0.25rem; }
.btn {
  display: inline-flex; align-items: center; background: var(--accent); color: #fff; border: none;
  padding: 0.4rem 0.9rem; border-radius: 6px; cursor: pointer; text-decoration: none;
  font-size: 0.9em; min-height: 2.5rem; box-sizing: border-box;
}
.btn.danger { background: var(--danger); }
.btn.secondary { background: var(--border); color: var(--fg); }
input, textarea, select { background: var(--bg); color: var(--fg); border: 1px solid var(--border); border-radius: 4px; padding: 0.4rem; }
textarea { width: 100%; font-family: monospace; }
.field { margin-bottom: 0.75rem; }
.muted { color: var(--muted); font-size: 0.9em; }
.card { border: 1px solid var(--border); border-radius: 8px; padding: 1rem; margin-bottom: 1rem; }

/* Crop box + tightened crop field row */
.crop-container { position: relative; display: inline-block; max-width: 100%; touch-action: none; }
.crop-box {
  position: absolute; border: 2px dashed var(--accent); background: rgba(37, 99, 235, 0.15);
  cursor: move; box-sizing: border-box; touch-action: none;
}
.crop-box .handle {
  position: absolute; width: 10px; height: 10px; background: var(--accent);
  border-radius: 50%; right: -5px; bottom: -5px; cursor: nwse-resize;
  touch-action: none;
}
.crop-fields { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 0.75rem; }
.crop-fields label { display: flex; flex-direction: column; font-size: 0.8em; gap: 0.2rem; }
.crop-fields input[type=number] { width: 4.5rem; }

/* Kind filter cards */
.kind-cards { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.kind-card {
  border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 1rem;
  text-decoration: none; color: var(--fg); min-width: 90px; text-align: center;
}
.kind-card:hover { border-color: var(--accent); }
.kind-card.active { border-color: var(--accent); background: rgba(37, 99, 235, 0.08); }
.kind-card .count { display: block; font-size: 1.3em; font-weight: 600; }
.kind-card .label { font-size: 0.85em; color: var(--muted); }

/* Search form */
.search-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.search-form label { display: flex; flex-direction: column; font-size: 0.8em; gap: 0.2rem; }

/* File grid */
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.file-card { border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem; }
.file-card .thumb {
  width: 100%; height: 140px; object-fit: cover; border-radius: 6px;
  cursor: pointer; margin-bottom: 0.5rem; display: block;
}
.file-card .placeholder-thumb {
  width: 100%; height: 140px; display: flex; align-items: center; justify-content: center;
  background: var(--border); border-radius: 6px; margin-bottom: 0.5rem;
  font-size: 0.85em; color: var(--muted); text-align: center; padding: 0.5rem;
}
.file-card .placeholder-thumb.clickable { cursor: pointer; }
.file-card .title { font-weight: 600; display: block; margin-bottom: 0.25rem; }
.file-card .actions { margin-top: 0.5rem; display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }

/* File-detail page preview */
.detail-preview {
  max-width: 100%; max-height: 400px; object-fit: contain; border-radius: 8px;
  cursor: pointer; display: block; margin-bottom: 1rem;
}
.detail-preview-placeholder {
  width: 100%; max-width: 400px; height: 160px; display: flex; align-items: center;
  justify-content: center; background: var(--border); border-radius: 8px;
  margin-bottom: 1rem; color: var(--muted);
}
.detail-preview-placeholder.clickable { cursor: pointer; }

/* Badges */
.badge { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.75em; margin-right: 0.25rem; }
.badge.raw { background: rgba(22, 163, 74, 0.2); color: #16a34a; }
.badge.protected { background: rgba(234, 88, 12, 0.2); color: #ea580c; }

/* Tag autocomplete */
.tag-suggestions {
  position: absolute; background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  max-height: 160px; overflow-y: auto; z-index: 10; display: none; width: 100%; top: 100%; left: 0;
}
.tag-suggestion-item { padding: 0.3rem 0.5rem; cursor: pointer; }
.tag-suggestion-item:hover { background: var(--border); }

/* Copy-link row */
.copy-row { display: flex; gap: 0.5rem; align-items: center; margin: 0.25rem 0; }
.copy-row input[readonly] { flex: 1; font-family: monospace; font-size: 0.85em; }

/* Media modal (image / video / audio / text) */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.85);
  align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay img, .modal-overlay video { max-width: 90vw; max-height: 90vh; }
.modal-overlay audio { width: 80vw; max-width: 500px; }
#modal-img { touch-action: none; -webkit-user-drag: none; user-select: none; }
.modal-overlay pre#modal-text {
  background: var(--bg); color: var(--fg); border-radius: 8px; padding: 1rem;
  max-width: 90vw; max-height: 85vh; overflow: auto; white-space: pre-wrap;
  word-break: break-word; font-family: monospace; font-size: 0.85em; margin: 0;
}
.modal-close {
  position: absolute; top: 1rem; right: 1.5rem; color: #fff; font-size: 2em;
  cursor: pointer; line-height: 1;
}

/* Tag chip input */
.tag-chip-input {
  border: 1px solid var(--border); border-radius: 6px; padding: 0.4rem;
  display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center;
}
.tag-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tag-chip {
  background: var(--accent); color: #fff; border-radius: 999px;
  padding: 0.15rem 0.4rem 0.15rem 0.6rem; font-size: 0.85em;
  display: inline-flex; align-items: center; gap: 0.3rem;
}
.tag-chip-remove { cursor: pointer; font-weight: bold; padding: 0 0.2rem; }
.tag-chip-remove:hover { opacity: 0.7; }
.tag-chip-entry { border: none; outline: none; background: transparent; flex: 1; min-width: 80px; padding: 0.2rem; }
