/**
 * Mini CMS — Public styles
 * Includes: base layout, components, dark mode, gallery lightbox.
 */

/* ── CSS Variables (light mode defaults) ──────────────────── */
:root {
  --bg: #ffffff;
  --bg-surface: #f5f5f5;
  --bg-card: #ffffff;
  --text: #1a1a1a;
  --text-muted: #666666;
  --border: #dddddd;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .04);
  --shadow-hover: 0 4px 12px rgba(0, 0, 0, .12);
  --transition: .2s ease;
}

/* ── Dark mode (system) ───────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  body:not([data-theme="light"]) {
    --bg: #0f172a;
    --bg-surface: #1e293b;
    --bg-card: #1e293b;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #334155;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --shadow: 0 1px 3px rgba(0, 0, 0, .3);
    --shadow-hover: 0 4px 12px rgba(0, 0, 0, .4);
  }
}

/* ── Dark mode (forced via settings) ─────────────────────── */
body[data-theme="dark"] {
  --bg: #0f172a;
  --bg-surface: #1e293b;
  --bg-card: #1e293b;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #334155;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --shadow: 0 1px 3px rgba(0, 0, 0, .3);
  --shadow-hover: 0 4px 12px rgba(0, 0, 0, .4);
}

/* ── Reset & base ─────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  transition: background var(--transition), color var(--transition);
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

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

a:hover {
  text-decoration: underline;
}

/* ── Layout ───────────────────────────────────────────────── */
main {
  max-width: 960px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem;
}

header,
footer {
  padding: 1rem 2rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

footer {
  border-top: 1px solid var(--border);
  border-bottom: none;
  text-align: center;
}

header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
}

.tagline {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

footer p {
  margin: 0.25rem 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.logo {
  max-height: 48px;
  width: auto;
  margin-bottom: 0.5rem;
}

/* ── Blocks ───────────────────────────────────────────────── */
.block {
  margin: 2.5rem 0;
}

.block-text h1,
.block-text h2,
.block-text h3 {
  color: var(--text);
}

.block-hero h1 {
  font-size: clamp(1.75rem, 4vw, 2.75rem);
  margin-bottom: 0.75rem;
  line-height: 1.2;
}

.block-hero p {
  font-size: 1.15rem;
  color: var(--text-muted);
}

/* ── Cards ────────────────────────────────────────────────── */
.cards {
  display: grid;
  gap: 1.5rem;
}

.cards.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.cards.cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

@media (max-width: 768px) {

  .cards.cols-3,
  .cards.cols-2 {
    grid-template-columns: 1fr;
  }
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition), transform var(--transition);
  padding-bottom: 1rem;
}

.card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.card h3 {
  margin: 0.75rem 1rem 0.4rem;
  font-size: 1.05rem;
  color: var(--text);
}

.card p {
  margin: 0 1rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.card img {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
}

.card-image-placeholder,
.image-placeholder,
.gallery-placeholder {
  height: 140px;
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  border-radius: var(--radius) var(--radius) 0 0;
}

/* ── Table ────────────────────────────────────────────────── */
.block-table {
  /* drag-handle jaoks eemaldatud overflow: auto; vaata .table-responsive */
}

.table-responsive {
  overflow-x: auto;
  width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 0.8rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-weight: 600;
  background: var(--bg-surface);
  color: var(--text);
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}

td {
  color: var(--text);
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: var(--bg-surface);
}

td.highlight {
  font-weight: 600;
  color: var(--primary);
}

/* ── Gallery ──────────────────────────────────────────────── */
.gallery {
  display: grid;
  gap: 1rem;
}

.gallery.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.gallery.cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

@media (max-width: 768px) {
  .gallery.cols-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {

  .gallery.cols-3,
  .gallery.cols-2 {
    grid-template-columns: 1fr;
  }
}

.gallery figure {
  margin: 0;
  overflow: hidden;
  border-radius: var(--radius);
  cursor: pointer;
}

.gallery figure img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  transition: transform .3s ease;
}

.gallery figure:hover img {
  transform: scale(1.04);
}

.gallery figcaption {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  padding: 0 0.25rem;
}

/* ── Products ─────────────────────────────────────────────── */
.products {
  display: grid;
  gap: 1.5rem;
}

.products.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.products.cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

@media (max-width: 768px) {

  .products.cols-3,
  .products.cols-2 {
    grid-template-columns: 1fr;
  }
}

.product-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition), transform var(--transition);
}

.product-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.product-card img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
}

.product-image-placeholder {
  height: 160px;
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.product-info {
  padding: 1rem;
}

.product-info h3 {
  margin: 0 0 0.4rem;
  font-size: 1.05rem;
  color: var(--text);
}

.product-info p {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.product-price {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.2rem 0.65rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

.product-cta {
  display: inline-block;
  padding: 0.5rem 1.2rem;
  background: var(--primary);
  color: #fff !important;
  font-weight: 600;
  font-size: 0.875rem;
  border-radius: var(--radius);
  text-decoration: none !important;
  transition: background var(--transition), transform var(--transition);
}

.product-cta:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

/* ── Button block ─────────────────────────────────────────── */
.button-block {
  padding: 1rem 0;
}

.button-block.align-center {
  text-align: center;
}

.button-block.align-left {
  text-align: left;
}

.button-block.align-right {
  text-align: right;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0.75rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius);
  text-decoration: none !important;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), transform var(--transition), box-shadow var(--transition);
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff !important;
  border: 2px solid var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(37, 99, 235, .3);
}

.btn-outline {
  background: transparent;
  color: var(--primary) !important;
  border: 2px solid var(--primary);
}

.btn-outline:hover {
  background: var(--primary);
  color: #fff !important;
}

.btn-ghost {
  background: transparent;
  color: var(--text) !important;
  border: 2px solid transparent;
}

.btn-ghost:hover {
  background: var(--bg-surface);
}

.btn-icon {
  font-size: 1.1em;
}

/* ── Split layout ─────────────────────────────────────────── */
.split-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  align-items: center;
}

.split-layout.img-right .split-image {
  order: 2;
}

.split-layout.img-right .split-text {
  order: 1;
}

.split-image img {
  width: 100%;
  border-radius: var(--radius);
  object-fit: cover;
}

.split-text h1,
.split-text h2,
.split-text h3 {
  margin-top: 0;
  color: var(--text);
}

.split-text p {
  color: var(--text-muted);
  line-height: 1.7;
}

@media (max-width: 768px) {
  .split-layout {
    grid-template-columns: 1fr;
  }

  .split-layout.img-right .split-image {
    order: 1;
  }

  .split-layout.img-right .split-text {
    order: 2;
  }
}

/* ── Contact form ─────────────────────────────────────────── */
.contact-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 480px;
}

.contact-form input,
.contact-form textarea {
  padding: 0.65rem 0.9rem;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.contact-form input:focus,
.contact-form textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

.contact-form textarea {
  min-height: 130px;
  resize: vertical;
}

.contact-form button {
  align-self: flex-start;
  padding: 0.65rem 1.5rem;
  font-size: 1rem;
  font-family: inherit;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  transition: background var(--transition), transform var(--transition);
}

.contact-form button:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.contact-form button:active {
  transform: none;
}

/* ── Edit mode toggle button ──────────────────────────────── */
.mcms-edit-toggle {
  position: fixed;
  top: 12px;
  right: 14px;
  z-index: 9000;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(128, 128, 128, .15);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .2s ease, background .2s ease, color .2s ease;
  text-decoration: none;
}

.mcms-edit-toggle:hover {
  opacity: 1 !important;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
}

body:hover .mcms-edit-toggle {
  opacity: .35;
}

/* ── Gallery lightbox (public + edit mode) ────────────────── */
.mcms-lightbox {
  position: fixed;
  inset: 0;
  z-index: 10010;
  background: rgba(0, 0, 0, .92);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity .25s ease, visibility .25s ease;
}

.mcms-lightbox.mcms-open {
  opacity: 1;
  visibility: visible;
}

.mcms-lightbox img {
  max-width: 90vw;
  max-height: 88vh;
  object-fit: contain;
  border-radius: 4px;
  user-select: none;
  -webkit-user-select: none;
}

.mcms-lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255, 255, 255, .15);
  border: none;
  color: #fff;
  font-size: 1.5rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease;
}

.mcms-lightbox-close:hover {
  background: rgba(255, 255, 255, .28);
}

.mcms-lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, .1);
  border: none;
  color: #fff;
  font-size: 1.8rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease;
}

.mcms-lightbox-nav:hover {
  background: rgba(255, 255, 255, .25);
}

.mcms-lightbox-prev {
  left: 16px;
}

.mcms-lightbox-next {
  right: 16px;
}

.mcms-lightbox-counter {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, .7);
  font-size: .85rem;
}

@media (max-width: 480px) {
  .mcms-lightbox-nav {
    width: 40px;
    height: 40px;
    font-size: 1.4rem;
  }

  .mcms-lightbox-prev {
    left: 8px;
  }

  .mcms-lightbox-next {
    right: 8px;
  }
}