/**
 * Ichebo Command Shell (v2) — Layout Foundation
 * Four-Column Dynamic Grid Architecture
 */

:root {
  /* Panel Widths */
  --sidebar-w: 64px;
  --context-w: 240px;
  --options-w: 300px;

  /* State Variables (controlled by shell_v2.js) */
  --context-state: 1;
  /* 1 = open, 0 = collapsed */
  --options-state: 0;
  /* 0 = hidden by default */

  /* Computed Widths */
  --actual-context-w: calc(var(--context-w) * var(--context-state));
  --actual-options-w: calc(var(--options-w) * var(--options-state));

  /* Surface Transitions */
  --shell-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Mobile breakpoint: hide desktop shell, show mobile fallback ── */
@media (max-width: 1023px) {
  .ics-shell { display: none !important; }
  #ws-mobile-shell { display: block !important; }
}
@media (min-width: 1024px) {
  #ws-mobile-shell { display: none !important; }
  .fab { display: none !important; }
}

/* ── Shell Container ────────────────────────────────────────── */
.ics-shell {
  display: grid;
  grid-template-columns:
    var(--sidebar-w) var(--actual-context-w) 1fr var(--actual-options-w);
  grid-template-rows: 1fr;
  /* Topbar is now part of the stage */
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background: var(--ink);
  /* Base background is dark */
  transition: grid-template-columns var(--shell-transition);
}

/* ── Column 1: Primary Sidebar (Global Switcher) ────────────── */
.ics-sidebar {
  grid-column: 1;
  grid-row: 1 / -1;
  background: var(--ink);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-s) 0;
  z-index: 100;
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  transition: background var(--shell-transition), color var(--shell-transition);
}

html:not(.dark) .ics-sidebar {
  background: var(--card-2);
  color: var(--text);
  border-right: 1px solid var(--border);
}

.ics-sidebar__logo {
  width: 32px;
  height: 32px;
  margin-bottom: var(--space-l);
}

.ics-logo {
  filter: none;
  transition: filter var(--transition-fast);
}

html:not(.dark) .ics-logo {
  /* Light mode sidebar is --card-2 (stone), so invert white SVG to black */
  filter: brightness(0);
}

.ics-sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-m);
  flex: 1;
}

/* Bottom-pinned admin items (Tenancy etc.) — visually separated from core nav */
.ics-sidebar__bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-m);
  padding-bottom: var(--space-s);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: var(--space-s);
  margin-top: var(--space-s);
}

html:not(.dark) .ics-sidebar__bottom {
  border-top-color: var(--border);
}

.ics-sidebar__item {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-m);
  color: rgba(255, 255, 255, 0.4);
  transition: all var(--transition-fast);
  text-decoration: none;
  position: relative;
}

html:not(.dark) .ics-sidebar__item {
  color: var(--muted);
}

.ics-sidebar__item:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
}

html:not(.dark) .ics-sidebar__item:hover {
  color: var(--text);
  background: var(--hover);
}

.ics-sidebar__item.active {
  color: var(--primary);
}

.ics-sidebar__item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
  box-shadow: 0 0 8px var(--primary);
}

/* ── Instant tooltip on sidebar items ───────────────────────── */
.ics-sidebar__item[data-tooltip] {
  overflow: visible;
}

.ics-sidebar__item[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--ink);
  color: #fff;
  font-family: var(--ff-body);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  padding: 5px 10px;
  border-radius: var(--radius-s);
  border: 1px solid rgba(255, 255, 255, 0.08);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s ease;
  z-index: 200;
}

.ics-sidebar__item[data-tooltip]:hover::after {
  opacity: 1;
}

html:not(.dark) .ics-sidebar__item[data-tooltip]::after {
  background: var(--ink);
  color: #fff;
  border-color: rgba(0, 0, 0, 0.15);
}

/* ── Column 2: Context Bar (App Nav / Explorer) ─────────────── */
.ics-context-bar {
  grid-column: 2;
  grid-row: 1 / -1;
  background: var(--ink-2);
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 90;
  transition: all var(--shell-transition);
  opacity: var(--context-state);
}

html:not(.dark) .ics-context-bar {
  background: var(--card);
  border-right: 1px solid var(--border);
}

.ics-context-bar__header {
  height: 56px;
  padding: 0 var(--space-s);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  font-family: var(--ff-display);
  font-weight: 700;
  font-size: var(--fz-0);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

html:not(.dark) .ics-context-bar__header {
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.ics-context-bar__content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-m) var(--space-s);
}

/* ── Column 3: The Stage (Main Working Area) ────────────────── */
.ics-stage {
  grid-column: 3;
  grid-row: 1 / -1;
  background: var(--card);
  /* Stone */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  box-shadow: -4px 0 12px rgba(0, 0, 0, 0.05);
  border-left: 1px solid var(--border);
  min-width: 480px;
  /* Prevent being squeezed out */
}

.ics-stage__topbar {
  height: 56px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-s);
  background: var(--bg);
  z-index: 10;
  gap: var(--space-m);
}

.ws-topbar__search {
  display: flex;
  align-items: center;
  gap: var(--space-2xs);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 0 12px;
  height: 36px;
  width: 200px;
  transition: all var(--transition);
}

.ws-topbar__search:focus-within {
  width: 300px;
  border-color: var(--primary);
  background: var(--bg);
  box-shadow: 0 0 0 3px var(--primary-alpha);
}

.ws-topbar__search input {
  border: none;
  background: transparent;
  font-size: var(--fz--1);
  color: var(--text);
  width: 100%;
  outline: none;
}

.ws-topbar__search .material-symbols-outlined {
  font-size: 18px;
  color: var(--muted);
}

.ws-icon-btn {
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-s);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.ws-icon-btn:hover {
  background: var(--hover);
  border-color: var(--muted-light);
}

.ws-icon-btn.active {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-alpha);
}

.ics-stage__content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* The Document Canvas */
.ics-canvas {
  width: 100%;
  max-width: 900px;
  padding: 0 var(--space-m);
  height: fit-content;
}

/* ── Column 4: Options Bar (Metadata / Right Pane) ──────────── */
.ics-options-bar {
  grid-column: 4;
  grid-row: 1 / -1;
  background: var(--card-2);
  /* Stone 2 */
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 80;
  transition: opacity var(--shell-transition);
  opacity: var(--options-state);
}

.ics-options-bar__header {
  height: 56px;
  padding: 0 var(--space-s);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  /* Contrast with Stone 2 */
}

.ics-options-bar__content {
  flex: 1;
  overflow-y: auto;
  position: relative;
}

/* ── Options Tabs ── */
.ics-options-tabs {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--space-xs);
  gap: var(--space-xs);
}

.ics-options-tab {
  padding: var(--space-xs) var(--space-2xs);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.ics-options-tab:hover {
  color: var(--text);
}

.ics-options-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.ws-options-pane {
  display: none;
  height: 100%;
}

.ws-options-pane.active {
  display: block;
}

.ics-bible-sidecar {
  width: 100%;
  height: 100%;
  border: none;
  background: var(--bg);
}

/* Level Badge & Avatar Utils */
.ws-sidebar__level-dot {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #fff;
  font-weight: 800;
  flex-shrink: 0;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
}

.ws-sidebar__avatar {
  border-radius: 50%;
  background: var(--card-2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-weight: 700;
  color: var(--text);
  border: 1px solid var(--border);
  transition: transform var(--transition-fast);
}

.ws-sidebar__avatar:hover {
  transform: scale(1.05);
  border-color: var(--primary);
}

.ws-sidebar__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ── Utils ── */
.u-text-ink {
  color: var(--ink);
}

.u-text-stone {
  color: var(--card);
}