/**
 * Digital Signage - base structural CSS
 * -----------------------------------------------------------------------
 * This file controls LAYOUT and BEHAVIOR only. All look-and-feel
 * (colors, fonts, logos, backgrounds) is driven by CSS custom properties
 * that a per-client theme.css file sets. Do not hardcode colors here -
 * add a new --signage-* variable instead so themes can override it.
 *
 * Variable contract (set these in a client's theme.css):
 *   --signage-bg               page background color
 *   --signage-bg-image         optional page background image (e.g. url(...))
 *   --signage-fg               primary text color
 *   --signage-muted            secondary text color (times, hints)
 *   --signage-accent           accent color (current-item highlight, header)
 *   --signage-accent-fg        text color used on top of --signage-accent
 *   --signage-item-bg          background of each schedule row
 *   --signage-item-bg-now      background of the row currently happening
 *   --signage-divider          divider/border color
 *   --signage-radius           corner radius used throughout
 *   --signage-font-family      body font
 *   --signage-heading-font-family  heading/title font (falls back to body)
 *   --signage-logo-url         optional url(...) shown in the header
 */

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--signage-bg, #0b0f19) var(--signage-bg-image, none) center / cover no-repeat fixed;
  color: var(--signage-fg, #f5f6fa);
  font-family: var(--signage-font-family, "Segoe UI", Roboto, Arial, sans-serif);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------------------------------------------------------------------
 * Location picker (index.html)
 * ------------------------------------------------------------------- */

.picker-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4vh 4vw;
  text-align: center;
}

.picker-title {
  font-family: var(--signage-heading-font-family, var(--signage-font-family, inherit));
  font-size: clamp(2rem, 5vw, 3.5rem);
  margin: 0 0 0.5em;
}

.picker-subtitle {
  color: var(--signage-muted, #9aa2b1);
  margin: 0 0 2em;
  font-size: clamp(1rem, 2vw, 1.25rem);
}

.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  width: 100%;
  max-width: 1100px;
  list-style: none;
  padding: 0;
  margin: 0;
}

.picker-card {
  display: block;
  padding: 1.75rem 1.25rem;
  background: var(--signage-item-bg, rgba(255,255,255,0.06));
  border: 1px solid var(--signage-divider, rgba(255,255,255,0.12));
  border-radius: var(--signage-radius, 12px);
  color: inherit;
  text-decoration: none;
  font-size: 1.25rem;
  font-weight: 600;
  transition: transform 0.15s ease, background 0.15s ease;
}

.picker-card:hover,
.picker-card:focus-visible {
  transform: translateY(-2px);
  background: var(--signage-accent, #4f6df5);
  color: var(--signage-accent-fg, #ffffff);
}

.picker-card-sub {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--signage-muted, #9aa2b1);
}

/* ---------------------------------------------------------------------
 * Room page
 * ------------------------------------------------------------------- */

.room-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 3vh 4vw;
}

.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 3vh;
}

.room-header-logo {
  width: 3rem;
  height: 3rem;
  background: var(--signage-logo-url, none) center / contain no-repeat;
}

.room-name {
  font-family: var(--signage-heading-font-family, var(--signage-font-family, inherit));
  font-size: clamp(1.5rem, 3.5vw, 2.75rem);
  margin: 0;
  flex: 1;
}

.room-clock {
  text-align: right;
  line-height: 1.2;
}

.room-clock-time {
  font-size: clamp(1.5rem, 3vw, 2.25rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.room-clock-date {
  color: var(--signage-muted, #9aa2b1);
  font-size: clamp(0.9rem, 1.5vw, 1.1rem);
}

.schedule-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow: hidden;
}

.schedule-item {
  display: flex;
  align-items: baseline;
  gap: 1.25rem;
  background: var(--signage-item-bg, rgba(255,255,255,0.05));
  border: 1px solid var(--signage-divider, rgba(255,255,255,0.1));
  border-radius: var(--signage-radius, 12px);
  padding: 1rem 1.5rem;
  transition: transform 0.4s ease, opacity 0.4s ease, background 0.4s ease,
    max-height 0.5s ease, padding 0.5s ease, margin 0.5s ease;
  max-height: 220px;
  overflow: hidden;
  /* Flex items shrink below their content's natural height by default. In a
   * column of many rows that's exactly the wrong behavior here: it silently
   * squishes every row (clipping title/description text via the overflow:
   * hidden above) instead of leaving rows full-size and letting the ones
   * that don't fit be hidden outright by trimOverflowingItems() in app.js.
   * This is what caused descriptions to disappear specifically on shorter
   * screens (1920x1080) while looking fine on taller ones. */
  flex-shrink: 0;
}

.schedule-item.is-now {
  background: var(--signage-item-bg-now, var(--signage-accent, #4f6df5));
  color: var(--signage-accent-fg, #ffffff);
  border-color: transparent;
}

.schedule-item-time {
  flex: 0 0 auto;
  min-width: 6.5em;
  font-size: clamp(1rem, 1.6vw, 1.4rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--signage-muted, #9aa2b1);
}

.schedule-item.is-now .schedule-item-time {
  color: inherit;
}

.schedule-item-title {
  font-size: clamp(1.1rem, 2vw, 1.6rem);
  font-weight: 600;
}

.schedule-item-details {
  margin-top: 0.15rem;
  color: var(--signage-muted, #9aa2b1);
  font-size: clamp(0.9rem, 1.3vw, 1.1rem);
}

.schedule-item.is-now .schedule-item-details {
  color: inherit;
  opacity: 0.85;
}

/* entering / leaving animation states */
.schedule-item.is-entering {
  opacity: 0;
  transform: translateY(16px);
}

/* An item that doesn't fully fit in the space available on this screen -
 * hidden rather than clipped through the middle. It reappears on its own
 * once earlier items fall off and free up room. */
.schedule-item.is-overflow-hidden {
  display: none;
}

.schedule-item.is-leaving {
  opacity: 0;
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  margin-bottom: -0.75rem;
  border-width: 0;
  transform: scale(0.98);
}

.room-empty-state,
.room-error-state {
  text-align: center;
  color: var(--signage-muted, #9aa2b1);
  font-size: 1.25rem;
  padding: 3rem 1rem;
}

.room-error-state {
  color: #ff6b6b;
}

.room-footer {
  margin-top: 2vh;
  text-align: center;
}

.room-back-link {
  color: var(--signage-muted, #9aa2b1);
  text-decoration: none;
  font-size: 0.9rem;
}

/* ---------------------------------------------------------------------
 * Orientation handling
 * A room's orientation is set explicitly in rooms.json (most signage
 * monitors are physically rotated by the OS/graphics driver, so the
 * browser viewport is already portrait-shaped - this class just lets
 * the theme fine-tune sizing/spacing per orientation). A CSS media
 * query fallback also applies automatically based on real viewport
 * shape for monitors where explicit rotation isn't set.
 * ------------------------------------------------------------------- */

body.orientation-portrait .schedule-item {
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
}

body.orientation-portrait .schedule-item-time {
  min-width: 0;
}

@media (orientation: portrait) {
  body:not(.orientation-landscape) .schedule-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }
  body:not(.orientation-landscape) .schedule-item-time {
    min-width: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .schedule-item {
    transition: none !important;
  }
}
