:root {
  --accent: #fa5252;
  --accent-dark: #e03131;
  --bg: #f7f7f9;
  --card-bg: #ffffff;
  --text: #1c1c1e;
  --text-muted: #6b6b76;
  --border: #e6e6ea;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-hover: 0 6px 20px rgba(0, 0, 0, 0.09);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17171a;
    --card-bg: #221f22;
    --text: #f2f2f4;
    --text-muted: #a3a3ab;
    --border: #322f33;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-hover: 0 6px 24px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: inherit; text-decoration: none; }

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.brand span { color: var(--accent); }

.nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

.nav a, .nav button.linklike {
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
}
.nav a.active, .nav a:hover, .nav button.linklike:hover { background: var(--bg); color: var(--text); }

.nav .spacer { flex: 1; }

/* ---------- Layout helpers ---------- */

.view { max-width: 1100px; margin: 0 auto; padding: 24px; }
.view-narrow { max-width: 480px; margin: 60px auto; padding: 24px; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.section-title { font-size: 15px; font-weight: 700; margin: 28px 0 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- Buttons / forms ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}
.btn:hover { border-color: var(--text-muted); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

.btn-danger { color: var(--accent-dark); }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.field input[type="text"], .field input[type="password"], .field input[type="search"], .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field-row { display: flex; gap: 12px; }
.field-row > .field { flex: 1; }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

form .error { color: var(--accent-dark); font-size: 13px; margin: 8px 0; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 100;
  box-shadow: var(--shadow-hover);
}
.toast.error { background: var(--accent-dark); color: white; }

/* ---------- Catalog ---------- */

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar input[type="search"] {
  flex: 1;
  min-width: 200px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card-bg);
}
.toolbar select {
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card-bg);
}

.tag-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.chip {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: white; }

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

.item-card {
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
  display: flex;
  flex-direction: column;
}
.item-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }

.item-thumb {
  aspect-ratio: 1 / 1;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.item-thumb img { width: 100%; height: 100%; object-fit: cover; }
.item-thumb .placeholder { font-size: 13px; color: var(--text-muted); }

.item-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.item-title { font-weight: 700; font-size: 14px; line-height: 1.3; }
.item-creator { font-size: 12px; color: var(--text-muted); }
.item-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-muted);
}
.item-size { font-size: 11px; color: var(--text-muted); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }

/* ---------- Item detail ---------- */

.detail-layout { display: grid; grid-template-columns: 280px 1fr; gap: 28px; }
@media (max-width: 700px) { .detail-layout { grid-template-columns: 1fr; } }

.detail-thumb { border-radius: var(--radius); overflow: hidden; aspect-ratio: 1/1; background: var(--card-bg); border: 1px solid var(--border); }
.detail-thumb img { width: 100%; height: 100%; object-fit: cover; }

.detail-title { font-size: 24px; font-weight: 800; margin: 0 0 4px; }
.detail-creator { color: var(--text-muted); margin-bottom: 12px; }
.detail-tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.detail-desc { color: var(--text); line-height: 1.6; white-space: pre-wrap; margin: 14px 0; }

.file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  background: var(--card-bg);
}
.file-name { font-weight: 600; font-size: 14px; word-break: break-all; }
.file-size { font-size: 12px; color: var(--text-muted); }

/* ---------- Upload ---------- */

.match-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin: 14px 0; }
.match-card {
  display: flex;
  gap: 10px;
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  background: var(--card-bg);
}
.match-card.selected { border-color: var(--accent); }
.match-card img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.match-card .mtitle { font-size: 13px; font-weight: 700; line-height: 1.3; }
.match-card .mcreator { font-size: 12px; color: var(--text-muted); }
.match-card .mprice { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.progress-bar { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; margin-top: 10px; }
.progress-bar > div { height: 100%; background: var(--accent); width: 0%; transition: width 0.15s ease; }

/* ---------- Tables (admin/storage) ---------- */

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }

.quota-bar { height: 14px; border-radius: 999px; background: var(--border); overflow: hidden; margin: 10px 0 4px; }
.quota-bar > div { height: 100%; background: var(--accent); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin: 16px 0 28px; }
.stat-card { padding: 16px; }
.stat-value { font-size: 24px; font-weight: 800; }
.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }

.padded { padding: 18px 20px; }

.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
