/* ============================================================
   Shared App Shell Chrome
   ============================================================

   The generic app-shell chrome — topbar, drawer menu, sidebar skeleton,
   workspace nav, item list, panel header, main stage — extracted from
   Component Designer's app.css (the repo's chrome standard) so every app
   under apps/ draws it from one place instead of each hand-copying a
   similar-but-drifting version. Component Designer and Document Designer
   both link this ahead of their own app.css, same pattern as
   editor-workspaces.css and wcs-dialog.css.

   Colors come from window.WCS_COLORS, copied onto :root as custom
   properties by each app's own index.html bootstrap script, before this
   file's rules run.

   What stays OUT of here, and why:
   - Workspace CONTENT styling (counter/card/token/design-elements editors;
     manuals/charts) lives beside the code that emits it — app.css for the
     former, editor-workspaces.css for the latter. This file is chrome only.
   - A gamebox's own document tree (Document Designer's manual/chapter
     sidebar) and Package's summary tiles are one app's content, not chrome —
     they stay in that app's own app.css.
   - `--radius-md`/`--radius-lg` and the box-shadow-heavy counter/card panels
     they size are Component Designer content styling, not chrome; they stay
     defined locally in that app's own app.css rather than here. */

:root {
  color-scheme: light;
  --font-ui: system-ui, sans-serif;
  --topbar-height: 40px;
  --panel: var(--surfaceAlt);
  --panel-strong: var(--surface);
  --ink: var(--text);
  --muted: var(--textMuted);
  --line: var(--border);
  /* --accent already arrives from WCS_COLORS. */
  --accent-strong: #5f3316;                 /* a darker accent, for pressed/active */
  --accent-soft: rgba(122, 72, 32, 0.12);   /* the accent as a wash */
  /* Content ink, not chrome — same values as window.WCS_DESIGN_TOKENS,
     which seeds new counter/card/chart/manual objects. Kept here because both
     apps' content rules already reference them by these names. */
  --teal: #315f66;
  --gold: #b88c2f;
  --radius-sm: 12px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  /* Content face for authored counter/card/manual text, not app chrome —
     kept scoped to specific content rules, never cascaded from body. */
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;

  /* Theme hooks read by apps/shared/ui-components/ruler.css, mapped onto the
     tokens above so the shared ruler inherits the app's colors instead of
     falling back to its built-in defaults. */
  --wcs-ruler-line: var(--line);
  --wcs-ruler-face: var(--surfaceAlt);
  --wcs-ruler-tick-major-color: var(--textDim);
  --wcs-ruler-tick-minor-color: var(--textMuted);
  --wcs-ruler-label-font: var(--mono);
  --wcs-ruler-label-color: var(--muted);

  /* Theme hooks read by apps/shared/ui-components/confirm-dialog.css. */
  --wcs-confirm-scrim: rgba(30, 16, 8, 0.28);
  --wcs-confirm-surface: var(--surfaceAlt);
  --wcs-confirm-line: var(--line);
  --wcs-confirm-text: var(--ink);
  --wcs-confirm-accent: var(--accent);
  --wcs-confirm-accent-text: #fffaf0;
  --wcs-confirm-secondary-surface: var(--surface);
}

* {
  box-sizing: border-box;
}

/* The `hidden` attribute must actually hide. Browsers implement it as
   `[hidden] { display: none }` in the UA stylesheet, which ANY author rule
   setting `display` outranks — an author declaration beats a UA one at equal
   specificity. So every element an app gives `display: flex` (the app menu,
   sidebar sections, dialogs) would stay visible with hidden="true" set
   without this. `!important` is what makes the attribute authoritative again
   regardless of what a class rule says. */
[hidden] {
  display: none !important;
}

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

body {
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--ink);
  background: var(--bg);
}

button,
a,
textarea,
input,
select {
  font: inherit;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Topbar ──────────────────────────────────────────────── */

.topbar {
  position: relative;
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 8px;
  background: var(--surfaceDeep);
  border-bottom: 1px solid var(--line);
}

.topbar-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.menu-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: none;
  color: var(--ink);
  cursor: pointer;
}

.menu-button:hover {
  background: var(--surfaceActive);
}

.menu-button svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
}

/* The hex mark at the leftmost edge of .topbar-main, linking back to the
   root launcher (/). Geometry (.wcs-topbar-icon-link/.wcs-topbar-icon) and
   this context's hover tint live in apps/shared/ui-components/brand-bar.css
   -- linked by this app for that one shared component, so the icon lands
   at the identical box position whether it's on this light topbar or that
   file's own dark bar. Requires <link brand-bar.css> in this app's HTML. */

.component-menu-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 14px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 170px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffdf8;
  box-shadow: 0 14px 28px rgba(34, 26, 19, 0.16);
}

.component-menu-panel[hidden] {
  display: none;
}

.component-menu-item {
  width: 100%;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 700;
  text-align: left;
}

.component-menu-item:hover {
  background: rgba(159, 65, 32, 0.08);
  border-color: rgba(159, 65, 32, 0.14);
}

.component-menu-divider {
  height: 1px;
  margin: 3px 4px;
  background: var(--line);
}

.app-title {
  padding: 2px 8px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--ink);
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

/* ── Workspace shell / sidebar ──────────────────────────────── */

.workspace-shell {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
}

.panel {
  border: 1px solid var(--line);
  background: var(--panel);
}

.library-sidebar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  font-size: 0.84rem;
  overflow-y: auto;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.workspace-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.workspace-tab,
.item-button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.45);
  color: var(--ink);
  cursor: pointer;
}

.workspace-tab {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 6px;
  padding: 5px 6px;
  text-align: left;
  font-weight: 700;
  min-height: 26px;
}

.workspace-tab span:first-child {
  flex: 1;
}

.workspace-tab strong,
.tiny-badge,
.panel-pill {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.workspace-tab strong {
  font-size: 0.58rem;
}

.workspace-tab:hover {
  background: var(--surfaceActive);
}

/* Active state fills solid with accent, per UI_STYLE_GUIDE.md's Buttons and
   Controls rule ("active state fills with accent"). */
.workspace-tab.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fffaf0;
}

.workspace-tab.is-active strong {
  color: #fffaf0;
}

.workspace-tab.is-coming-soon {
  background: rgba(255, 255, 255, 0.34);
  color: var(--muted);
  cursor: not-allowed;
}

.workspace-tab.is-coming-soon strong {
  color: var(--muted);
  opacity: 0.75;
}

.workspace-tab:disabled {
  opacity: 1;
}

.workspace-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 5px;
  border-radius: 999px;
  background: rgba(184, 140, 47, 0.16);
  color: #8d650f;
  font-family: var(--mono);
  font-size: 0.54rem;
  font-style: normal;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.item-button {
  padding: 6px 7px;
  text-align: left;
}

.tiny-badge,
.panel-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 3px 7px;
  background: rgba(49, 95, 102, 0.1);
  color: var(--teal);
}

/* ── Main stage ──────────────────────────────────────────── */

.main-stage {
  position: relative; /* anchors TODO #128's full-cover read-only overlay
                          (component-designer/app.css's .editor-lock-overlay)
                          -- inert for any app that doesn't add one */
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  min-width: 0;
}

.workspace-secondary {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0;
}

.workspace-secondary[hidden] {
  display: none;
}

.panel-header {
  flex-shrink: 0;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surfaceAlt);
}

.panel-header h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
}

.panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: auto;
}

.empty-state {
  padding: 8px;
  color: var(--muted);
  font-size: 11px;
  font-style: italic;
}
