/* market.beaver.supply — base component styles.
   Grid area assignments + reusable components.
   Theme-specific layout and colors come from themes.css (loaded before this file). */

/* ── reset / box-sizing ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; }

/* ── grid area assignments ───────────────────────────────── */
.site-header  { grid-area: header; }
.site-content { grid-area: content; }
.site-footer  { grid-area: footer; }

/* ── body ────────────────────────────────────────────────── */
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 1rem 2rem;
  line-height: 1.6;
}

/* subtle background texture so glass elements have depth */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse at 20% 0%, var(--gradient-start) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, var(--gradient-end) 0%, transparent 50%);
  opacity: .1;
  pointer-events: none;
}

/* ── headings / display type ────────────────────────────── */
h1, h2, h3 { line-height: 1.2; font-family: var(--display-font, var(--font)); }
h1 {
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 700;
  letter-spacing: -.02em;
}
h2 {
  font-size: clamp(1.4rem, 3vw, 2.2rem);
  font-weight: 700;
  letter-spacing: -.01em;
}
h3 { font-size: clamp(1.1rem, 2vw, 1.5rem); font-weight: 600; }

/* ── links ──────────────────────────────────────────────── */
a { color: var(--accent); text-decoration: none; transition: color .15s; }
a:hover { color: var(--accent-hover); }

/* ── header / nav ───────────────────────────────────────── */
.site-header {
  background: var(--header-bg);
  color: var(--header-text);
  margin: 0 -1rem 1.5rem;
  padding: .65rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
}
/* glass enhancement when supported */
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .site-header {
    -webkit-backdrop-filter: blur(10px) saturate(160%);
    backdrop-filter: blur(10px) saturate(160%);
  }
}
.site-header nav {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem .9rem;
  align-items: center;
}
.site-header nav a { color: var(--header-text); }
.site-header nav a:hover { opacity: .8; }
.site-header .greeting { opacity: .7; font-size: .85rem; }
.site-header .logout-form { display: inline; }
.site-header button {
  background: transparent;
  border: 1px solid currentColor;
  color: var(--header-text);
  padding: .15rem .65rem;
}

/* ── theme picker (dropdown) ────────────────────────────── */
.theme-picker {
  margin-left: auto;
  display: flex;
  gap: .4rem;
  align-items: center;
  font-size: .82rem;
}
.theme-picker select {
  appearance: none;
  background: rgba(255, 255, 255, .12);
  color: var(--header-text);
  border: 1px solid rgba(255, 255, 255, .25);
  border-radius: 1rem;
  padding: .2rem 1.6rem .2rem .6rem;
  font: inherit;
  font-size: .82rem;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23fff' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .45rem center;
}
.theme-picker select:hover { background-color: rgba(255, 255, 255, .18); }
.theme-picker select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ── card ───────────────────────────────────────────────── */
.card {
  background: var(--glass-bg, var(--surface));
  border: 1px solid var(--glass-border, var(--border));
  border-radius: var(--radius-lg, var(--radius));
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  transition: transform .2s, box-shadow .2s;
  overflow: hidden;
}
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .card {
    -webkit-backdrop-filter: blur(12px) saturate(160%);
    backdrop-filter: blur(12px) saturate(160%);
  }
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* ── badge ──────────────────────────────────────────────── */
.badge {
  display: inline-block;
  background: var(--badge-bg);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: .1rem .65rem;
  margin: .1rem;
  font-size: .82rem;
}

/* ── notice ─────────────────────────────────────────────── */
.notice {
  background: var(--notice-bg);
  border: 1px solid var(--notice-border);
  padding: .75rem 1rem;
  border-radius: var(--radius);
}

/* ── error text ─────────────────────────────────────────── */
.error { color: var(--error); }

/* ── footer ─────────────────────────────────────────────── */
.site-footer {
  color: var(--footer-text);
  font-size: .82rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

/* ── buttons ────────────────────────────────────────────── */
button, .btn {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: var(--radius);
  padding: .55rem 1.1rem;
  cursor: pointer;
  font: inherit;
  text-decoration: none;
  display: inline-block;
  transition: transform .15s, box-shadow .15s, background .15s;
}
button:hover, .btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
button:active, .btn:active { transform: translateY(0); }

/* ── forms ──────────────────────────────────────────────── */
.field { margin: .65rem 0; }
.field label { display: block; font-weight: 600; margin-bottom: .25rem; }
.field input, .field select, .field textarea {
  width: 100%;
  max-width: 520px;
  padding: .5rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, .06);
}
.field small { color: var(--muted); }

/* ── tables ─────────────────────────────────────────────── */
table { border-collapse: collapse; width: 100%; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
td, th { border: 1px solid var(--border); padding: .5rem .65rem; text-align: left; }
th { background: var(--badge-bg); font-weight: 600; }

/* ── flash messages ─────────────────────────────────────── */
.messages { padding: 0; }
.messages li {
  list-style: none;
  margin: .5rem 0;
  padding: .6rem .9rem;
  border-radius: var(--radius);
}
.messages .success { background: var(--success-bg); }
.messages .error { background: var(--error-bg); }

/* ── photos / gallery ───────────────────────────────────── */
.card-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius);
  display: block;
  margin-bottom: .5rem;
  background: var(--badge-bg);
}
.gallery { margin: 1rem 0; }
.gallery #gallery-main {
  width: 100%;
  max-height: 520px;
  object-fit: contain;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.gallery-thumbs { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.gallery-thumb {
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 0;
  background: none;
  cursor: pointer;
}
.gallery-thumb img {
  width: 72px; height: 72px; object-fit: cover;
  border-radius: calc(var(--radius) - 2px);
  display: block;
}
.gallery-thumb.active { border-color: var(--accent); }
.label-img { max-width: 100%; border: 1px solid var(--border); border-radius: var(--radius); }
.photo-row { display: flex; gap: 1rem; align-items: flex-start; }
.photo-thumb { width: 120px; height: 90px; object-fit: cover; border-radius: var(--radius); }
.photo-row input[name="alt_text"] {
  max-width: 320px;
  padding: .3rem .5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
}

/* ── message thread ─────────────────────────────────────── */
.thread { display: flex; flex-direction: column; gap: .5rem; margin: 1rem 0; }
.msg {
  border: 1px solid var(--border);
  background: var(--glass-bg, var(--surface));
  border-radius: var(--radius);
  padding: .5rem .8rem;
  max-width: 85%;
}
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .msg {
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }
}
.msg.mine { align-self: flex-end; background: var(--badge-bg); }
.msg p { margin: .3rem 0 0; }

/* ── scroll reveal ──────────────────────────────────────── */
[data-reveal] {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity .5s ease, transform .5s ease;
}
[data-reveal].in-view {
  opacity: 1;
  transform: translateY(0);
}
@media (prefers-reduced-motion: reduce) {
  [data-reveal] {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

/* ── responsive ─────────────────────────────────────────── */
@media (max-width: 639px) {
  .site-header nav { gap: .25rem .6rem; }
  .theme-picker {
    margin-left: 0;
    width: 100%;
    margin-top: .3rem;
  }
  table { font-size: .88rem; }
  /* Sidebar theme: collapse to top header on mobile */
  html[data-theme="sidebar"] .page {
    grid-template-columns: 1fr;
    grid-template-areas: "header" "content" "footer";
  }
  html[data-theme="sidebar"] .site-header {
    position: relative;
    height: auto;
    flex-direction: row;
  }
  html[data-theme="sidebar"] .site-header nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
  html[data-theme="sidebar"] .site-header nav a {
    padding: .4rem .75rem;
  }
  html[data-theme="sidebar"] .site-header nav a::before {
    display: none;
  }
  /* Horizon: reduce hero height on mobile */
  html[data-theme="horizon"] .page {
    grid-template-rows: 50vh 1fr auto;
  }
  /* Magazine: single column cards on mobile */
  html[data-theme="magazine"] .site-content .grid:first-of-type .card:first-child {
    grid-column: 1 / -1;
    grid-template-columns: 1fr;
    min-height: auto;
  }
  html[data-theme="magazine"] .site-content .grid:first-of-type .card:not(:first-child) {
    grid-column: 1 / -1;
  }
  html[data-theme="magazine"] .site-content .grid:not(:first-of-type) {
    grid-template-columns: 1fr;
  }
}