/*
 * css/shell.css — Shell (Layer 1) styles. Swiss flat: no shadows, no gradients.
 * MUST: use workspace tokens and logical properties (inline-start/end, block-start/end).
 * MUST NOT: target canvas content blocks (css/canvas.css owns those), :root beyond tokens,
 *           html/body beyond the base reset, or the framework shell.
 * EXTEND: new shell regions get their own .uc-* block here.
 */

/* ── Workspace tokens (light) ─────────────────────────────────────────── */
:root {
  --workspace-rail: oklch(0.985 0 0);
  --workspace-paper: oklch(0.925 0 0);
  --workspace-hairline: oklch(0.82 0 0);
  --workspace-toggle: oklch(0.88 0 0);
  --workspace-toggle-ink: oklch(0.32 0 0);
  --workspace-accent-base: #8f0000;
  --workspace-accent: var(--workspace-accent-base);
  --workspace-focus: var(--workspace-accent);
  --workspace-glass: color-mix(in srgb, var(--workspace-ink) 7%, transparent);
  --workspace-glass-hover: color-mix(in srgb, var(--workspace-ink) 12%, transparent);
  --workspace-glass-active: color-mix(in srgb, var(--workspace-accent) 18%, transparent);
  --workspace-ink: oklch(0.2 0 0);
  --uc-tip-bg: oklch(0.208 0.042 265.755);
  --uc-tip-ink: oklch(0.984 0.003 247.858);
}

.dark {
  --workspace-rail: oklch(0.145 0 0);
  --workspace-paper: oklch(0.225 0 0);
  --workspace-hairline: oklch(0.32 0 0);
  --workspace-toggle: oklch(0.285 0 0);
  --workspace-toggle-ink: oklch(0.72 0 0);
  --workspace-accent: color-mix(in oklch, var(--workspace-accent-base) 68%, white);
  --workspace-focus: var(--workspace-accent);
  --workspace-ink: oklch(0.96 0 0);
  --uc-tip-bg: oklch(0.929 0.013 255.508);
  --uc-tip-ink: oklch(0.208 0.042 265.755);
}

/* ── Base reset (parity with the framework's preflight) ───────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--workspace-rail);
  color: var(--workspace-ink);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
img, svg, video { display: block; vertical-align: middle; }
button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

/* ── Workspace shell — Swiss flat, no shadows, no gradients ───────────── */

.uc-shell {
  --uc-rail-width: 52px;
  --uc-footer-height: 34px;
  --uc-fillet: 4px;
  --uc-fillet-lg: 10px;
  --uc-tool: 30px;
  --uc-lead: 30px;
  --uc-group-gap: 26px;
  --uc-tool-gap: 6px;
  --uc-end-width: 96px;
  --uc-end-height: 20px;
  display: grid;
  grid-template-columns: var(--uc-rail-width) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) var(--uc-footer-height);
  width: 100%;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background: var(--workspace-rail);
  color: var(--workspace-ink);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.uc-rail {
  position: relative;
  grid-column: 1;
  grid-row: 1 / 3;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  justify-items: center;
  align-content: stretch;
  min-height: 0;
  padding-block: 10px;
  row-gap: var(--uc-group-gap);
}

.uc-rail-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;

  gap: var(--uc-tool-gap);
  width: 100%;
  min-height: 0;
  /* overflow stays visible so cascade panels can escape the rail;
     scroll is re-enabled only when the viewport is too short. */
  scrollbar-width: none;
}

.uc-rail-list::-webkit-scrollbar { display: none; }

.uc-canvas {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  background: var(--workspace-paper);
  border-start-start-radius: var(--uc-fillet-lg);
  border-end-start-radius: var(--uc-fillet-lg);
}

.uc-canvas-content { min-height: 100%; }
.uc-canvas-error { margin: 16px; color: var(--workspace-accent); }

.uc-footer {
  position: relative;
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  background: var(--workspace-rail);
}

.uc-footer-list {
  position: absolute;
  top: calc(var(--uc-end-height) / -2);
  inset-inline-end: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 1;
  max-width: calc(100vw - var(--uc-rail-width) - 24px);
  overflow-x: auto;
  scrollbar-width: none;
  background: transparent;
  touch-action: pan-x;
  cursor: grab;
}
.uc-footer-list::-webkit-scrollbar { display: none; }
.uc-footer-list:active { cursor: grabbing; }

/* ── Toggles — flat, no background, accent active state ──────────────── */

.uc-toggle {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--workspace-toggle-ink);
  font: 500 10px / 1 "Helvetica Neue", Helvetica, Arial, sans-serif;
  letter-spacing: 0.04em;
  text-align: center;
  cursor: pointer;
  user-select: none;
  border-radius: var(--uc-fillet);
  transition: color 120ms linear, border-color 120ms linear;
}

.uc-toggle:hover { color: var(--workspace-ink); }
.uc-toggle--tool, .uc-toggle--footer {
  background: var(--workspace-glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.uc-toggle--tool:hover, .uc-toggle--footer:hover { background: var(--workspace-glass-hover); }
.uc-toggle[aria-pressed="true"],
.uc-toggle[aria-expanded="true"] { color: var(--workspace-accent); }
.uc-toggle--tool[aria-expanded="true"], .uc-toggle--footer[aria-pressed="true"] { background: var(--workspace-glass-active); }
.uc-toggle:focus-visible {
  outline: 1px solid var(--workspace-focus);
  outline-offset: 2px;
}

.uc-toggle--lead {
  width: auto;
  min-height: var(--uc-lead);
  padding-inline: 2px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--workspace-ink);
}

.uc-toggle--tool { width: var(--uc-tool); height: var(--uc-tool); }
.uc-toggle--tool svg { width: 17px; height: 17px; }
.uc-icon { display: inline-flex; }
.uc-icon svg, .uc-toggle--tool img { width: 17px; height: 17px; }

.uc-toggle--footer {
  width: var(--uc-end-width);
  height: var(--uc-end-height);
  border: 1px solid var(--workspace-hairline);
  border-radius: 999px;
  font-size: 8px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
}

.uc-toggle--footer[aria-pressed="true"] { border-color: var(--workspace-accent); }

/* ── Cascade panels — settings (from toggle 14) and tool subsets ──────── */

.uc-settings { position: relative; display: flex; }
.uc-tool-slot { position: relative; display: flex; }

.uc-panel {
  position: absolute;
  inset-inline-start: calc(100% + 8px);
  width: max-content;
  min-width: 188px;
  max-width: min(320px, calc(100vw - var(--uc-rail-width) - 16px));
  padding: 12px;
  background: var(--workspace-rail);
  border: 1px solid var(--workspace-hairline);
  border-radius: var(--uc-fillet);
  animation: uc-cascade 140ms linear;
  z-index: 5;
}

.uc-panel--settings { inset-block-end: 0; transform-origin: bottom left; }
.uc-panel--tool { inset-block-start: 50%; transform: translateY(-50%); transform-origin: left center; }

@keyframes uc-cascade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.uc-panel-title {
  margin: 0 0 10px;
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--workspace-toggle-ink);
}

.uc-panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-block: 7px;
  border-top: 1px solid var(--workspace-hairline);
  font-size: 11px;
  letter-spacing: 0.01em;
  color: var(--workspace-ink);
}

.uc-panel-option {
  display: grid;
  gap: 8px;
  padding-block: 9px;
  border-block-start: 1px solid var(--workspace-hairline);
  font-size: 11px;
  color: var(--workspace-ink);
}

.uc-seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 2px; min-width: 0; }

.uc-seg button {
  min-width: 0;
  width: 100%;
  height: auto;
  min-height: 24px;
  padding: 4px 6px;
  border: 0;
  border-radius: 2px;
  background: var(--workspace-toggle);
  color: var(--workspace-toggle-ink);
  font: 500 9px / 1.2 "Helvetica Neue", Helvetica, Arial, sans-serif;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: normal;
  overflow-wrap: anywhere;
}

.uc-seg button[aria-pressed="true"] {
  background: var(--workspace-accent);
  color: var(--workspace-rail);
}

.uc-switch {
  width: 28px;
  height: 14px;
  padding: 2px;
  border: 0;
  border-radius: 2px;
  background: var(--workspace-toggle);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

.uc-switch span {
  width: 10px;
  height: 10px;
  background: var(--workspace-toggle-ink);
  transition: transform 120ms linear;
}

.uc-switch[aria-pressed="true"] { background: var(--workspace-accent); }
.uc-switch[aria-pressed="true"] span {
  transform: translateX(14px);
  background: var(--workspace-rail);
}

/* ── Tooltip — portal-style, flat, no shadow ──────────────────────────── */

.uc-tooltip {
  position: fixed;
  z-index: 50;
  max-width: 260px;
  padding: 6px 12px;
  border-radius: 6px;
  background: var(--uc-tip-bg);
  color: var(--uc-tip-ink);
  font: 500 12px / 1.4 "Helvetica Neue", Helvetica, Arial, sans-serif;
  letter-spacing: 0.01em;
  pointer-events: none;
  animation: uc-tip-in 150ms ease-out;
}
.uc-tooltip[hidden] { display: none; }

@keyframes uc-tip-in {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

/* ── Adaptive scales ──────────────────────────────────────────────────── */

@media (min-width: 1440px) {
  .uc-shell {
    --uc-rail-width: 58px;
    --uc-footer-height: 38px;
    --uc-tool: 32px;
    --uc-lead: 32px;
    --uc-end-width: 108px;
    --uc-end-height: 22px;
    --uc-group-gap: 32px;
  }
}

@media (max-width: 700px) {
  .uc-shell {
    --uc-tool: 28px;
    --uc-lead: 28px;
    --uc-tool-gap: 4px;
    --uc-end-width: min(84px, calc((100vw - 36px) / 3));
    --uc-end-height: 18px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }

  /* Canvas fills the top; chassis (rail) becomes a bottom dock. */
  .uc-canvas {
    grid-column: 1;
    grid-row: 1;
    border-radius: 0 0 var(--uc-fillet-lg) var(--uc-fillet-lg);
    padding-block-start: 30px;
  }

  .uc-rail {
    grid-column: 1;
    grid-row: 2;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 12px;
    row-gap: 0;
    padding: 17px 12px 10px;
  }

  .uc-rail-list {
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    overflow-x: auto;
    overflow-y: hidden;
    padding-block: 2px;
    touch-action: pan-x;
    cursor: grab;
  }
  .uc-rail-list:active { cursor: grabbing; }

  /* Action cluster stays near the viewport block-start on mobile. */
  .uc-footer {
    grid-column: 1;
    grid-row: 1;
    align-self: start;
    height: 0;
    min-height: 0;
    background: transparent;
    z-index: 2;
    pointer-events: none;
  }

  .uc-footer-list {
    pointer-events: auto;
    inset-block-start: 6px;
    inset-inline-end: 12px;
    gap: 6px;
    max-width: calc(100vw - 24px);
  }

  .uc-panel--settings {
    inset-inline-start: auto;
    inset-inline-end: 0;
    inset-block-end: calc(100% + 10px);
    min-width: 0;
    width: min(220px, calc(100vw - 24px));
  }

  .uc-panel--tool {
    position: fixed;
    inset-inline-start: 12px;
    inset-inline-end: 12px;
    inset-block-start: auto;
    inset-block-end: 74px;
    width: auto;
    max-width: none;
    transform: none;
  }
}

@media (max-height: 600px) {
  .uc-rail-list { overflow-y: auto; overflow-x: hidden; }
  .uc-shell { --uc-group-gap: 16px; --uc-tool-gap: 4px; }
}
@media (max-width: 700px) and (max-height: 600px) {
  .uc-rail-list { overflow-x: auto; overflow-y: hidden; }
}

@media (max-height: 560px) {
  .uc-shell {
    --uc-tool: 24px;
    --uc-lead: 24px;
    --uc-group-gap: 12px;
    --uc-tool-gap: 3px;
    --uc-footer-height: 28px;
  }
  .uc-toggle--tool svg { width: 14px; height: 14px; }
  .uc-rail-list { justify-content: flex-start; }
}

@media (max-width: 380px) {
  .uc-toggle--footer { font-size: 7px; letter-spacing: 0.08em; }
}

@media (prefers-reduced-motion: reduce) {
  .uc-toggle, .uc-switch span { transition: none; }
  .uc-panel { animation: none; }
  .uc-tooltip { animation: none; }
}

.uc-shell[data-density="compact"] {
  --uc-tool: 26px;
  --uc-lead: 26px;
  --uc-group-gap: 16px;
  --uc-tool-gap: 3px;
  --uc-rail-width: 44px;
  --uc-footer-height: 28px;
  --uc-end-height: 18px;
}
