:root{
  /* theme variables are defined in theme-default.css */
  --radius:18px;
  --shadow: 0 10px 30px rgba(0,0,0,.10);
  --max: 1100px;

  --tile-img-radius: 14px;
  --tile-img-aspect: 16 / 9; /* can be overridden by theme */
  --ad-img-aspect: 16 / 6;
}

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

/* =========================================================
   Top Bar
   ========================================================= */
.appbar{
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--appbar-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.appbar__inner{
  max-width: var(--max);
  margin: 0 auto;
  padding: 12px 14px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 12px;
}
.brand{
  color: var(--text);
  text-decoration:none;
  font-weight: 900;
  letter-spacing:.4px;
}
.appnav{ display:flex; gap: 10px; }
.appnav a{
  color: var(--muted);
  text-decoration:none;
  padding: 8px 10px;
  border-radius: 12px;
}
.appnav a.active, .appnav a:hover{
  color: var(--text);
  background: var(--hover);
}

.wrap{
  max-width: var(--max);
  margin: 0 auto;
  padding: 14px;
}

/* =========================================================
   Tiles grid (FLUID / AUTO-FIT)
   PURPOSE:
     - Grid is not fixed to 2/3/4 columns.
     - It automatically fits as many columns as possible based on min width.
     - Supports full-row and wide items via span classes.
   SAFE TO REPLACE: YES
   ========================================================= */

.grid{
  display:grid;
  gap: 12px;
  align-items: start;

  /* ✅ Fluid: pack as many columns as will fit.
     350px matches your “ad block ~350px” goal. */
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));

  /* ✅ Helps pack around wide/full items when spans exist */
  grid-auto-flow: dense;
}

/* Full row item */
.grid .span-full{ grid-column: 1 / -1; }

/* Wide item */
.grid .span-2{ grid-column: span 2; }

/* Mobile safety */
@media (max-width: 380px){
  .grid{ grid-template-columns: 1fr; }
}


/* =========================================================
   Day-2 Layout Enhancement: Tile spans (admin-controlled)
   PURPOSE:
   - Allow a tile to take up more "slots" in the grid.
   - Used when admin sets page_layout_items.grid_span.
   EXPECTED CLASSES:
   - .span-2 => spans 2 columns (tablet/desktop)
   - .span-4 => spans full row (desktop/tablet)
   SAFETY:
   - On mobile (1-column), spans must NOT force weird behavior
   ========================================================= */
.grid .span-2{ grid-column: span 2; }
.grid .span-4{ grid-column: 1 / -1; }

/* Guard rails: on narrow screens, ignore spans and stack normally */
@media (max-width: 719px){
  .grid .span-2,
  .grid .span-4{
    grid-column: auto;
  }
}

.tile{
  display:flex;
  flex-direction: column;
  text-decoration:none;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow:hidden;
  background: var(--card);
  box-shadow: var(--shadow);
}

.tile__media{
  width: 100%;
  aspect-ratio: var(--tile-img-aspect);
  background: var(--media-bg);
  display:flex;
  align-items:center;
  justify-content:center;
}

.tile__img{
  width: 100%;
  height: 100%;
  object-fit: cover;   /* looks clean for tiles */
  display:block;
}

.tile__ph{
  width:100%;
  height:100%;
  background: var(--media-bg);
}

.tile__meta{
  padding: 10px 12px 12px;
}
.tile__title{
  font-weight: 900;
  font-size: 14px;
  line-height: 1.25;
}
.tile__sub{
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

/* =========================================================
   Full-width blocks (modules)
   NOTE:
   - Modules are rendered between tile grids as full-width blocks.
   - If you later want modules to behave like tiles, that will be a
     renderer + admin option (not CSS-only).
   ========================================================= */
.block{
  margin: 14px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.block__title{
  font-weight: 900;
  margin-bottom: 10px;
}

/* =========================================================
   Lists
   ========================================================= */
.list{
  display:flex;
  flex-direction: column;
  gap: 10px;
}
.list__item{
  text-decoration:none;
  color: var(--text);
  padding: 10px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card2);
}
.list__item:hover{
  background: var(--hover);
}
.list__title{
  font-weight: 800;
  font-size: 14px;
}

/* =========================================================
   Ads
   ========================================================= */
.adgrid{
  display:grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
@media (min-width: 720px){
  .adgrid{ grid-template-columns: 1fr 1fr; }
}

.adcard__media{
  width:100%;
  aspect-ratio: var(--ad-img-aspect);
  max-height: 120px;            /* ✅ caps banner height */
  background: var(--media-bg);
  display:flex;
  align-items:center;
  justify-content:center;
}

.adcard__img{
  max-width: 100%;
  max-height: 120px;            /* ✅ matches cap */
  width: auto;
  height: auto;
  object-fit: contain;
  display:block;
}

.adcard__ph{
  height: 140px;
  display:flex;
  align-items:center;
  justify-content:center;
  color: var(--muted);
}
.adcard__label{
  padding: 10px;
  color: var(--muted);
  font-size: 12px;
}

/* =========================================================
   Article
   ========================================================= */
.article{
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.article__title{ margin: 6px 0 12px; font-size: 20px; }
.article__body img{ max-width:100%; height:auto; }

/* =========================================================
   Empty
   ========================================================= */
.empty{ color: var(--muted); padding: 16px 0; }

/* =========================================================
   Modal
   ========================================================= */
.modal{ position: fixed; inset: 0; display: none; z-index: 100; }
.modal.is-open{ display: block; }
.modal__backdrop{ position:absolute; inset:0; background: rgba(0,0,0,.55); }
.modal__panel{
  position:absolute;
  left: 50%; top: 50%;
  transform: translate(-50%,-50%);
  width: min(960px, 94vw);
  height: min(720px, 86vh);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow:hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
  display:flex;
  flex-direction: column;
}
.modal__bar{
  display:flex;
  justify-content:flex-end;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.modal__btn{
  border: 1px solid var(--line);
  background: var(--card2);
  color: var(--text);
  border-radius: 12px;
  padding: 8px 10px;
  cursor:pointer;
  font-weight: 800;
}
.modal__btn:hover{ background: var(--hover); }
.modal__frame{
  flex:1;
  width:100%;
  border:0;
  background: #fff;
}

/* =========================================================
   BRANDING (logo + tagline)
   NOTE:
   - Public header loads these fields from DB site_settings.
   - If logo URL is blank, the <img> element is not rendered.
   ========================================================= */
.brand{
  display:flex;
  align-items:center;
  gap: 10px;
}

.brand__logo{
  width: 34px;
  height: 34px;
  border-radius: 10px;
  object-fit: contain;
  background: var(--card2);
  border: 1px solid var(--line);
}

.brand__text{
  display:flex;
  flex-direction: column;
  line-height: 1.05;
}

.brand__name{
  font-weight: 900;
  letter-spacing: .4px;
}

.brand__tagline{
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
}

/* =========================================================
   TABLET FRAME WRAPPER (Day 2)
   PURPOSE:
   - Mobile-first: no heavy bezel
   - Tablet/Desktop: framed "tablet" look
   ========================================================= */
.tablet{
  max-width: var(--max);
  margin: 0 auto;
}

.tablet__inner{
  background: transparent;
}

/* Tablet frame turns on at tablet breakpoint */
@media (min-width: 720px){
  .tablet{
    padding: 14px;
    border-radius: calc(var(--radius) + 10px);
    border: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.03));
    box-shadow: var(--shadow);
  }
  .tablet__inner{
    border-radius: var(--radius);
    border: 1px solid var(--line);
    overflow: hidden;
    background: transparent; /* keeps your theme bg behavior */
  }
}

/* =========================================================
   Site Footer (DB-driven)
   NOTE:
   - Footer content is stored in site_settings:
       footer_html (HTML)
       footer_small_print (text)
   - footer_html is printed as HTML (admin-controlled)
   ========================================================= */
.site-footer{
  max-width: var(--max);
  margin: 14px auto 20px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.site-footer__html a{
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.site-footer__small{
  margin-top: 8px;
  opacity: 0.9;
}
