/* CIF Command UI — executive shell: 3-tier grid, command bar, rails, shelf.
   Composition follows the Fable Final Review §4.1. */

.cifc-app {
  display: grid;
  grid-template-rows: var(--cif-bar-h) 1fr auto;
  min-height: 100vh;
}

/* ---- T0 Command Bar -------------------------------------------------- */
.cifc-bar {
  position: sticky;
  top: 0;
  z-index: var(--z-bar);
  height: var(--cif-bar-h);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  background: var(--cif-glass);
  backdrop-filter: blur(var(--cif-blur));
  -webkit-backdrop-filter: blur(var(--cif-blur));
  border-bottom: 1px solid var(--cif-line);
  box-shadow: 0 1px 0 rgba(201, 162, 75, 0.18);
}
.cifc-bar__brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.cifc-bar__brand b { color: var(--cif-text); }
.cifc-bar__brand span {
  color: var(--cif-gold);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}
.cifc-bar__spacer { flex: 1; }
.cifc-bar__group { display: flex; align-items: center; gap: 14px; }

.cifc-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 28px;
  padding: 0 12px;
  border: 1px solid var(--cif-line);
  border-radius: 999px;
  background: var(--cif-glass-2);
  font-size: 12px;
  color: var(--cif-text-dim);
  white-space: nowrap;
}
.cifc-chip b { color: var(--cif-text); font-weight: 600; }
.cifc-chip--state {
  border-color: rgba(57, 214, 242, 0.4);
  color: var(--cif-text);
}
.cifc-chip__dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--cif-text-faint);
}
.cifc-chip__dot--ok { background: var(--cif-success); box-shadow: 0 0 8px var(--cif-success); }
.cifc-chip__dot--warn { background: var(--cif-warn); box-shadow: 0 0 8px var(--cif-warn); }
.cifc-chip__dot--bad { background: var(--cif-danger); box-shadow: 0 0 8px var(--cif-danger); }
.cifc-chip__dot--live { background: var(--cif-cyan); box-shadow: 0 0 10px var(--cif-cyan); }

.cifc-badge {
  min-width: 18px; height: 18px; padding: 0 5px;
  display: inline-grid; place-items: center;
  border-radius: 999px;
  font-size: 11px; font-weight: 700;
  background: rgba(139, 150, 172, 0.18);
  color: var(--cif-text-dim);
}
.cifc-badge--gold {
  background: rgba(201, 162, 75, 0.18);
  color: var(--cif-gold-bright);
  box-shadow: inset 0 0 0 1px rgba(201, 162, 75, 0.4);
}

.cifc-lang {
  display: inline-flex;
  border: 1px solid var(--cif-line);
  border-radius: 8px;
  overflow: hidden;
}
.cifc-lang button {
  background: transparent;
  border: 0;
  color: var(--cif-text-dim);
  font-size: 11px;
  padding: 5px 9px;
}
.cifc-lang button[aria-pressed="true"] {
  background: rgba(57, 214, 242, 0.14);
  color: var(--cif-text);
}
.cifc-clock { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--cif-text-dim); }

/* ---- T1/T2 grid ------------------------------------------------------ */
.cifc-grid {
  display: grid;
  /* Flexible rails (shrink toward 270px) keep the 720px core intact without
     forcing a horizontal scrollbar between the collapse breakpoint and full
     desktop width. */
  grid-template-columns:
    minmax(270px, var(--cif-rail-w))
    minmax(720px, 1fr)
    minmax(270px, var(--cif-rail-e-w));
  gap: var(--cif-gap);
  padding: var(--cif-gap);
  align-items: stretch;
  min-height: 0;
}
.cifc-rail { display: flex; flex-direction: column; gap: var(--cif-gap); min-width: 0; min-height: 0; }
/* The governance rail can outgrow the viewport — let it scroll within its column
   instead of stretching the whole grid. */
.cifc-rail--east { overflow-y: auto; padding-right: 2px; }
.cifc-rail--west { overflow-y: auto; padding-right: 2px; }
.cifc-stage { min-width: 0; }

/* ---- T3 Intel Shelf -------------------------------------------------- */
.cifc-shelf {
  z-index: var(--z-shelf);
  border-top: 1px solid var(--cif-line);
  background: var(--cif-deep);
}
.cifc-shelf__tabs {
  display: flex;
  gap: 6px;
  height: var(--cif-shelf-h);
  align-items: center;
  padding: 0 14px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.cifc-shelf__tab {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--cif-line);
  border-radius: 999px;
  background: var(--cif-glass-2);
  color: var(--cif-text-dim);
  font-size: 12px;
  white-space: nowrap;
}
.cifc-shelf__tab[aria-selected="true"] {
  color: var(--cif-text);
  border-color: rgba(57, 214, 242, 0.45);
  background: rgba(57, 214, 242, 0.10);
}
.cifc-shelf__panel {
  display: none;
  padding: 16px;
  border-top: 1px solid var(--cif-line-soft);
  min-height: 180px;
}
.cifc-shelf__panel[data-open="true"] { display: block; }

/* ---- Command-bar motion toggle (perf kill-switch) ------------------- */
.cifc-iconbtn {
  width: 28px; height: 28px;
  display: inline-grid; place-items: center;
  border: 1px solid var(--cif-line);
  border-radius: 999px;
  background: var(--cif-glass-2);
  color: var(--cif-text-dim);
  font-size: 13px; line-height: 1;
}
.cifc-iconbtn[aria-pressed="true"] { color: var(--cif-cyan); border-color: rgba(57, 214, 242, 0.4); }
.cifc-iconbtn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---- Accessibility — visible keyboard focus (Phase 5) --------------- */
/* Inputs deliberately drop the default :focus outline; restore a clear ring
   for keyboard navigation only (:focus-visible) across all interactive els. */
.cifc-root :is(button, a, select, input, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--cif-cyan);
  outline-offset: 2px;
  border-radius: var(--cif-radius-sm);
}

/* ---- Responsive (Phase 5) ------------------------------------------- */
/* Tablet / narrow desktop: rails fold beneath the core stage (which keeps
   focus via order:-1) once the 720px core + minimum rails no longer fit.
   Rails drop their internal scroll so the page — not each column — scrolls,
   avoiding nested scroll traps. */
@media (max-width: 1340px) {
  .cifc-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-auto-rows: min-content;
  }
  .cifc-stage { order: -1; }
  .cifc-rail--west, .cifc-rail--east { overflow-y: visible; }
}

/* Mobile: the command bar wraps and its chip group scrolls horizontally
   instead of overflowing; tighter gaps; the core never forces a horizontal
   scrollbar below 720px. */
@media (max-width: 720px) {
  .cifc-app { grid-template-rows: auto 1fr auto; }
  .cifc-bar { flex-wrap: wrap; height: auto; gap: 10px; padding: 8px 12px; }
  .cifc-bar__spacer { display: none; }
  .cifc-bar__group {
    width: 100%;
    overflow-x: auto;
    scrollbar-width: thin;
    padding-bottom: 2px;
  }
  .cifc-grid { padding: 10px; gap: 10px; }
  .cifc-core, .cifc-core__canvas { max-width: 100%; }
}
