:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e4e4e7;
  --text: #18181b;
  --muted: #71717a;
  --primary: #dc2626;
  --primary-text: #ffffff;
  --danger: #b91c1c;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0d;
    --surface: #151518;
    --border: #2a2a30;
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

#app { min-height: 100vh; }
.boot {
  display: grid;
  place-items: center;
  min-height: 100vh;
  color: var(--muted);
}

/* ---------- Auth ---------- */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 0.25rem; font-size: 1.25rem; }
.auth-card p { margin: 0 0 1.5rem; }

/* ---------- Shell (sidebar + main) ---------- */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand {
  display: block;
  text-decoration: none;
  color: inherit;
  padding: 0.25rem 0.5rem;
  margin-bottom: 1rem;
}
.sidebar .brand img {
  display: block;
  width: 180px;
  max-width: 100%;
  height: auto;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.nav-btn {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}
.nav-btn:hover { background: var(--bg); color: var(--text); }
.nav-btn.active { background: var(--bg); color: var(--text); font-weight: 500; }

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.sidebar-foot .user-label {
  color: var(--muted);
  font-size: 12px;
  padding: 0 0.5rem 0.25rem;
}
.sidebar-foot button {
  text-align: left;
  padding: 0.5rem 0.75rem;
  background: transparent;
  border: none;
  color: var(--muted);
  border-radius: 6px;
  font: inherit;
}
.sidebar-foot button:hover { background: var(--bg); color: var(--text); }

.auth-logo {
  display: block;
  width: 220px;
  max-width: 100%;
  height: auto;
  margin: 0 auto 1.5rem;
}

@media (prefers-color-scheme: dark) {
  .sidebar .brand img,
  .auth-logo {
    filter: brightness(1.4) contrast(1.05);
  }
}

@media (max-width: 720px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 1rem 1rem 0.75rem;
  }
  .sidebar .brand img { width: 140px; }
  .sidebar-foot {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
  }
  .sidebar-foot .user-label { padding: 0; }
}

/* ---------- Panels ---------- */
main { padding: 1.5rem; max-width: 1200px; margin: 0 auto; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.panel-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 1rem; font-weight: 600; }
.filters {
  margin-left: auto;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ---------- View toggle ---------- */
.view-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.view-toggle button {
  padding: 0.4rem 0.55rem;
  border: none;
  border-radius: 0;
  color: var(--muted);
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.view-toggle button + button { border-left: 1px solid var(--border); }
.view-toggle button:hover { background: var(--bg); color: var(--text); }
.view-toggle button.active { background: var(--bg); color: var(--text); }

/* ---------- List (cards) ---------- */
.list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  padding: 1.25rem;
}
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
}
.card:hover { border-color: var(--muted); transform: translateY(-1px); }
.card .thumb {
  aspect-ratio: 4 / 3;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.75rem;
  display: grid;
  place-items: center;
  color: var(--muted);
  overflow: hidden;
}
.card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.card h3 { margin: 0 0 0.25rem; font-size: 0.95rem; }
.card .meta { color: var(--muted); font-size: 12px; display: flex; gap: 0.5rem; flex-wrap: wrap; }
.card .meta .badge {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
}
.empty {
  padding: 3rem;
  text-align: center;
  color: var(--muted);
}

/* ---------- List (table/rows view) ---------- */
.sponsorships-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.sponsorships-table thead th {
  text-align: left;
  padding: 0.6rem 1rem;
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 1;
}
.sponsorships-table tbody tr {
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.sponsorships-table tbody tr:hover { background: var(--bg); }
.sponsorships-table tbody tr:last-child { border-bottom: none; }
.sponsorships-table td {
  padding: 0.6rem 1rem;
  vertical-align: middle;
}
.sponsorships-table td.name { font-weight: 500; }
.sponsorships-table td.name .thumb-sm {
  display: inline-block;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  background: var(--border);
  margin-right: 0.5rem;
  vertical-align: middle;
  overflow: hidden;
}
.sponsorships-table td.name .thumb-sm img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.sponsorships-table td.products {
  color: var(--muted);
  max-width: 340px;
}
.type-pill {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  text-transform: capitalize;
}
.sponsorships-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

/* ---------- Table ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left;
  padding: 0.65rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.table th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.table tr:last-child td { border-bottom: none; }
.table .actions { display: flex; gap: 0.25rem; justify-content: flex-end; }
.role-badge {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.role-badge.admin { background: var(--primary); color: var(--primary-text); border-color: transparent; }

/* ---------- Form elements ---------- */
label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
  font-size: 13px;
}
label span { color: var(--muted); }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; font-family: inherit; }

button {
  font: inherit;
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
}
button:hover { background: var(--bg); }
button.primary {
  background: var(--primary);
  color: var(--primary-text);
  border-color: transparent;
}
button.primary:hover { filter: brightness(1.1); }
button.danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
button.danger:hover { background: var(--danger); color: #fff; }
button.ghost { background: transparent; border-style: dashed; color: var(--muted); }
button.icon {
  width: 28px; height: 28px; padding: 0;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  background: transparent;
}
button.icon:hover { color: var(--text); }

.err {
  background: rgba(220, 38, 38, 0.1);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 13px;
  margin: 0.75rem 0;
}
.muted { color: var(--muted); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 100;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
}
.modal-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.modal-card h3 { margin: 0; font-size: 1.05rem; }
.modal-card footer {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.modal-card .spacer { flex: 1; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}
.grid-2 .span-2 { grid-column: span 2; }
@media (max-width: 500px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-2 .span-2 { grid-column: span 1; }
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin: 1rem 0;
}
fieldset legend { padding: 0 0.5rem; color: var(--muted); font-size: 12px; }

.products .product-row {
  display: grid;
  grid-template-columns: 1fr 2fr auto;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.products .product-row input { margin: 0; }

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.media-tile {
  position: relative;
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg);
}
.media-tile img { width: 100%; height: 100%; object-fit: cover; }
.media-tile button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border: none;
  font-size: 14px;
  line-height: 1;
}

label.file {
  display: inline-block;
  padding: 0.5rem 0.85rem;
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
}
label.file input { display: none; }

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  z-index: 200;
  max-width: 360px;
}
.toast.success { border-left: 3px solid #16a34a; }
.toast.error { border-left: 3px solid var(--danger); }

[hidden] { display: none !important; }
