/* Typography shared by the workspace shell and its embedded applications.
   Components assign the inherited role variables where HTML alone is ambiguous. */
:root {
  --ui-reading-size: 14px;
  --ui-prose-size: 16px;
  --ui-prose-line: 28px;
  --ui-detail-size: 12px;
  --ui-heading: #262626;
  --ui-title: #303030;
  --ui-body: #333333;
  --ui-secondary: #696969;
  --ui-tag: #595959;
}

/* Shared by the main site and embedded AI/document pages. Typing keeps the
   field's normal boundary and caret, without an extra focus frame or glow. */
@layer workspace-reading {
  :is(
    input:not(:is([type="button" i], [type="submit" i], [type="reset" i],
      [type="checkbox" i], [type="radio" i], [type="range" i],
      [type="color" i], [type="file" i], [type="image" i], [type="hidden" i])),
    textarea, select, [contenteditable]:not([contenteditable="false" i]), [role="textbox"]
  ):is(:focus, :focus-visible),
  :is(.search, .expansion-picker-search):focus-within {
    outline: none !important;
    outline-offset: 0 !important;
    box-shadow: none !important;
  }
}

@scope (:root) to (.admin-console) {
@layer workspace-reading {
  :where(body, main, section, article, aside, header, footer, nav, form, dialog,
    div, p, li, label, summary, a, button, input, select, textarea, span, b,
    strong, em, i, td, th, dt, dd, small, time, h1, h2, h3, h4, h5, h6
  ):not(:where(svg *, [contenteditable="true"], [contenteditable="true"] *,
    #preview, #preview *, #versionPreview, #versionPreview *, .brain-prose, .brain-prose *, pre, pre *, code *, [style*="font-size"])) {
    font-size: var(--reading-size, var(--ui-reading-size)) !important;
  }
  :where(body, p, label, summary, a, button, input, select, textarea, li, td,
    th, dt, dd, h1, h2, h3, h4, h5, h6, strong, b, small, time, span:not(:empty)
  ):not(:where(svg *, [contenteditable="true"], [contenteditable="true"] *,
    #preview, #preview *, #versionPreview, #versionPreview *, .brain-prose, .brain-prose *, pre *, code *, [style*="color"])) {
    color: var(--surface-ink, var(--reading-ink, var(--ui-body))) !important;
  }
  :where(h1, h2, h3, h4, h5, h6):not(:where([contenteditable] *, #preview *, #versionPreview, #versionPreview *, .brain-prose, .brain-prose *)) {
    --reading-ink: var(--ui-heading);
    font-weight: 650 !important;
  }
  :where(small, time) {
    --reading-size: var(--ui-detail-size);
    --reading-ink: var(--ui-secondary);
    font-weight: 400 !important;
  }
  time { font-variant-numeric: tabular-nums; }
  :where(input, textarea)::placeholder { color: var(--surface-ink, var(--ui-secondary)) !important; }

}

/* Apply roles to the text itself so adjoining counts, icons and controls
   retain their own scale. Author-formatted content keeps its own hierarchy. */
@layer workspace-reading {
  :where(h1, h2):not(:where(.document-content *, [contenteditable] *, #preview *, #versionPreview, #versionPreview *, .brain-prose, .brain-prose *)),
  [data-type-role="module"] {
    font-size: 16px !important; line-height: 24px !important;
    font-weight: 650 !important; color: var(--surface-ink, var(--ui-heading)) !important;
  }
  [data-type-role="group"], th:not(.document-content *, [contenteditable] *, .brain-prose *) {
    font-size: var(--ui-reading-size) !important; line-height: 22px !important;
    font-weight: 650 !important; color: var(--surface-ink, var(--ui-heading)) !important;
  }
  [data-type-role="item"] {
    font-size: var(--ui-reading-size) !important; line-height: 22px !important;
    font-weight: 550 !important; color: var(--surface-ink, var(--ui-title)) !important;
  }
  :where(p, td):not(:where(.document-content *, [contenteditable] *, #preview *, #versionPreview, #versionPreview *, .brain-prose, .brain-prose *)),
  [data-type-role="body"] {
    font-size: var(--ui-reading-size) !important; line-height: 24px !important;
    font-weight: 400 !important; color: var(--surface-ink, var(--ui-body)) !important;
  }
  :where(small, time):not(:where(.document-content *, [contenteditable] *)), [data-type-role="meta"] {
    font-size: var(--ui-detail-size) !important; line-height: 18px !important;
    font-weight: 400 !important; color: var(--surface-ink, var(--ui-secondary)) !important;
  }
  [data-type-role="tag"] {
    font-size: var(--ui-detail-size) !important; line-height: 18px !important;
    font-weight: 500 !important; color: var(--surface-ink, var(--ui-tag)) !important;
  }
  [data-type-role="page"], [data-type-role="report"], [data-type-role="metric"] {
    font-size: var(--document-heading-size, 20px) !important; line-height: 1.45 !important;
    font-weight: 650 !important; color: var(--surface-ink, var(--ui-heading)) !important;
  }
  [data-type-role="report"] { font-size: 24px !important; line-height: 34px !important; font-weight: 700 !important; }
  [data-type-role="metric"] { font-size: 32px !important; line-height: 40px !important; color: var(--surface-ink, #111) !important; font-variant-numeric: tabular-nums; }
}

@layer workspace-reading {
  :is(.workspace-main-nav, .ai-section-nav, .brain-layout header nav) > :is(button, a):is([aria-pressed="true"], [aria-current="page"]) {
    --reading-ink: #111;
    background-color: transparent !important;
    --surface-ink: initial !important;
    font-weight: 650;
  }
}

@layer workspace-reading {
  :is(.minimal-project-tabs,.minimal-density-switch,.workbench-local-tabs,.coverage-dimension-switch) > button:is(.active,[aria-pressed="true"],[aria-selected="true"]) {
    background:transparent !important; --surface-ink:initial !important; --reading-ink:#262626; font-weight:600 !important;
    box-shadow:inset 0 -2px var(--vi-regular); border-bottom-color:transparent;
  }
}
}


/* Admin pages and nested icons also consume the paired surface foreground. */
@layer workspace-reading {
  :where(.admin-console :is(button, a, [role="button"], [class*="banner" i]), .admin-console :is(button, [role="button"], [class*="banner" i]) :is(span, strong, small, p, svg)),
  :where(button svg, [role="button"] svg) {
    color: var(--surface-ink, revert-layer) !important;
  }
}

/* One surface/foreground pair per action, including controls inside embedded pages. */
:root {
  --vi-primary: #ff0000;
  --vi-regular: #08766d;
  --vi-on-solid: #ffffff;
}
@layer workspace-reading {
  :is([data-vi-action], button.primary, button[type="submit"], input[type="submit"], a.primary) {
    --vi-fill: var(--vi-primary);
    --vi-ink: var(--vi-on-solid);
    --surface-ink: var(--vi-ink) !important;
    white-space: nowrap;
    background: var(--vi-fill) !important;
    border-color: var(--vi-fill) !important;
    color: var(--vi-ink) !important;
    font-weight: 600;
  }
  :root [data-vi-action="regular"] { --vi-fill: var(--vi-regular); }
  :is([data-vi-action], button.primary, button[type="submit"], input[type="submit"]):disabled:not(.brain-send) {
    --vi-fill: #edf0ef;
    --vi-ink: #616866;
    opacity: 1 !important;
  }

  .brain-send:disabled { opacity: 1 !important; }
  :is([data-vi-action], button.primary, button[type="submit"], a.primary) :is(span, strong, small, svg, i, b) {
    color: var(--vi-ink) !important;
  }
  :is([data-vi-action], button.primary, button[type="submit"]):focus-visible {
    outline: 2px solid #333;
    outline-offset: 2px;
  }
}

@layer workspace-reading {
  :is(.task-stats-segment, .calendar-scope-switch, .scale-switch, .worktime-filter-group nav, .workbench-scope-toolbar nav, .workbench-scope-brand-filter) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    overflow: visible;
  }
  :is(.task-stats-segment, .task-stats-status, .worktime-filter-group nav, .calendar-scope-switch, .scale-switch) > button,
  button[data-vi-filter] {
    --surface-ink: #595959 !important;
    color: var(--surface-ink) !important;
    flex: 0 0 auto !important;
    width: auto !important;
    padding: 6px 8px !important;
    white-space: nowrap !important;
    background: transparent !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    font-weight: 400 !important;
    &[aria-pressed="true"] {
      --surface-ink: #262626 !important;
      font-weight: 600 !important;
      box-shadow: inset 0 -2px var(--vi-regular) !important;
    }
    &:focus-visible { outline: 2px solid var(--vi-regular); outline-offset: 2px; }
  }
}
