:root {
  --bg: #f1f5f9;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-contrast: #ffffff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --shadow-lg: 0 20px 50px -24px rgba(15, 23, 42, 0.12);
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --content-max: 1240px;
}

* {
  box-sizing: border-box;
}

html,
body {
  color-scheme: light;
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 800px at 80% -10%, rgba(191, 219, 254, 0.65) 0%, transparent 60%),
    radial-gradient(900px 600px at -10% 110%, rgba(221, 214, 254, 0.5) 0%, transparent 55%), var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica,
    Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  color: var(--primary-hover);
}

.muted {
  color: var(--text-muted);
  margin: 0;
}

.container {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* ---------- Dashboard (full viewport, 3-column grid) ---------- */
body.page-dashboard {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

body.page-dashboard .topbar-inner {
  max-width: none;
}

body.page-dashboard .container {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 20px 24px 28px;
  min-height: 0;
}

body.page-dashboard .container:not(:has(#emptyState:not([hidden]))) > #cards {
  flex: 1;
  min-height: 0;
}

body.page-dashboard .container:has(#emptyState:not([hidden])) > #emptyState {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin: 0;
}

body.page-dashboard .cards-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
  align-content: start;
}

@media (max-width: 960px) {
  body.page-dashboard .cards-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  body.page-dashboard .cards-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(14px);
  background: rgba(255, 255, 255, 0.72);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.2px;
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: conic-gradient(from 210deg, #6aa8ff, #b07cff, #ff7ec2, #6aa8ff);
  box-shadow: 0 6px 22px -8px rgba(37, 99, 235, 0.35);
}
.brand-tag {
  margin-left: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary);
}
.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  color: var(--text);
  transition: background 120ms ease, border-color 120ms ease,
    color 120ms ease, transform 60ms ease;
  font-family: inherit;
  white-space: nowrap;
}
.btn:active {
  transform: translateY(1px);
}
.btn-primary {
  background: var(--primary);
  color: var(--primary-contrast);
  border-color: var(--primary);
  font-weight: 600;
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-ghost:hover {
  background: rgba(15, 23, 42, 0.04);
  border-color: var(--border-strong);
}
.btn-danger {
  background: transparent;
  border-color: rgba(220, 38, 38, 0.35);
  color: var(--danger);
}
.btn-danger:hover {
  background: rgba(220, 38, 38, 0.08);
  border-color: var(--danger);
  color: var(--danger-hover);
}
.btn-block {
  width: 100%;
}
.btn-sm {
  padding: 5px 10px;
  font-size: 0.82rem;
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ---------- Dashboard cards ---------- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 22px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: transform 200ms ease, border-color 200ms ease,
    box-shadow 200ms ease, background 200ms ease;
  box-shadow: var(--shadow-lg);
}
.card:hover {
  transform: translateY(-4px);
  border-color: var(--border-strong);
  background: var(--bg-card-hover);
}
.card:hover .card-media {
  background: var(--bg-card-hover);
}

.card-head {
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.card-media {
  position: relative;
  aspect-ratio: 16 / 10;
  background: var(--bg-card);
  overflow: hidden;
}
.card-media img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  opacity: 0;
  transition: opacity 700ms ease;
}
.card-media img.is-active {
  opacity: 1;
}
.card-media .card-media-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(15, 23, 42, 0.35);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.card-dots {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  z-index: 2;
}
.card-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.22);
  transition: background 200ms ease, transform 200ms ease, box-shadow 200ms ease;
}
.card-dots span.is-active {
  background: var(--primary);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.95);
  transform: scale(1.2);
}

.card-body {
  padding: 14px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.2px;
  margin: 0;
}
.card-desc {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.88rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-url {
  margin-top: 8px;
  color: var(--text-dim);
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-body > .card-url:first-child {
  margin-top: 0;
}

/* ---------- Empty state ---------- */
.empty-state {
  margin: 80px auto;
  max-width: 460px;
  padding: 40px 28px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: rgba(15, 23, 42, 0.02);
  text-align: center;
}
.empty-state h2 {
  margin: 0 0 8px;
  font-size: 1.25rem;
}
.empty-state p {
  margin: 0 0 18px;
  color: var(--text-muted);
}
.empty-inline {
  margin: 12px 0 0;
  padding: 24px;
}

/* ---------- Login ---------- */
.page-login {
  display: flex;
}
.auth-shell {
  min-height: 100vh;
  width: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}
.auth-sub {
  margin: 0 0 4px;
  color: var(--text-muted);
  font-size: 0.92rem;
}
.auth-link {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.auth-link:hover {
  color: var(--text);
}

/* ---------- Forms ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}
input[type='text'],
input[type='url'],
input[type='password'],
textarea {
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
  width: 100%;
}
input:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}
input::placeholder {
  color: var(--text-dim);
}

.alert {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}
.alert-error {
  background: rgba(220, 38, 38, 0.08);
  border: 1px solid rgba(220, 38, 38, 0.28);
  color: var(--danger-hover);
}

/* ---------- Admin layout ---------- */
.admin-layout {
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-lg);
}
.panel-head {
  margin-bottom: 16px;
}
.panel-head h2 {
  margin: 0;
  font-size: 1.1rem;
}
.panel-head .muted {
  margin-top: 4px;
  font-size: 0.88rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: end;
}
.form-grid .field-wide {
  grid-column: 1 / -1;
}
.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}
@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- Admin cards ---------- */
.admin-cards {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.admin-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  padding: 18px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
@media (min-width: 820px) {
  .admin-card {
    grid-template-columns: 1.2fr 1fr;
  }
}
.admin-card-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}
.admin-card-head h3 {
  margin: 0;
  font-size: 1.02rem;
}
.admin-card-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.admin-card-fields .row {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 10px;
  align-items: center;
}
.admin-card-fields .row label {
  color: var(--text-muted);
  font-size: 0.85rem;
}
.admin-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.admin-images {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}
.image-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #e8edf5;
}
.image-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.image-tile button {
  position: absolute;
  top: 4px;
  right: 4px;
  border: none;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: background 120ms ease;
}
.image-tile button:hover {
  background: var(--danger);
  color: #ffffff;
  box-shadow: none;
}

.image-upload {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.image-upload-zone {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}
.image-upload-zone:hover,
.image-upload-zone.is-dragging {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.06);
  color: var(--text);
}
.image-upload-zone input {
  display: none;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 200ms ease, transform 200ms ease;
  pointer-events: none;
  z-index: 30;
}
.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.is-error {
  border-color: rgba(220, 38, 38, 0.35);
  color: var(--danger-hover);
}
