/* ============================================================================
   CCL_XGRAM — app-specific overrides on top of the CCI design system (cci.css).
   cci.css supplies the tokens, type, frosted panels, table, badges & buttons;
   this file only positions the floating overlays for the full-screen 3D app and
   styles the brick-sequence table.
   ============================================================================ */

/* The 3D canvas fills the viewport; the CCI gradient (from cci.css body) shows
   through behind the transparent (alpha) render on desktop. Overlays float on top. */
html, body { height: 100%; }
body { overflow: hidden; }
body > canvas { position: fixed; inset: 0; z-index: 0; display: block; }

/* ---- Status / controls panel (top-left) ----------------------------------- */
#status {
  position: fixed;
  top: var(--space-3);
  left: var(--space-3);
  z-index: 10;
  width: min(360px, calc(100vw - 2 * var(--space-3)));
  padding: var(--space-3) var(--space-4);
  font-size: var(--font-size-sm);
  line-height: 1.5;
}
#brand { gap: var(--space-2); }
#brand img { width: 36px; height: 36px; }
.cci-brand-word { font-size: 1.05rem; letter-spacing: 0.02em; }
#subtitle { margin-top: 2px; }

/* EN/DE language toggle, pinned to the status panel's top-right corner (issue #6). */
.lang-toggle {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  padding: 2px 10px;
  min-width: 2.4rem;
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
}

.status-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  margin-top: var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
}
.status-meta b { color: var(--color-heading); font-weight: 500; }

/* Connection / state words reuse the brand status colours. */
#status .ok  { color: var(--color-success); }
#status .bad { color: var(--color-danger); }

#status .hint { font-size: var(--font-size-xs); line-height: 1.45; margin-top: var(--space-3); }

#desktop-controls {
  margin-top: var(--space-3);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}
#desktop-controls .hint { flex-basis: 100%; margin-top: var(--space-1); }

/* ---- Brick laying-sequence table (right side) ----------------------------- */
#brick-panel {
  position: fixed;
  top: var(--space-3);
  right: var(--space-3);
  bottom: var(--space-3);
  z-index: 10;
  width: min(340px, calc(100vw - 2 * var(--space-3)));
  display: flex;
  flex-direction: column;
  padding: 0;            /* the head + scroll body manage their own padding */
  overflow: hidden;      /* clip the scroll body to the panel's square corners */
}
.bp-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  flex: 0 0 auto;
}
.bp-progress {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  color: var(--color-heading);
}
.bp-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Tighten the shared .cci-table for the narrow panel. */
#brick-table { font-size: var(--font-size-sm); }
#brick-table th,
#brick-table td { padding: 0.4rem 0.7rem; }

/* Sticky header — needs a near-solid fill so scrolling rows don't bleed through
   the frosted overlay behind it. */
#brick-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(14, 14, 16, 0.96);
}

.bp-col-n { width: 2.5rem; }
#brick-table td.bp-n { font-family: var(--font-mono); color: var(--color-text-muted); }
#brick-table td.bp-dims { font-family: var(--font-mono); font-size: var(--font-size-xs); white-space: nowrap; color: var(--color-text); }
.bp-factor { margin-left: 0.4rem; font-family: var(--font-mono); font-size: var(--font-size-xs); color: var(--color-text-muted); }

#brick-rows tr { cursor: pointer; }

/* Already-laid rows: dimmed. */
#brick-rows tr.laid td { color: var(--color-text-muted); }
#brick-rows tr.laid td.bp-dims { opacity: 0.6; }

/* The brick being laid now: yellow accent bar + soft tint, brighter text. */
#brick-rows tr.current { background: var(--cci-yellow-soft); }
#brick-rows tr.current td { color: var(--color-heading); }
#brick-rows tr.current td.bp-n {
  color: var(--color-heading);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--cci-yellow);
}

#brick-rows tr.bp-empty { cursor: default; }
#brick-rows tr.bp-empty:hover { background: transparent; }

/* Stability "unstable" badge (cci.css ships success/warning/muted; add danger). */
.badge-danger { color: var(--color-danger); border-color: rgba(255, 107, 107, 0.5); }

/* Record button while a capture session is live (issue #42): unmistakably red. */
.act.rec-live { color: #ff5a5a; border-color: rgba(255, 90, 90, 0.7); }

/* ---- Cutting room: grouped cut list (issue #35) --------------------------- */
/* Same right-side frosted panel as #brick-panel; revealed only in ?mode=cut. */
#cut-panel {
  position: fixed;
  top: var(--space-3);
  right: var(--space-3);
  bottom: var(--space-3);
  z-index: 10;
  width: min(360px, calc(100vw - 2 * var(--space-3)));
  display: none;                 /* revealed by body.cut-mode */
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}
body.cut-mode #cut-panel { display: flex; }
body.cut-mode #brick-panel { display: none; }   /* the cut list takes the laying table's slot */
body.cut-mode .lay-only { display: none; }        /* hide laying-only controls + hints */

/* Cut-only toolbar buttons: hidden until cut mode. */
.cut-only { display: none; }
body.cut-mode .cut-only { display: inline-flex; }

#cut-table { font-size: var(--font-size-sm); }
#cut-table th,
#cut-table td { padding: 0.4rem 0.7rem; vertical-align: middle; }
#cut-table thead th {                 /* near-solid sticky header (rows mustn't bleed through) */
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(14, 14, 16, 0.96);
}
.cut-col-check { width: 2rem; }
.cut-col-qty { width: 3rem; }
#cut-table td.cut-check { text-align: center; }
#cut-table td.cut-check input { width: 16px; height: 16px; accent-color: var(--cci-yellow); cursor: pointer; }
#cut-table td.cut-qty { font-family: var(--font-mono); color: var(--color-heading); white-space: nowrap; }
#cut-table td.cut-dims { font-family: var(--font-mono); font-size: var(--font-size-xs); white-space: nowrap; color: var(--color-text); }
.cut-from { display: block; margin-top: 2px; color: var(--color-text-muted); font-size: var(--font-size-xs); }
#cut-rows tr.done td { color: var(--color-text-muted); }
#cut-rows tr.done td.cut-dims { opacity: 0.55; text-decoration: line-through; }
#cut-rows tr.bp-empty { cursor: default; }
#cut-rows tr.bp-empty:hover { background: transparent; }

/* On narrow / portrait screens the side table would cover the view — hide it
   (this is a desktop feature) and let the status panel breathe. */
@media (max-width: 640px) {
  #brick-panel { display: none; }
  #status { width: min(360px, calc(100vw - 2 * var(--space-3))); }
  /* Cut mode fills the phone with the list, so it can't hide like the laying table. Split the
     screen into two NON-OVERLAPPING regions so the sheet can never rise over the status
     toolbar buttons (Open file / Cut list CSV / Print), no matter how tall either grows: a
     capped, self-scrolling status area up top and the cut list filling the rest. The cut-mode
     hint is dropped here to keep the status short. */
  body.cut-mode #status { max-height: 42vh; overflow-y: auto; }
  body.cut-mode #status .hint { display: none; }
  body.cut-mode #cut-panel {
    top: 45vh;
    left: var(--space-3);
    right: var(--space-3);
    bottom: var(--space-3);
    width: auto;
    max-height: none;
  }
}

/* Print the cut sheet on plain paper (issue #35): white page, just the list. Scoped to
   cut mode so printing the laying page is unaffected. */
@media print {
  body.cut-mode > canvas,
  body.cut-mode #status,
  body.cut-mode #brick-panel,
  body.cut-mode #ARButton { display: none !important; }   /* the Enter-AR button is screen-only (Phase 2) */
  body.cut-mode { overflow: visible; background: #fff; }
  body.cut-mode #cut-panel {
    display: flex !important;
    position: static;
    width: auto;
    max-height: none;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
    background: #fff;
    color: #000;
  }
  body.cut-mode #cut-panel .eyebrow,
  body.cut-mode #cut-panel .bp-progress { color: #000; }
  body.cut-mode #cut-scroll { overflow: visible; }
  body.cut-mode #cut-table thead th { position: static; background: #fff; color: #000; border-bottom: 1px solid #000; }
  body.cut-mode #cut-table td { color: #000; border-bottom: 1px solid #bbb; }
  body.cut-mode #cut-table td.cut-dims,
  body.cut-mode .cut-from { color: #000; opacity: 1; }
  body.cut-mode #cut-rows tr.done td.cut-dims { text-decoration: none; }
  body.cut-mode .badge { color: #000 !important; border-color: #000 !important; }
}
